-
Notifications
You must be signed in to change notification settings - Fork 0
/
final_video_code.py
148 lines (132 loc) · 4.91 KB
/
final_video_code.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
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
145
146
147
148
import serial
import time
import pyautogui
previous_command = False
next_command = False
speed = 0
for_pause = True
ports = ["com6 " , "com11"]
#ports = ["com6"]
# com7 for pedal com8 for handle
while 1:
for i in ports:
ArduinoSerial = serial.Serial(i,9600) #Create Serial port object called arduinoSerialData
time.sleep(2) #wait for 2 seconds for the communication to get established
incoming = str(ArduinoSerial.readline()) #read the serial data and print it as line
print(incoming)
if i==ports[0]:
if 'rest' in incoming:
#speed = 0
for_pause = True
if speed>0:
pyautogui.press('space')
if 'play' in incoming and for_pause==True:
for_pause=False
#pyautogui.typewrite(['space'], 0.2)
pyautogui.press('space')
if speed<=5:
for i in range(speed+5):
print(i)
speed+=2
#pyautogui.typewrite([''], 0.2)
pyautogui.press(']')
pyautogui.press(']')
#time.sleep(10)
else:
for i in range(speed):
speed-=1
pyautogui.press('[')
#time.sleep(10)
speed = 0
#pyautogui.press('space')
if 'speedUp0' in incoming:
for_pause = True
if speed<=10:
speed+=6
pyautogui.press(']')
pyautogui.press(']')
pyautogui.press(']')
pyautogui.press(']')
pyautogui.press(']')
pyautogui.press(']')
#time.sleep(10)
else:
for i in range(0,speed-10):
speed-=1
pyautogui.press('[')
#time.sleep(10)
if 'speedUp1' in incoming:
for_pause = True
if speed<=20:
speed+=3
pyautogui.press(']')
pyautogui.press(']')
pyautogui.press(']')
pyautogui.press(']')
pyautogui.press(']')
pyautogui.press(']')
#time.sleep(20)
else:
for i in range(0,speed-20):
speed-=1
pyautogui.press('[')
time.sleep(10)
if 'speedUp2' in incoming:
for_pause = True
if speed<=30:
speed+=6
pyautogui.press(']')
pyautogui.press(']')
pyautogui.press(']')
pyautogui.press(']')
pyautogui.press(']')
pyautogui.press(']')
#time.sleep(20)
else:
for i in range(0,speed-30):
pyautogui.press('[')
#time.sleep(10)
if 'speedUp3' in incoming:
for_pause = True
if speed<=40:
speed+=6
pyautogui.press(']')
pyautogui.press(']')
pyautogui.press(']')
pyautogui.press(']')
pyautogui.press(']')
pyautogui.press(']')
#time.sleep(20)
else:
for i in range(0,speed-40):
pyautogui.press('[')
#time.sleep(10)
if 'speedmax' in incoming:
for_pause= True
pyautogui.press(']')
time.sleep(5)
else:
if len(incoming)>4:
print(incoming)
for i in range(2,len(incoming)):
if not incoming[i].isdigit():
l = incoming[2:i]
break
incoming = int(l)
left = 230
right = 130
rest = 180
delta1 = 20
delta2 = 20
if (incoming<=(left+delta2) and incoming>=(left-delta2)) and previous_command==False:
pyautogui.press('p')
print("previous")
previous_command = True
elif (incoming<=(rest+delta1) and incoming>=(rest-delta1)):
print("same")
previous_command = False
next_command = False
elif (incoming<=(right+delta1) and incoming>=(right-delta1)) and next_command==False:
print("right")
pyautogui.press('n')
next_command = True