def startBCI(): object1=NeuroPy("COM6") #set call back: object1.setCallBack("attention",attention_callback) #start method object1.start() return None
def main(): print("hallo hallo") object1 = NeuroPy("/dev/rfcomm0") object1.setCallBack("attention", attention_callback) object1.start() while True: if (object1.meditation > 70): object1.stop()
class Nsky(): def __init__(self): self.value = 0 self.counter = 0 self.skip_value = 0 self.data_array = [0.000] * 1024 self.neuro_object = NeuroPy("COM15") self.caller() def attention_callback(self, attention_value): if (self.neuro_object.attention >= 15 and self.neuro_object.meditation >= 15 and self.neuro_object.poorSignal == 0): self.counter += 1 for i in range(len(self.data_array) - 1): self.data_array[i] = self.data_array[i + 1] self.data_array[1023] = attention_value if (self.counter == 1024): if (self.skip_value == 0): self.skip_value = 1 self.value = input( "(0 for left and 1 for right and 2 for ntg)") self.counter = 0 if self.value == 3: self.neuro_object.stop() return None with open('traindata.csv', 'ab') as datafile: writer = csv.writer(datafile) writer.writerow([ self.neuro_object.attention, self.neuro_object.meditation, self.neuro_object.poorSignal, self.data_array, self.value ]) self.value = input( "(0 for left and 1 for right and 2 for ntg)") self.counter = 0 return None def caller(self): #set call back: self.neuro_object.setCallBack("rawValue", self.attention_callback) #call start method self.value = input("(0 for left and 1 for right and 2 for ntg)") self.neuro_object.start() while True: if ( self.neuro_object.meditation > 100 ): #another way of accessing data provided by headset (1st being call backs) print("geda meditationg too much")
json_data = json.dumps(data) s.send(json_data) return None def meditation_callback(meditation_value): print ("Value of meditation is", meditation_value) data = {} data['type'] = 'meditation' data['value'] = str(meditation_value) json_data = json.dumps(data) s.send(json_data) return None object1.setCallBack("attention", attention_callback) object1.setCallBack("meditation", meditation_callback) object1.start() while True: x = 1 # print ("Meditation is", object1.meditation) # print ("Attention is", object1.attention) # print ("Delta is", object1.delta) # print ("Theta is", object1.theta) # print ("lowAlpha is", object1.lowAlpha) # print ("highAlpha is", object1.highAlpha) # print ("lowBeta is", object1.lowBeta) # print ("highBeta is", object1.highBeta) # print ("lowGamma is", object1.lowGamma)
#import winsound import numpy as np import matplotlib.pyplot as plt import matplotlib.animation as animation from pyo import * s = Server().boot() npo=NeuroPy('/dev/rfcomm0',57600) npo.start() def npacb(sigval): print sigval return None #npo.setCallBack("rawValue",npacb) npo.setCallBack("attention",npacb) freqeeg = 512 def crtfrearray(feeg): eegcoll = [] cnteeg=0 while cnteeg<feeg: eegcoll.append(npo.rawValue) cnteeg+=1 freqs = np.fft.fftfreq(len(eegcoll)) idx=np.argmax(np.abs(np.array(eegcoll))**2) freq=freqs[idx] freqhz=abs(freq*freqeeg) if freqhz>40 and freqhz<freqeeg: print freqhz
file_name = str(eyesOption[0]) + '-' + str(alphaOption[0]) with open(file_name,'a') as f: f.write(str(lowAlpha_value) + '\n') ''' def blinkstrength_callback(blinkstrength_value): print "Value of blinkstrength is", blinkstrength_value return None ''' #set recording timer in minutes nmin = 1 #set call back: #object1.setCallBack("attention",attention_callback) #object1.setCallBack("blinkStrength",blinkstrength_callback) object1.setCallBack("highAlpha", highalpha_callback) object1.setCallBack("lowAlpha", lowalpha_callback) #call start method object1.start() t_end = time.time() + 60*(nmin) print('start recording') while time.time() < t_end: #keep running until t_end continue print('done recording')
from NeuroPy import NeuroPy from time import sleep import serial neuropy = NeuroPy(port='/dev/tty.MindWaveMobile-SerialPo') def attention_callback(attention_value): """this function will be called everytime NeuroPy has a new value for attention""" print "Value of attention is: ", attention_value return None neuropy.setCallBack("attention", attention_callback) # neuropy.__srl = serial.Serial( # '/dev/tty.MindWaveMobile-SerialPo', 57600) #neuropy.__srl.flushInput() neuropy.start() print('Sleeping for 10 seconds') sleep(10) try: while True: sleep(1) finally: neuropy.stop()
import RPi.GPIO as GPIO import motor import ultrasonic neuropy = NeuroPy("/dev/rfcomm0") av = 0 /* * * Function Name: attention_level * Input: attention_value (parameter instantiated by setCallBack function from Neuropy library) * Output: - * Logic: Assigns attention value from raw data to variable av, if attention is above threshold * chair moves forward, ultrasonic sensor function is called while moving. * Wheelchair stops moving when attention drops or an obstacle is detected. * Example Call: neuropy.setCallBack("attention",attention_level) * */ def attention_level(attention_value): neuropy.setCallBack("attention",attention_level) av = attention_value print "\nAttention level = ", attention_value if attention_value > 50: #check if attention is above threshold print "Moving forward" motor.forward() #forward motion of wheelchair time.sleep(1) ultrasonic.ultra() #check for obbstacle distance else : print("Stopped Low Attention")
##Sample Program## from NeuroPy import NeuroPy object1=NeuroPy("COM6",57600) #If port not given 57600 is automatically assumed #object1=NeuroPy("/dev/rfcomm0") for linux def attention_callback(attention_value): "this function will be called everytime NeuroPy has a new value for attention" print ("Value of attention is",attention_value) #do other stuff (fire a rocket), based on the obtained value of attention_value #do some more stuff return None #set call back: object1.setCallBack("attention",attention_callback) #call start method object1.start() while True: if(object1.meditation>70): #another way of accessing data provided by headset (1st being call backs) object1.stop() #if meditation level reaches above 70, stop fetching data from the headset
writer = csv.writer(f) writer.writerow([ object1.attention, object1.meditation, object1.poorSignal, arr3, val3 ]) val = input("(0 for red 1 for green 2 for black and 3 for yellow)") val2 = val val3 = val cnter3 = 0 return None #set call back: object1.setCallBack("rawValue", attention_callback) #call start method val = input("(0 for red 1 for green 2 for black and 3 for yellow)") val2 = val val3 = val object1.start() try: sys.exit() except: print(sys.exc_info()[0]) while True: if ( object1.meditation > 100 ): #another way of accessing data provided by headset (1st being call backs) print "medidation too much" #object1.stop() #if meditation level reaches above 70, stop fetching data from the headset
def blink_callBack(blink_rate): print "Blink rate is", blink_rate return None def attention_callback(attention_value): "this function will be called everytime NeuroPy has a new value for attention" global idx, sum if idx > 0: idx= idx -1 sum = sum + attention_value return None else: idx = max print "Average value of attention is", sum/max #do other stuff (fire a rocket), based on the obtained value of attention_value #do some more stuff #ser.write(sum/max) ser.write(str(sum/max)) sum = 0 return None #set call backs object1.setCallBack("attention",attention_callback) object1.setCallBack("blinkStrength", blink_callBack) #call start method object1.start() while True: var = object1
## global prog_poorSignal_value ## prog_poorSignal_value = str(poorSignal_value) ## print "Value of poorSignal is",(prog_poorSignal_value) ## return None ## not needed ##def blinkStrength_callback(blinkStrength_value): ## "this function will be called everytime NeuroPy has a new value for meditation" ## global prog_blinkStrength_value ## prog_blinkStrength_value = str(blinkStrength_value) ## print "Value of blinkStrength is",(prog_blinkStrength_value) ## return None ##not available as per website #set call back: object1.setCallBack("attention", attention_callback) object1.setCallBack("meditation", meditation_callback) object1.setCallBack("delta", delta_callback) object1.setCallBack("theta", theta_callback) object1.setCallBack("lowAlpha", lowAlpha_callback) object1.setCallBack("highAlpha", highAlpha_callback) object1.setCallBack("lowBeta", lowBeta_callback) object1.setCallBack("highBeta", highBeta_callback) object1.setCallBack("lowGamma", lowGamma_callback) object1.setCallBack("midGamma", midGamma_callback) ##object1.setCallBack("poorSignal",poorSignal_callback) ##object1.setCallBack("blinkStrength",blinkStrength_callback) #call start method object1.start()
} headset = NeuroPy('/dev/cu.MindWaveMobile-DevA') def cb(name): def a_cb(value): print(name, value) return a_cb #call start method headset.start() #set call back: for attr in ('attention', 'delta', 'highAlpha', 'highBeta', 'lowAlpha', 'lowBeta', 'lowGamma', 'meditation', 'midGamma', 'theta'): headset.setCallBack(attr, cb(attr)) mp3 = mp3play.load('../6.mp3') mp3.play() # while True: # sleep(5) # print('Instant meditation:', headset.meditation) # if headset.meditation > 90: # headset.stop()
class BrainWindow(QWidget): def __init__(self, parent=None, sensorNUmber=0 ): #sensorNUmber - rfcomm port number - 0 for rfcomm0 etc super(BrainWindow, self).__init__(parent) self.sensorNUmber = sensorNUmber self.setWindowTitle(u"Mindwave " + str(self.sensorNUmber + 1)) layout = QGridLayout() layout.addWidget(QLabel("Value"), 0, 1) layout.addWidget(QLabel("Min"), 0, 2) layout.addWidget(QLabel("Max"), 0, 3) layout.addWidget(QLabel("Relative"), 0, 4) layout.addWidget(QLabel("Attention:"), 1, 0) layout.addWidget(QLabel("Poor signal:"), 1, 2) layout.addWidget(QLabel("Low beta"), 2, 0) layout.addWidget(QLabel("High beta"), 3, 0) layout.addWidget(QLabel("Low gamma"), 4, 0) layout.addWidget(QLabel("Mid gamma"), 5, 0) layout.addWidget(QLabel("Raw data:"), 6, 0) self.attentionLabel = QLabel() layout.addWidget(self.attentionLabel, 1, 1) self.poorSignalLabel = QLabel() layout.addWidget(self.poorSignalLabel, 1, 3) self.lBetaLabel = QLabel() self.lBetaMinLabel = QLabel() self.lBetaMaxLabel = QLabel() self.lBetaRelLabel = QLabel() layout.addWidget(self.lBetaLabel, 2, 1) layout.addWidget(self.lBetaMinLabel, 2, 2) layout.addWidget(self.lBetaMaxLabel, 2, 3) layout.addWidget(self.lBetaRelLabel, 2, 4) self.hBetaLabel = QLabel() self.hBetaMinLabel = QLabel() self.hBetaMaxLabel = QLabel() self.hBetaRelLabel = QLabel() layout.addWidget(self.hBetaLabel, 3, 1) layout.addWidget(self.hBetaMinLabel, 3, 2) layout.addWidget(self.hBetaMaxLabel, 3, 3) layout.addWidget(self.hBetaRelLabel, 3, 4) self.lGammaLabel = QLabel() self.lGammaMinLabel = QLabel() self.lGammaMaxLabel = QLabel() self.lGammaRelLabel = QLabel() layout.addWidget(self.lGammaLabel, 4, 1) layout.addWidget(self.lGammaMinLabel, 4, 2) layout.addWidget(self.lGammaMaxLabel, 4, 3) layout.addWidget(self.lGammaRelLabel, 4, 4) self.mGammaLabel = QLabel() self.mGammaMinLabel = QLabel() self.mGammaMaxLabel = QLabel() self.mGammaRelLabel = QLabel() layout.addWidget(self.mGammaLabel, 5, 1) layout.addWidget(self.mGammaMinLabel, 5, 2) layout.addWidget(self.mGammaMaxLabel, 5, 3) layout.addWidget(self.mGammaRelLabel, 5, 4) #stop stopButton = QPushButton("Stop") stopButton.clicked.connect(self.stop) layout.addWidget(stopButton, 7, 0) self.setLayout(layout) self.headSet = NeuroPy("/dev/rfcomm" + str(sensorNUmber), 57600) self.headSet.setCallBack("attention", self.attention_callback) self.headSet.setCallBack("lowBeta", self.lowBeta_callback) self.headSet.setCallBack("highBeta", self.highBeta_callback) self.headSet.setCallBack("lowGamma", self.lowGamma_callback) self.headSet.setCallBack("midGamma", self.midGamma_callback) self.headSet.setCallBack("rawValue", self.rawValue_callback) self.headSet.setCallBack("poorSignal", self.poorSignal_callback) self.headSet.start() self.highLimit = 100000 # ignore occasional higher values from EEG data self.lowLimit = 100 self.lBetamin = 10000 self.lBetamax = 0.1 self.lBetarelative = 0 self.hBetamin = 10000 self.hBetamax = 0.1 self.hBetarelative = 0 self.lGammamin = 10000 self.lGammamax = 0.1 self.lGammarelative = 0 self.mGammamin = 10000 self.mGammamax = 0.1 self.mGammarelative = 0 def __del__(self): self.stop() def stop(self): self.headSet.stop() #self.perf.Stop() #self.perf.Join() #self.cs.Stop() #TEMPORARY -delete later def lowBeta_callback(self, value): #print "Low beta: ", value if (value > self.highLimit or value < self.lowLimit): # don't handle occasional high values return self.lBetaLabel.setText(str(value)) if (value < self.lBetamin and value != 0): self.lBetamin = value self.lBetaMinLabel.setText(str(value)) if (value > self.lBetamax): self.lBetamax = value self.lBetaMaxLabel.setText(str(value)) self.lBetarelative = float(value - self.lBetamin) / (self.lBetamax - self.lBetamin + 1) self.lBetaRelLabel.setText(str(self.lBetarelative)) sendUdpMessage("sensor,lb" + str(self.sensorNUmber + 1) + "," + str(self.lBetarelative)) #self.cs.SetChannel("lowBetaRelative",self.lBetarelative) return None def highBeta_callback(self, value): #print "high beta: ", value if (value > self.highLimit or value < self.lowLimit): # don't handle occasional high values return self.hBetaLabel.setText(str(value)) if (value < self.hBetamin and value != 0): self.hBetamin = value self.hBetaMinLabel.setText(str(value)) if (value > self.hBetamax): self.hBetamax = value self.hBetaMaxLabel.setText(str(value)) self.hBetarelative = float(value - self.hBetamin) / (self.hBetamax - self.hBetamin + 1) self.hBetaRelLabel.setText(str(self.hBetarelative)) sendUdpMessage("sensor,hb" + str(self.sensorNUmber + 1) + "," + str(self.hBetarelative)) #self.cs.SetChannel("highBetaRelative",self.hBetarelative) return None def lowGamma_callback(self, value): #print "Low gamma: ", value if (value > self.highLimit or value < self.lowLimit): # don't handle occasional high values return self.lGammaLabel.setText(str(value)) if (value < self.lGammamin and value != 0): self.lGammamin = value self.lGammaMinLabel.setText(str(value)) if (value > self.lGammamax): self.lGammamax = value self.lGammaMaxLabel.setText(str(value)) self.lGammarelative = float(value - self.lGammamin) / ( self.lGammamax - self.lGammamin + 1) self.lGammaRelLabel.setText(str(self.lGammarelative)) #self.cs.SetChannel("lowBetaRelative",self.lGammarelative) return None def midGamma_callback(self, value): #print "mid gamma: ", value if (value > self.highLimit or value < self.lowLimit): # don't handle occasional high values return self.mGammaLabel.setText(str(value)) if (value < self.mGammamin and value != 0): self.mGammamin = value self.mGammaMinLabel.setText(str(value)) if (value > self.mGammamax): self.mGammamax = value self.mGammaMaxLabel.setText(str(value)) self.mGammarelative = float(value - self.mGammamin) / ( self.mGammamax - self.mGammamin + 1) self.mGammaRelLabel.setText(str(self.mGammarelative)) #self.cs.SetChannel("midmGammaRelative",self.mGammarelative) return None def attention_callback(self, value): #print "Attention: ",value self.attentionLabel.setText(str(value)) sendUdpMessage("sensor,attention" + str(self.sensorNUmber + 1) + "," + str(float(value) / 100)) #self.cs.SetChannel("attention",value) return None def rawValue_callback(self, value): #this is very fast don't print this #print "rawValue: ", value #self.cs.SetChannel("rawValue",value) if (abs(value) < 1000): sendUdpMessage("sensor,raw" + str(self.sensorNUmber + 1) + "," + str(value)) return None def poorSignal_callback(self, value): print "headset: ", self.sensorNUmber, "poor signal: ", value self.poorSignalLabel.setText(str(value))
class BrainWindow(QWidget): def __init__(self, parent=None, sensorNUmber=0): #sensorNUmber - rfcomm port number - 0 for rfcomm0 etc super(BrainWindow, self).__init__(parent) self.sensorNUmber = sensorNUmber self.setWindowTitle(u"Mindwave"+str(self.sensorNUmber)) layout = QGridLayout() layout.addWidget(QLabel("Value"),0,1) layout.addWidget(QLabel("Min"),0,2) layout.addWidget(QLabel("Max"),0,3) layout.addWidget(QLabel("Relative"),0,4) layout.addWidget(QLabel("Attention:"),1,0) layout.addWidget(QLabel("Poor signal:"),1,2) layout.addWidget(QLabel("Low beta"),2,0) layout.addWidget(QLabel("High beta"),3,0) layout.addWidget(QLabel("Low gamma"),4,0) layout.addWidget(QLabel("Mid gamma"),5,0) layout.addWidget(QLabel("Raw data:"),6,0) self.attentionLabel = QLabel() layout.addWidget(self.attentionLabel,1,1) self.poorSignalLabel = QLabel() layout.addWidget(self.poorSignalLabel,1,3) self.lBetaLabel = QLabel() self.lBetaMinLabel = QLabel() self.lBetaMaxLabel = QLabel() self.lBetaRelLabel = QLabel() layout.addWidget(self.lBetaLabel,2,1) layout.addWidget(self.lBetaMinLabel,2,2) layout.addWidget(self.lBetaMaxLabel,2,3) layout.addWidget(self.lBetaRelLabel,2,4) self.hBetaLabel = QLabel() self.hBetaMinLabel = QLabel() self.hBetaMaxLabel = QLabel() self.hBetaRelLabel = QLabel() layout.addWidget(self.hBetaLabel,3,1) layout.addWidget(self.hBetaMinLabel,3,2) layout.addWidget(self.hBetaMaxLabel,3,3) layout.addWidget(self.hBetaRelLabel,3,4) self.lGammaLabel = QLabel() self.lGammaMinLabel = QLabel() self.lGammaMaxLabel = QLabel() self.lGammaRelLabel = QLabel() layout.addWidget(self.lGammaLabel,4,1) layout.addWidget(self.lGammaMinLabel,4,2) layout.addWidget(self.lGammaMaxLabel,4,3) layout.addWidget(self.lGammaRelLabel,4,4) self.mGammaLabel = QLabel() self.mGammaMinLabel = QLabel() self.mGammaMaxLabel = QLabel() self.mGammaRelLabel = QLabel() layout.addWidget(self.mGammaLabel,5,1) layout.addWidget(self.mGammaMinLabel,5,2) layout.addWidget(self.mGammaMaxLabel,5,3) layout.addWidget(self.mGammaRelLabel,5,4) #stop stopButton = QPushButton("Stop") stopButton.clicked.connect(self.stop) layout.addWidget(stopButton,7,0) self.setLayout(layout) self.headSet = NeuroPy("/dev/rfcomm"+str(sensorNUmber),57600) self.headSet.setCallBack("attention",self.attention_callback) self.headSet.setCallBack("lowBeta",self.lowBeta_callback) self.headSet.setCallBack("highBeta",self.highBeta_callback) self.headSet.setCallBack("lowGamma",self.lowGamma_callback) self.headSet.setCallBack("midGamma",self.midGamma_callback) self.headSet.setCallBack("rawValue",self.rawValue_callback) self.headSet.setCallBack("poorSignal",self.poorSignal_callback) self.headSet.start() self.highLimit = 100000 # ignore occasional higher values from EEG data self.lowLimit = 100 self.lBetamin = 10000 self.lBetamax = 0.1 self.lBetarelative = 0 self.hBetamin = 10000 self.hBetamax = 0.1 self.hBetarelative = 0 self.lGammamin = 10000 self.lGammamax = 0.1 self.lGammarelative = 0 self.mGammamin = 10000 self.mGammamax = 0.1 self.mGammarelative = 0 def __del__(self): self.stop() def stop(self): self.headSet.stop() #self.perf.Stop() #self.perf.Join() #self.cs.Stop() #TEMPORARY -delete later def lowBeta_callback(self, value): #print "Low beta: ", value if (value>self.highLimit or value<self.lowLimit): # don't handle occasional high values return self.lBetaLabel.setText(str(value)) if (value<self.lBetamin and value!=0): self.lBetamin = value self.lBetaMinLabel.setText(str(value)) if (value>self.lBetamax): self.lBetamax = value self.lBetaMaxLabel.setText(str(value)) self.lBetarelative = float(value-self.lBetamin)/(self.lBetamax-self.lBetamin+1) self.lBetaRelLabel.setText(str(self.lBetarelative)) sendUdpMessage("sensor,lb"+str(self.sensorNUmber+1)+","+str(self.lBetarelative)) #self.cs.SetChannel("lowBetaRelative",self.lBetarelative) return None def highBeta_callback(self, value): #print "high beta: ", value if (value>self.highLimit or value<self.lowLimit): # don't handle occasional high values return self.hBetaLabel.setText(str(value)) if (value<self.hBetamin and value!=0): self.hBetamin = value self.hBetaMinLabel.setText(str(value)) if (value>self.hBetamax): self.hBetamax = value self.hBetaMaxLabel.setText(str(value)) self.hBetarelative = float(value-self.hBetamin)/(self.hBetamax-self.hBetamin+1) self.hBetaRelLabel.setText(str(self.hBetarelative)) sendUdpMessage("sensor,hb"+str(self.sensorNUmber+1)+","+str(self.hBetarelative)) #self.cs.SetChannel("highBetaRelative",self.hBetarelative) return None def lowGamma_callback(self, value): #print "Low gamma: ", value if (value>self.highLimit or value<self.lowLimit): # don't handle occasional high values return self.lGammaLabel.setText(str(value)) if (value<self.lGammamin and value!=0): self.lGammamin = value self.lGammaMinLabel.setText(str(value)) if (value>self.lGammamax): self.lGammamax = value self.lGammaMaxLabel.setText(str(value)) self.lGammarelative = float(value-self.lGammamin)/(self.lGammamax-self.lGammamin+1) self.lGammaRelLabel.setText(str(self.lGammarelative)) #self.cs.SetChannel("lowBetaRelative",self.lGammarelative) return None def midGamma_callback(self, value): #print "mid gamma: ", value if (value>self.highLimit or value<self.lowLimit): # don't handle occasional high values return self.mGammaLabel.setText(str(value)) if (value<self.mGammamin and value!=0): self.mGammamin = value self.mGammaMinLabel.setText(str(value)) if (value>self.mGammamax): self.mGammamax = value self.mGammaMaxLabel.setText(str(value)) self.mGammarelative = float(value-self.mGammamin)/(self.mGammamax-self.mGammamin+1) self.mGammaRelLabel.setText(str(self.mGammarelative)) #self.cs.SetChannel("midmGammaRelative",self.mGammarelative) return None def attention_callback(self, value): #print "Attention: ",value self.attentionLabel.setText(str(value)) sendUdpMessage("sensor,attention"+str(self.sensorNUmber+1)+","+str(float(value)/100)) #self.cs.SetChannel("attention",value) return None def rawValue_callback(self, value): #this is very fast don't print this #print "rawValue: ", value #self.cs.SetChannel("rawValue",value) if (abs(value)<1000): sendUdpMessage("sensor,raw"+str(self.sensorNUmber+1)+","+str(value)) return None def poorSignal_callback(self,value): print "headset: ",self.sensorNUmber,"poor signal: ",value self.poorSignalLabel.setText(str(value))
from NeuroPy import NeuroPy object1=NeuroPy("/dev/rfcomm0") #If port not given 57600 is automatically assumed #object1=NeuroPy("/dev/rfcomm0") for linux def attention_callback(attention_value): "this function will be called everytime NeuroPy has a new value for attention" print ("Value of attention is",attention_value) #do other stuff (fire a rocket), based on the obtained value of attention_value #do some more stuff return None def blink_callback(blink_value): "this function will be called everytime NeuroPy has a new value for blink" print ("Value of blinks is",blink_value) #do other stuff (fire a rocket), based on the obtained value of attention_value #do some more stuff return None #set call back: object1.setCallBack("attention",attention_callback) object1.setCallBack("blink", blink_callback) #set call back: object1.setCallBack("meditation",attention_callback) #call start method object1.start() while True: if(object1.meditation>70): #another way of accessing data provided by headset (1st being call backs) object1.stop() #if meditation level reaches above 70, stop fetching data from the headset
med.refresh() med.update(-value) value = 0 for v in volume: value = value + v value = value / len(volume) #os.system("amixer sset 'Master' " + str(value) + "% > /dev/null") #do other stuff (fire a rocket), based on the obtained value of attention_value #do some more stuff return None def blink_cb(value): print("Blink " + str(value)) #set call back: object1.setCallBack("attention", attention_callback) object1.setCallBack("meditation", meditation_callback) object1.setCallBack("blinkStrength", blink_cb) #call start method object1.start() try: while True: time.sleep(0.5) except: print("exit") object1.stop()
# if(count>=5): # count=0 # if(count0>=3): # print("left") # return 30 # count0=0 # count1=0 # elif(count1>=3): # print("right") # count0=0 # return 40 # count1=0 # else: # print("null") # count0=0 # count1=0 #with open('dataset3.csv', 'ab') as f: #writer = csv.writer(f) #writer.writerow([object1.attention, object1.meditation, object1.poorSignal, temp, 1]) return None #set call back: object1.setCallBack("midGamma",attention_callback) #call start method object1.start() while True: if(object1.meditation>100): #another way of accessing data provided by headset (1st being call backs) print("geda meditationg too much") #object1.stop() #if meditation level reaches above 70, stop fetching data from the headset
import matplotlib.animation as animation from pyo import * s = Server().boot() npo = NeuroPy('/dev/rfcomm0', 57600) npo.start() def npacb(sigval): print sigval return None #npo.setCallBack("rawValue",npacb) npo.setCallBack("attention", npacb) freqeeg = 512 def crtfrearray(feeg): eegcoll = [] cnteeg = 0 while cnteeg < feeg: eegcoll.append(npo.rawValue) cnteeg += 1 freqs = np.fft.fftfreq(len(eegcoll)) idx = np.argmax(np.abs(np.array(eegcoll))**2) freq = freqs[idx] freqhz = abs(freq * freqeeg) if freqhz > 40 and freqhz < freqeeg:
f.write(str(lowAlpha_value) + '\n') ''' def blinkstrength_callback(blinkstrength_value): print "Value of blinkstrength is", blinkstrength_value return None ''' #set recording timer in minutes nmin = 1 #set call back: #object1.setCallBack("attention",attention_callback) #object1.setCallBack("blinkStrength",blinkstrength_callback) object1.setCallBack("highAlpha", highalpha_callback) object1.setCallBack("lowAlpha", lowalpha_callback) #call start method object1.start() #define an INET, STREAMing socket sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) #define IP address and match port with EEGServer port server_address = (SERVER_ADDRESS, 2222) print >> sys.stderr, 'connecting to %s port %s' % server_address #socket connect requires IP address and also port number sock.connect(server_address) t_end = time.time() + 60 * (nmin) print('start recording')
ser = serial.Serial('/dev/ttyUSB0', 9600); #Default Arduino USB serial def attention_callback(attention_value): print "Attention is",attention_value return None def meditation_callback(meditation_value): print "Meditation is",meditation_value return None def lowBeta_callback(lowBeta_value): print "Low Beta Wave is",lowBeta_value return None #Set call back: object1.setCallBack("attention",attention_callback) object1.setCallBack("meditation",meditation_callback) object1.setCallBack("lowBeta",lowBeta_callback) #Call start method object1.start() while True: if(object1.attention > 70): ser.write(chr(1)) time.sleep(1) if(object1.meditation > 70): ser.write(chr(2)) time.sleep(1) if(object1.lowBeta > 10000): ser.write(chr(3))