-
Notifications
You must be signed in to change notification settings - Fork 0
/
traffic_lights_algorithm.bs2
58 lines (54 loc) · 1.16 KB
/
traffic_lights_algorithm.bs2
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
'{$STAMP BS2}
'{$PBASIC 2.5}
Setup:
'variables
multiplier VAR WORD
counter VAR WORD
'tune this parameter to set cycle rate; increase to lengthen cycle
multiplier = 1
Main:
HIGH 2 'bottom green on
HIGH 5 'top green on
HIGH 6 'left red on
HIGH 9 'right red on
FOR counter = 1 TO (30 * multiplier): 'base 3 seconds
GOSUB MPU6050_Interrupt
PAUSE 100
NEXT
LOW 2 'bottom green off
LOW 5 'top green off
HIGH 1 'bottom yellow on
HIGH 4 'top yellow on
FOR counter = 1 TO (10 * multiplier): 'base 1 second
GOSUB MPU6050_Interrupt
PAUSE 100
NEXT
LOW 1 'bottom yellow off
LOW 4 'top yellow off
LOW 6 'left red off
LOW 9 'right red off
HIGH 0 'bottom red on
HIGH 3 'top red on
HIGH 8 'left green on
HIGH 11 'right green on
FOR counter = 1 TO (30 * multiplier): 'base 3 seconds
GOSUB MPU6050_Interrupt
PAUSE 100
NEXT
LOW 8 'left green off
LOW 11 'right green off
HIGH 7 'left yellow on
HIGH 10 'right yellow on
FOR counter = 1 TO (10 * multiplier): 'base 1 second
GOSUB MPU6050_Interrupt
PAUSE 100
NEXT
LOW 7 'left yellow off
LOW 10 'right yellow off
LOW 0 'bottom red off
LOW 3 'top red off
'loop
GOTO Main
END
MPU6050_Interrupt:
RETURN