public void run(){	
		
		//This is the bundle we will put all our data in throughout the app, then send over UDP port 57110
		osc.OSCBundle bundle = new OSCBundle(); 

		while (true){	// loop to acquire, bundle and send data
			
			listenForStateChange();
			
			
			//Collect raw EEG data and send it out the OSC port.
			if (readytocollect) {
				
				//Tell emotiv where to look for the device data in memory
				
				Edk.INSTANCE.EE_DataUpdateHandle(0, hData);
				Edk.INSTANCE.EE_DataGetNumberOfSample(hData, nSamplesTaken);
				
				///////////////////////////////////////
				
				// check to make sure we have samples to query for data
				if (nSamplesTaken != null){
					if (nSamplesTaken.getValue() != 0) { 				
						
						
						double[] data = new double[nSamplesTaken.getValue()]; //set the size of the data array the length of the sample buffer
						int index = 0;					
						
						/**
						 * RAW DATA ACQUISITION LOOP
						 * the outermost loop (sampleIdx) iterates over the samples (usually four sampled / acquisition in my experience)
						 * the innermost loop iterates over each channel's sample value
						 * the raw data array raweeg is just data2d minus the first 3 channels.
						 */
						
						for (int sampleIdx=0 ; sampleIdx<nSamplesTaken.getValue() ; ++ sampleIdx) { // for the number of samples taken
							
							for (int i = 0 ; i < data2d.length ; i++) { //for each EEG channel
								
								Edk.INSTANCE.EE_DataGet(hData,i,data,nSamplesTaken.getValue());
																
								data2d[i][index] = data[sampleIdx] ;	
				
								
							}	
														
							
							double[][]raweeg = new double[data2d.length-3][data2d[0].length] ; // RAW DATA array : EEG channels 1:14
							Object args[] = new Object[16]; //Object where we will put our raw EEG data for transport over OSC
							bundle = new OSCBundle();

							for(int i=0;i<raweeg.length;i++){// Put all the raw EEG data into an object array to be packed into an OSC Bundle

								alldata2d.get(i).add(raweeg[i][index]) ;
								//System.out.println(" channel:" + i + " data:" + data2d[i][index]+" sample:"+scount+sampleIdx) ; // PRINT THE RAW DATA for each sample taken
								
								args[i] = new Float(data2d[i][index]);
								//System.out.println ("i: " + i + ", " + data2d[i][index]);
																
							}
							
							try {
								@SuppressWarnings("deprecation")
								osc.OSCMessage raw = new osc.OSCMessage("/eeg/raw/", args);
								
								bundle.addPacket(raw);
								bundle.addPacket(excitement_short);
								bundle.addPacket(excitement_long);
								bundle.addPacket(engagement_boredom);
								bundle.addPacket(frustration);
								bundle.addPacket(meditation);
								bundle.addPacket(current_action);
								
								sender.send(bundle);
							
							} catch (IOException e) {
								e.printStackTrace();
							}
						}	
					}
				}
			}
		}
	}