-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathpedestrian.py
50 lines (47 loc) · 1.35 KB
/
pedestrian.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
#
# Traffic Light with Pedestrian Crossing
#
from microbit import *
# We are just using a buzzer for one tone,
# but this include is the easiest way to do this
import music
# Run this over and over forever
while True:
# Set the traffic light to GO
pin13.write_digital(0)
pin2.write_digital(1)
pin12.write_digital(1)
# Read the button, if it is pressed then
# do the crossing animation
if button_a.is_pressed():
# Now do the crossing routine
pin13.write_digital(1)
sleep(5000)
pin2.write_digital(0)
pin1.write_digital(1)
sleep(1000)
pin1.write_digital(0)
pin16.write_digital(1)
sleep(2000)
pin8.write_digital(1)
pin12.write_digital(0)
pin13.write_digital(0)
for counta in range(0,40):
music.pitch(1600, 100)
sleep(80)
for countb in range (0,10):
pin8.write_digital(0)
sleep(200)
pin8.write_digital(1)
sleep(200)
pin8.write_digital(0)
pin12.write_digital(1)
sleep(2000)
pin1.write_digital(1)
sleep(1000)
pin1.write_digital(0)
pin2.write_digital(1)
pin16.write_digital(0)
# Now we keep traffic moving for at least 30 Seconds
# stops the crossing from being permanently on
sleep(30000)