forked from Tcm0/PybricksRemoteLayouts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path42100 UPPER HUB EXPERIMENTAL.py
66 lines (56 loc) · 1.7 KB
/
42100 UPPER HUB EXPERIMENTAL.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
#THIS IS AN EXPERIMENTAL VERSION!
#I DON'T HAVE THIS SET. I CAN NOT TEST THIS CODE PROPERLY!
#INSTALLATION:
#Install this on the hub in the upper part. Connect one remote to it
#Install the code for the lower hub on the lower hub. Connect another remote.
#USAGE
#Change "mode" with red buttons on remote (A+B = left mode, C+D = right mode)
from pybricks.pupdevices import *
from pybricks.parameters import *
from pybricks.tools import wait
Motor1 = Motor(Port.A)
Motor2 = Motor(Port.B)
Motor3 = Motor(Port.C)
Motor4 = Motor(Port.D)
remoteControl = Remote()
mode = 0
#main loop
while True:
#update pressed buttons information
pressed = remoteControl.buttons.pressed()
if Button.LEFT in pressed:
mode = 0
elif Button.RIGHT in pressed:
mode = 1
#commands to drive forwards or backwards
if mode == 0:
Motor3.dc(0)
Motor4.dc(0)
if Button.LEFT_PLUS in pressed:
Motor1.dc(100)
elif Button.LEFT_MINUS in pressed:
Motor1.dc(-100)
else:
Motor1.dc(0)
if Button.RIGHT_PLUS in pressed:
Motor2.dc(100)
elif Button.RIGHT_MINUS in pressed:
Motor2.dc(-100)
else:
Motor2.dc(0)
else:
Motor1.dc(0)
Motor2.dc(0)
if Button.LEFT_PLUS in pressed:
Motor3.dc(100)
elif Button.LEFT_MINUS in pressed:
Motor3.dc(-100)
else:
Motor3.dc(0)
if Button.RIGHT_PLUS in pressed:
Motor4.dc(100)
elif Button.RIGHT_MINUS in pressed:
Motor4.dc(-100)
else:
Motor4.dc(0)
wait(100)