-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathMovementTesting.py
68 lines (48 loc) · 1.5 KB
/
MovementTesting.py
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
import serial, serial.tools.list_ports
import time
# pip install pyserial
def main():
# finds available serial ports
com = findPort()
# Serial object
arduino = serial.Serial(com, 9600, timeout=1)
# While loop to test mouse movements in game
while True:
print ("Enter move X")
moveX = str(input())
print ("Enter move Y")
moveY = str(input())
print ("Moving X coord:", moveX)
print ("Moving y coord:", moveY)
# waits 5 seconds to send commands. Gives time to switch to game
time.sleep(5)
# writes move comand to serial object
arduino.write((moveX + ':' + moveY + 'x').encode())
print('Done. To quit enter q')
# if q is entered end the program
if moveX == 'q' or moveY == 'q':
break
# Finds available ports
def findPort():
# Find all serial ports available
ports = list(serial.tools.list_ports.comports())
# Create array for storing ports
choices = []
# create variable to increment number of choices
choiceNum = 0
print()
print('select the number of your serial port')
# add all serial ports to array
for i in ports:
i = str(i).split(' ')
choices.append(i[0])
print(str(choiceNum) + ' - ' + i[0])
choiceNum += 1
port = int(input())
# returns serial port to main function
try:
return choices[port]
except:
print('choose a valid number')
findPort()
main()