-
Notifications
You must be signed in to change notification settings - Fork 0
/
microbit_servo_move.js
64 lines (64 loc) · 1.59 KB
/
microbit_servo_move.js
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
let updt_servo = 0
let result = ""
serial.redirect(
SerialPin.USB_TX,
SerialPin.USB_RX,
BaudRate.BaudRate9600
)
let _default = 20
let servo1_pos = _default
let servo2_pos = _default
pins.servoWritePin(AnalogPin.P0, servo1_pos)
pins.servoWritePin(AnalogPin.P1, servo2_pos)
basic.forever(function () {
result = serial.readLine()
if (result == "up") {
basic.showLeds(`
. . # . .
. # # # .
# . # . #
. . # . .
. . # . .
`)
servo1_pos += 5
} else if (result == "down") {
basic.showLeds(`
. . # . .
. . # . .
# . # . #
. # # # .
. . # . .
`)
servo1_pos += -5
} else if (result == "left") {
basic.showLeds(`
. . # . .
. # . . .
# # # # #
. # . . .
. . # . .
`)
servo2_pos += 5
} else if (result == "right") {
basic.showLeds(`
. . # . .
. . . # .
# # # # #
. . . # .
. . # . .
`)
servo2_pos += -5
} else if (result == "stop") {
basic.showIcon(IconNames.No)
updt_servo = 0
} else if (result == "reset") {
basic.showIcon(IconNames.SmallSquare)
servo1_pos = _default
servo2_pos = _default
}
if (updt_servo) {
pins.servoWritePin(AnalogPin.P0, servo1_pos)
pins.servoWritePin(AnalogPin.P1, servo2_pos)
}
updt_servo = 1
})