-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.ts
More file actions
63 lines (63 loc) · 1.37 KB
/
Copy pathmain.ts
File metadata and controls
63 lines (63 loc) · 1.37 KB
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
function change_states () {
if (state == 1) {
state = 3
} else if (state == 3) {
state = 4
} else if (state == 4) {
state = 2
} else if (state == 2) {
state = 1
}
}
function set_colours () {
if (state == 1) {
red = 1
yellow = 0
green = 0
} else if (state == 3) {
red = 1
yellow = 1
green = 0
} else if (state == 4) {
red = 0
yellow = 0
green = 1
} else if (state == 2) {
red = 0
yellow = 1
green = 0
}
}
function write_lights () {
if (red == 1) {
pins.digitalWritePin(DigitalPin.P1, 1)
} else if (red == 0) {
pins.digitalWritePin(DigitalPin.P1, 0)
}
if (yellow == 1) {
pins.digitalWritePin(DigitalPin.P2, 1)
} else if (yellow == 0) {
pins.digitalWritePin(DigitalPin.P2, 0)
}
if (green == 1) {
pins.digitalWritePin(DigitalPin.P8, 1)
} else if (green == 0) {
pins.digitalWritePin(DigitalPin.P8, 0)
}
}
let green = 0
let yellow = 0
let red = 0
let state = 0
pins.digitalWritePin(DigitalPin.P1, 0)
pins.digitalWritePin(DigitalPin.P2, 0)
pins.digitalWritePin(DigitalPin.P8, 0)
state = 1
basic.forever(function () {
set_colours()
write_lights()
if (input.buttonIsPressed(Button.A)) {
change_states()
basic.pause(1000)
}
})