forked from resolute-support/pxt-apprentice_Car
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.ts
87 lines (78 loc) · 2.2 KB
/
test.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
// tests go here; this will not be compiled when this package is used as an extension.
kBit.carStop()
function testNeopixel() {
strip.clear()
basic.pause(500)
strip.showColor(neopixel.colors(NeoPixelColors.White))
strip.show()
basic.pause(500)
strip.showColor(neopixel.colors(NeoPixelColors.Red))
strip.show()
basic.pause(500)
strip.showColor(neopixel.colors(NeoPixelColors.Orange))
strip.show()
basic.pause(500)
strip.showColor(neopixel.colors(NeoPixelColors.Yellow))
strip.show()
basic.pause(500)
strip.showColor(neopixel.colors(NeoPixelColors.Green))
strip.show()
basic.pause(500)
strip.showColor(neopixel.colors(NeoPixelColors.Blue))
strip.show()
basic.pause(500)
strip.clear()
}
if (irRemote.returnIrButton() == irRemote.irButton(KBitIrButtons.Ok)) {
}
function followLine() {
let tracking_values = kBit.lineTracking()
if (tracking_values == 1) {
kBit.run(KBitDir.TurnRight, 40)
} else if (tracking_values == 2) {
kBit.run(KBitDir.TurnLeft, 40)
} else if (tracking_values == 3) {
kBit.run(KBitDir.RunForward, 30)
} else {
basic.clearScreen()
}
}
function testMovement() {
kBit.run(KBitDir.RunForward, 40)
basic.pause(1000)
kBit.carStop()
basic.pause(500)
kBit.run(KBitDir.RunBack, 40)
basic.pause(1000)
kBit.carStop()
basic.pause(500)
kBit.run(KBitDir.TurnLeft, 40)
basic.pause(1000)
kBit.carStop()
basic.pause(500)
kBit.run(KBitDir.TurnRight, 40)
basic.pause(1000)
kBit.carStop()
basic.pause(500)
kBit.carStop()
}
//change pin to pin 5
let strip = neopixel.create(DigitalPin.P8, 18, NeoPixelMode.RGB)
/**
* Testing the neopixel should show red, orange, yellow, green and blue, for a second each
*/
testNeopixel()
/**
* Testing the motors will make the robot move forwards, backwards, turn left and turn right
*/
testMovement()
/**
* After testing the neopixel and the motors, the microbit will display the
* distance the ultrasonic sensor measures on neopixel ring
*/
basic.forever(function () {
serial.writeNumber(kBit.ultra())
serial.writeLine("")
strip.showBarGraph(kBit.ultra(), 30)
followLine()
})