-
Notifications
You must be signed in to change notification settings - Fork 0
/
Radio Receiver.txt
87 lines (85 loc) · 3.68 KB
/
Radio Receiver.txt
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
// Set radio group so that the micro:bits can
// communicate with each other
radio.setGroup(1)
basic.showString("R")
radio.onDataPacketReceived( ({ receivedString }) => {
// To Stop (when "S" is received), reset everything
if (receivedString == "S") {
pins.analogWritePin(AnalogPin.P0, 0)
pins.analogWritePin(AnalogPin.P2, 0)
pins.digitalWritePin(DigitalPin.P1, 0)
pins.digitalWritePin(DigitalPin.P8, 0)
pins.digitalWritePin(DigitalPin.P12, 0)
pins.digitalWritePin(DigitalPin.P16, 0)
basic.showString("S")
// To move Forward (when "F" is received)),
// move both wheels in forward direction
} else if (receivedString == "F") {
pins.analogWritePin(AnalogPin.P0, 1000)
pins.analogWritePin(AnalogPin.P2, 1000)
pins.digitalWritePin(DigitalPin.P1, 1)
pins.digitalWritePin(DigitalPin.P8, 0)
pins.digitalWritePin(DigitalPin.P12, 1)
pins.digitalWritePin(DigitalPin.P16, 0)
basic.showArrow(ArrowNames.North)
// If move Forward Right (when "FR" is received),
// move only right wheel in forward direction
} else if (receivedString == "FR") {
pins.analogWritePin(AnalogPin.P0, 0)
pins.analogWritePin(AnalogPin.P2, 1000)
pins.digitalWritePin(DigitalPin.P1, 0)
pins.digitalWritePin(DigitalPin.P8, 0)
pins.digitalWritePin(DigitalPin.P12, 1)
pins.digitalWritePin(DigitalPin.P16, 0)
basic.showArrow(ArrowNames.NorthEast)
// If move Forward Left (when "FL" is received),
// move only left wheel in forward direction
} else if (receivedString == "FL") {
pins.analogWritePin(AnalogPin.P0, 1000)
pins.analogWritePin(AnalogPin.P2, 0)
pins.digitalWritePin(DigitalPin.P1, 1)
pins.digitalWritePin(DigitalPin.P8, 0)
pins.digitalWritePin(DigitalPin.P12, 0)
pins.digitalWritePin(DigitalPin.P16, 0)
basic.showArrow(ArrowNames.NorthWest)
// To move Backward (when "B" is received)),
// move both wheels in reverse direction
} else if (receivedString == "B") {
pins.analogWritePin(AnalogPin.P0, 1000)
pins.analogWritePin(AnalogPin.P2, 1000)
pins.digitalWritePin(DigitalPin.P1, 0)
pins.digitalWritePin(DigitalPin.P8, 1)
pins.digitalWritePin(DigitalPin.P12, 0)
pins.digitalWritePin(DigitalPin.P16, 1)
basic.showArrow(ArrowNames.South)
// If move Backward Right (when "BR" is received),
// move only right wheel in reverse direction
} else if (receivedString == "BR") {
pins.analogWritePin(AnalogPin.P0, 0)
pins.analogWritePin(AnalogPin.P2, 1000)
pins.digitalWritePin(DigitalPin.P1, 0)
pins.digitalWritePin(DigitalPin.P8, 0)
pins.digitalWritePin(DigitalPin.P12, 0)
pins.digitalWritePin(DigitalPin.P16, 1)
basic.showArrow(ArrowNames.SouthEast)
// If move Backward Left (when "BL" is received),
// move only left wheel in reverse direction
} else if (receivedString == "BL") {
pins.analogWritePin(AnalogPin.P0, 1000)
pins.analogWritePin(AnalogPin.P2, 0)
pins.digitalWritePin(DigitalPin.P1, 0)
pins.digitalWritePin(DigitalPin.P8, 1)
pins.digitalWritePin(DigitalPin.P12, 0)
pins.digitalWritePin(DigitalPin.P16, 0)
basic.showArrow(ArrowNames.SouthWest)
// Reset everything to stop the mini bot
} else {
pins.analogWritePin(AnalogPin.P0, 0)
pins.analogWritePin(AnalogPin.P2, 0)
pins.digitalWritePin(DigitalPin.P1, 0)
pins.digitalWritePin(DigitalPin.P8, 0)
pins.digitalWritePin(DigitalPin.P12, 0)
pins.digitalWritePin(DigitalPin.P16, 0)
basic.showString("S")
}
})