-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
89 lines (88 loc) · 2.37 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
function sendDirection () {
RadioString = ""
for (let value of Directions) {
RadioString = "" + RadioString + value + ","
}
radio.sendString(RadioString)
PlayRobot()
Directions = []
}
function PlayRobot () {
basic.showIcon(IconNames.Ghost)
for (let value2 of RadioString.split(",")) {
showDirection(value2)
}
basic.showIcon(IconNames.Yes)
}
input.onButtonPressed(Button.A, function () {
huskylens.request()
if (huskylens.isAppear(1, HUSKYLENSResultType_t.HUSKYLENSResultBlock)) {
showDirection("L")
Directions.push("L")
} else if (huskylens.isAppear(2, HUSKYLENSResultType_t.HUSKYLENSResultBlock)) {
showDirection("R")
Directions.push("R")
} else if (huskylens.isAppear(3, HUSKYLENSResultType_t.HUSKYLENSResultBlock)) {
showDirection("F")
Directions.push("F")
} else if (huskylens.isAppear(4, HUSKYLENSResultType_t.HUSKYLENSResultBlock)) {
basic.showString("GO!")
basic.showIcon(IconNames.Yes)
music.ringTone(988)
music.rest(music.beat(BeatFraction.Double))
sendDirection()
} else {
basic.showNumber(huskylens.readBox_s(Content3.ID))
basic.pause(500)
basic.showIcon(IconNames.No)
basic.pause(500)
music.ringTone(131)
}
basic.clearScreen()
})
input.onButtonPressed(Button.B, function () {
Directions = []
basic.showIcon(IconNames.No)
basic.pause(500)
})
function showDirection (Direction2: string) {
if (Direction2 == "L") {
basic.showLeds(`
. . # . .
. # . . .
# # # # #
. # . . #
. . # . #
`)
} else if (Direction2 == "R") {
basic.showLeds(`
. . # . .
. . . # .
# # # # #
# . . # .
# . # . .
`)
} else if (Direction2 == "F") {
basic.showLeds(`
. . # . .
. # # # .
# . # . #
. . # . .
. . # . .
`)
} else {
basic.showIcon(IconNames.No)
}
basic.pause(1000)
basic.clearScreen()
basic.pause(200)
music.ringTone(988)
}
let RadioString = ""
let Directions: string[] = []
huskylens.initI2c()
huskylens.initMode(protocolAlgorithm.OBJECTCLASSIFICATION)
Directions = []
radio.setGroup(33)
basic.forever(function () {
})