-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
52 lines (52 loc) · 1.69 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
52
function right () {
PCA9685.setLedDutyCycle(PCA9685.LEDNum.LED1, 0, 67)
PCA9685.setLedDutyCycle(PCA9685.LEDNum.LED2, 100, 67)
PCA9685.setLedDutyCycle(PCA9685.LEDNum.LED3, 0, 67)
PCA9685.setLedDutyCycle(PCA9685.LEDNum.LED4, 50, 67)
}
function back () {
PCA9685.setLedDutyCycle(PCA9685.LEDNum.LED1, 100, 67)
PCA9685.setLedDutyCycle(PCA9685.LEDNum.LED2, 50, 67)
PCA9685.setLedDutyCycle(PCA9685.LEDNum.LED3, 100, 67)
PCA9685.setLedDutyCycle(PCA9685.LEDNum.LED4, 50, 67)
}
function front () {
PCA9685.setLedDutyCycle(PCA9685.LEDNum.LED1, 0, 67)
PCA9685.setLedDutyCycle(PCA9685.LEDNum.LED2, 50, 67)
PCA9685.setLedDutyCycle(PCA9685.LEDNum.LED3, 0, 67)
PCA9685.setLedDutyCycle(PCA9685.LEDNum.LED4, 50, 67)
}
function left () {
PCA9685.setLedDutyCycle(PCA9685.LEDNum.LED1, 0, 67)
PCA9685.setLedDutyCycle(PCA9685.LEDNum.LED2, 50, 67)
PCA9685.setLedDutyCycle(PCA9685.LEDNum.LED3, 0, 67)
PCA9685.setLedDutyCycle(PCA9685.LEDNum.LED4, 100, 67)
}
function stop () {
PCA9685.reset(67)
}
let distance = 0
PCA9685.init(67, 0)
let strip = neopixel.create(DigitalPin.P5, 18, NeoPixelMode.RGB)
basic.forever(function () {
distance = sonar.ping(
DigitalPin.P14,
DigitalPin.P15,
PingUnit.Centimeters
)
serial.writeNumber(distance)
serial.writeLine("")
if (distance >= 15 && distance <= 30) {
front()
strip.showColor(neopixel.colors(NeoPixelColors.Blue))
}
if (distance <= 10) {
back()
strip.showColor(neopixel.colors(NeoPixelColors.Purple))
}
if (distance > 10 && distance < 15 || distance > 30) {
stop()
strip.showColor(neopixel.colors(NeoPixelColors.Red))
}
basic.pause(100)
})