- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython-controller.py
More file actions
Latest commit
33 lines (32 loc) · 979 Bytes
/
Copy pathpython-controller.py
File metadata and controls
33 lines (32 loc) · 979 Bytes
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
importserial
importtime
importkeyboard
arduino=serial.Serial(port='COM3', baudrate=9600, timeout=.1)
olddata=''
text=''
while(True):
data=arduino.readline()
try:
data=str(data, 'utf-8')
if('x'indata):
if(int(data[1:]) >1024/2+1024/4):
keyboard.press('right')
keyboard.release('left')
elif(int(data[1:]) <1024/2-1024/4):
keyboard.press('left')
keyboard.release('right')
else:
keyboard.release('left')
keyboard.release('right')
elif('y'indata):
if(int(data[1:]) >1024/2+1024/4):
keyboard.press('up')
elif(int(data[1:]) <1024/2-1024/4):
keyboard.press('down')
else:
keyboard.release('up')
keyboard.release('down')
except:
pass
if(keyboard.is_pressed('F6')):
break