-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdraw_mindwave
More file actions
144 lines (126 loc) · 5.68 KB
/
draw_mindwave
File metadata and controls
144 lines (126 loc) · 5.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import time
import bluetooth
import serial
from mindwavemobile.MindwaveDataPoints import RawDataPoint
from mindwavemobile.MindwaveDataPointReader import MindwaveDataPointReader
import textwrap
import matplotlib.pyplot as plt
import numpy as np
colors = ['b', 'c', 'y', 'm', 'r']
# You probably won't need this if you're embedding things in a tkinter plot...
plt.ion()
x=0
fig = plt.figure()
ax = fig.add_subplot(111)
#ser = serial.Serial('COM11', 9600) ## 9600 is your baud rate
"""
Meditation Level: 0
Attention Level: 0
EEG Powers:
delta: 1682408
theta: 15655
lowAlpha: 72844
highAlpha: 48227
lowBeta: 21979
highBeta: 15213
lowGamma: 39352
midGamma: 8628
Poor Signal Level: 55
"""
open_sill=close_sill=4
state=0
aa=10
t=""
meditation=attention=Poor=0
x=midGamma_y=theta_y=lowGamma_y=highBeta_y=lowBeta_y=highAlpha_y=lowAlpha_y=delta_y=0
xx=1
if __name__ == '__main__':
mindwaveDataPointReader = MindwaveDataPointReader()
mindwaveDataPointReader.start()
if (mindwaveDataPointReader.isConnected()):
while(True):
dataPoint = mindwaveDataPointReader.readNextDataPoint()
if (not dataPoint.__class__ is RawDataPoint):
t=dataPoint.__str__()
if (t[0]=='M'):
meditation=dataPoint.meditationValue
# print dataPoint.meditationValue
elif (t[0]=='A'):
attention=dataPoint.attentionValue
# print dataPoint.attentionValue
elif (t[0]=='P'):
aa-=1
Poor=dataPoint.amountOfNoise
if(Poor>75):
print "Poor Signal"
open_sill=close_sill=2
else :
if (attention>=75):
print ("Attention:%d",attention)
elif (attention<=25) :
print ("Inattention:%d",attention)
else :
print ("Medium attention:%d",attention)
if (meditation>=75):
print ("Meditation:%d",meditation)
open_sill=2
if (close_sill<=0):
ser.write('0')
else :
close_sill-=1
elif ((meditation<=35 and meditation>0) or (attention>=75)) :
print ("Impatient:%d",meditation)
close_sill=2
if (open_sill<=0):
ser.write('1')
else :
open_sill-=1
else :
open_sill=close_sill=2
print ("Medium Meditation:%d",meditation)
# print dataPoint.amountOfNoise
elif (t[0]=='E' and aa<=0):
# next_delta_y=dataPoint.delta
# plt.plot([x,x+1],[delta_y,next_delta_y],label="$Delta$",color="red")
# delta_y=next_delta_y
# print dataPoint.delta
# next_theta_y = dataPoint.theta
# plt.plot([x,x+1],[theta_y,next_theta_y],label="$Theta$",color="g")
# theta_y=next_theta_y
# print dataPoint.theta
next_lowAlpha_y = dataPoint.lowAlpha
plt.plot([x,x+1],[lowAlpha_y,next_lowAlpha_y],label="$lowAlpha$",color="g")
# lowAlpha_y=next_lowAlpha_y
# print dataPoint.lowAlpha
lowAlpha_y=next_lowAlpha_y
# lowAlpha_y=next_highAlpha_y = dataPoint.highAlpha
# plt.plot([xx,xx+1],[next_lowAlpha_y,next_highAlpha_y],label="$highAlpha$",color="g")
# highAlpha_y=next_highAlpha_y
# print dataPoint.highAlpha
next_lowBeta_y = dataPoint.lowBeta
plt.plot([x,x+1],[lowBeta_y,next_lowBeta_y],label="$lowBeta_$",color="b")
# lowBeta_y=next_lowBeta_y
# print dataPoint.lowBeta
lowBeta_y=next_lowBeta_y
#lowBeta_y=next_highBeta_y = dataPoint.highBeta
# plt.plot([xx,xx+1],[next_lowBeta_y,next_highBeta_y],label="$highBeta_$",color="b")
# highBeta_y=next_highBeta_y
# print dataPoint.highBeta
next_lowGamma_y = dataPoint.lowGamma
plt.plot([x,x+1],[lowGamma_y,next_lowGamma_y],label="$lowGamma_$",color="red")
# theta_y=next_theta_y
# print dataPoint.lowGamma
lowGamma_y=next_lowGamma_y
# lowGamma_y=next_midGamma_y = dataPoint.midGamma
# plt.plot([xx,xx+1],[next_lowGamma_y,next_midGamma_y],label="$midGamma_$",color="red")
# midGamma_y=next_midGamma_y
# print dataPoint.midGamma
fig.canvas.draw()
x=x+1
# xx=x+1
# print dataPoint.__str__()
else:
print(textwrap.dedent("""\
Exiting because the program could not connect
to the Mindwave Mobile device.""").replace("\n", " "))
ser.close()