-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
51 lines (51 loc) · 1.43 KB
/
main.ts
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
function setamber () {
pins.analogWritePin(AnalogPin.P0, 767)
pins.analogWritePin(AnalogPin.P1, 63)
pins.analogWritePin(AnalogPin.P2, 0)
for (let index = 0; index < 1; index++) {
basic.pause(100)
}
images.iconImage(IconNames.Sad).showImage(0)
}
function setred () {
pins.analogWritePin(AnalogPin.P0, 511)
pins.analogWritePin(AnalogPin.P1, 0)
pins.analogWritePin(AnalogPin.P2, 0)
for (let index = 0; index < 2; index++) {
basic.pause(100)
}
text = text_list[randint(0, text_list.length - 1)]
basic.showString("" + (text))
images.iconImage(IconNames.Skull).showImage(0)
}
function setgreen () {
pins.analogWritePin(AnalogPin.P0, 0)
pins.analogWritePin(AnalogPin.P1, 511)
pins.analogWritePin(AnalogPin.P2, 0)
images.iconImage(IconNames.Heart).showImage(0)
}
let distance = 0
let text = ""
let text_list: string[] = []
pins.analogWritePin(AnalogPin.P0, 0)
pins.analogWritePin(AnalogPin.P1, 0)
pins.analogWritePin(AnalogPin.P2, 0)
let safe = 175
let unsafe = 125
text_list = ["Uh-oh!", "Eeek!", "Oops!", "Eff-off!", "Wibble!"]
basic.forever(function () {
distance = sonar.ping(
DigitalPin.P8,
DigitalPin.P16,
PingUnit.Centimeters
)
basic.showNumber(distance)
if (distance == 0 || distance > safe) {
setgreen()
} else if (distance > unsafe) {
setamber()
} else if (distance < unsafe) {
setred()
}
basic.pause(5000)
})