-
Notifications
You must be signed in to change notification settings - Fork 4
/
demo.py
59 lines (48 loc) · 1.13 KB
/
demo.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
from lc import LionChief
import time
# Replace this mac address with the one
# belonging to your train
chief = LionChief("44:A6:E5:41:AE:72")
chief.set_bell_pitch(1)
# Gracefully start or stop
def ramp(start_speed, end_speed):
speed = start_speed
while speed != end_speed:
chief.set_speed(speed)
if speed > end_speed:
speed -= 1
else:
speed += 1
time.sleep(0.2)
chief.set_speed(end_speed)
while True:
# Let the conductor say something
chief.speak()
# Have to give adequate to speak, otherwise horn
# will cut off the conductor's voice
time.sleep(3.5)
# Time to go
chief.set_horn(True)
ramp(0, 6)
# Turn the horn off
time.sleep(2)
chief.set_horn(False)
# Keep training along
time.sleep(10)
# Reverse
ramp(6, 0)
chief.set_reverse(True)
ramp(0, 6)
time.sleep(10)
# Back to normal
ramp(6, 0)
chief.set_reverse(False)
ramp(0, 6)
time.sleep(40)
# This is our stop
chief.set_bell(True)
time.sleep(1)
ramp(6, 0)
time.sleep(1)
chief.set_bell(False)
time.sleep(180)