I have some code which I am trying to run, basically the system should draw the tkinter canvas then constantly monitor the headset results - currently it seems to only run the code once rather than (as I expected) loop through the if statement.
Any suggestions would be most appreciated.
A
import Tkinter as tk
import serial
import mindwave
import time
headset = mindwave.Headset('/dev/ttyUSB0', 'AF66')
while headset.status != 'connected':
time.sleep(0.5)
if headset.status == 'standby':
headset.connect()
print ("Retrying connect...")
print(headset.status)
arduino = serial.Serial('/dev/ttyACM0', 9600)
count = 0
value = '0'
points = [
[250,250,350,250,350,350,250,350],
[300,100,500,500,100,500],
[100,100,100,500,500,300],
[100,100,500,100,300,500],
[100,300,500,100,500,500],
]
root = tk.Tk()
# set window to middle of screen
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
xcoord = screen_width//2 - 300
ycoord = screen_height//2 - 300
root.geometry("%dx%d+%d+%d" % (600,600,xcoord,ycoord))
#set up canvas
canvas1 = tk.Canvas(root, relief=tk.FLAT, background="blue")
canvas1.pack(fill=tk.BOTH, expand=1)
# create the polygon with tag "button"
canvas1.create_polygon(points[count], fill="darkgreen", outline="yellow", tag="button")
#monitor attention results
if headset.attention > 70:
print("Attention: %s, Meditation: %s" % (headset.attention, headset.meditation))
else:
print("attention too low")
time.sleep(.2)