-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
101 lines (100 loc) · 2.74 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
function turnLeft () {
cuteBot.motors(50, 100)
cuteBot.colorLight(cuteBot.RGBLights.RGB_R, 0x00ff00)
cuteBot.colorLight(cuteBot.RGBLights.RGB_L, 0x000000)
leftled.showColor(neopixel.colors(NeoPixelColors.Green))
rightled.showColor(neopixel.colors(NeoPixelColors.Black))
basic.showLeds(`
. . # . .
. . . # .
# # # # #
. . . # .
. . # . .
`)
}
function goForward () {
cuteBot.motors(100, 100)
cuteBot.colorLight(cuteBot.RGBLights.ALL, 0x00ff00)
strip.showColor(neopixel.colors(NeoPixelColors.Green))
basic.showLeds(`
. . # . .
. # # # .
# . # . #
. . # . .
. . # . .
`)
}
function stop () {
cuteBot.stopcar()
cuteBot.colorLight(cuteBot.RGBLights.ALL, 0xff0000)
strip.showColor(neopixel.colors(NeoPixelColors.Red))
basic.showLeds(`
. . . . .
. # # # .
. # # # .
. # # # .
. . . . .
`)
}
function reverse () {
stop()
cuteBot.colorLight(cuteBot.RGBLights.RGB_R, 0xff8000)
cuteBot.colorLight(cuteBot.RGBLights.RGB_L, 0xff8000)
rightled.showColor(neopixel.colors(NeoPixelColors.Orange))
leftled.showColor(neopixel.colors(NeoPixelColors.Orange))
basic.pause(500)
basic.showLeds(`
. . # . .
. . # . .
# . # . #
. # # # .
. . # . .
`)
cuteBot.moveTime(cuteBot.Direction.backward, 50, 2)
basic.showLeds(`
. . . . .
. # # # .
. # # # .
. # # # .
. . . . .
`)
cuteBot.colorLight(cuteBot.RGBLights.ALL, 0xff0000)
strip.showColor(neopixel.colors(NeoPixelColors.Red))
}
function turnRight () {
cuteBot.motors(100, 50)
cuteBot.colorLight(cuteBot.RGBLights.RGB_R, 0x000000)
cuteBot.colorLight(cuteBot.RGBLights.RGB_L, 0x00ff00)
leftled.showColor(neopixel.colors(NeoPixelColors.Black))
rightled.showColor(neopixel.colors(NeoPixelColors.Green))
basic.showLeds(`
. . # . .
. # . . .
# # # # #
. # . . .
. . # . .
`)
}
radio.onReceivedString(function (receivedString) {
if (receivedString == "forward") {
goForward()
} else if (receivedString == "stop") {
stop()
} else if (receivedString == "left") {
turnLeft()
} else if (receivedString == "right") {
turnRight()
} else if (receivedString == "reverse") {
reverse()
} else {
}
})
// Set up LEDs and assign radio group
let rightled: neopixel.Strip = null
let leftled: neopixel.Strip = null
let strip: neopixel.Strip = null
strip = neopixel.create(DigitalPin.P15, 2, NeoPixelMode.RGB)
leftled = strip.range(0, 1)
rightled = strip.range(1, 1)
radio.setGroup(82)
basic.showIcon(IconNames.Yes)