forked from CytronTechnologies/pxt-edubit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.ts
136 lines (105 loc) · 3.65 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// tests go here; this will not be compiled when this package is used as a library
// Play a tone when sound sensor event is raised.
edubitSoundBit.onEvent(SoundSensorCompareType.MoreThan, 512, function () {
music.playTone(262, music.beat(BeatFraction.Whole))
})
// Play a tone when potentiometer event is raised.
edubitPotentioBit.onEvent(PotCompareType.LessThan, 512, function () {
music.playTone(523, music.beat(BeatFraction.Whole))
})
// Play a tone when IR sensor event is raised.
edubitIrBit.onIrSensorEvent(IrEventType.Rise, function () {
music.playTone(988, music.beat(BeatFraction.Whole))
})
// Loop forever.
basic.forever(function () {
// Plot the first row LED according to sound level.
if (edubitSoundBit.readSoundSensor() > 700) {
led.plot(0, 0)
led.plot(1, 0)
} else if (edubitSoundBit.compareSoundSensor(SoundSensorCompareType.MoreThan, 350)) {
led.plot(0, 0)
led.unplot(1, 0)
} else {
led.unplot(0, 0)
led.unplot(1, 0)
}
// Plot the second row LED according to potentiometer value.
if (edubitPotentioBit.readPotValue() > 700) {
led.plot(0, 1)
led.plot(1, 1)
} else if (edubitPotentioBit.comparePot(PotCompareType.MoreThan, 350)) {
led.plot(0, 1)
led.unplot(1, 1)
} else {
led.unplot(0, 1)
led.unplot(1, 1)
}
// Plot the state of the IR sensor on third row LED.
if (edubitIrBit.isIrSensorTriggered()) {
led.plot(0, 2)
}
if (edubitIrBit.readIrSensor() == 0) {
led.unplot(0, 2)
}
// Plot the power input voltage on 4th row LED 1.
if (edubitPower.readVin() > 4.0) {
led.plot(0, 3);
} else {
led.unplot(0, 3);
}
// Plot the power state on 4th row LED 2.
if (edubitPower.isPowerOn()) {
led.plot(1, 3);
} else {
led.unplot(1, 3);
}
// Plot the low batt state on 4th row LED 3.
if (edubitPower.isLowBatt()) {
led.plot(2, 3);
} else {
led.unplot(2, 3);
}
// Plot the overvoltage state on 4th row LED 4.
if (edubitPower.isOvervoltage()) {
led.plot(3, 3);
} else {
led.unplot(3, 3);
}
// RGB-bit / NeoPixel code removed
// Turn on yellow LED on Traffic Light Bit.
edubitTrafficLightBit.setLed(LedColor.Red, 0)
edubitTrafficLightBit.setLed(LedColor.Yellow, 1)
edubitTrafficLightBit.setLed(LedColor.Green, 0)
// Toggle all LEDs on Traffic Light Bit 10 times.
for (let index = 0; index < 10; index++) {
edubitTrafficLightBit.toggleLed(LedColor.Red)
edubitTrafficLightBit.toggleLed(LedColor.Yellow)
edubitTrafficLightBit.toggleLed(LedColor.Green)
basic.pause(200)
}
// Run Motor 1 forward at 50% speed for 1 second.
edubitMotors.runMotor(MotorChannel.M1, MotorDirection.Forward, 127)
basic.pause(1000)
edubitMotors.brakeMotor(MotorChannel.M1)
// Run Motor 2 backward at 100% speed for 1 second.
edubitMotors.runMotor(MotorChannel.M2, MotorDirection.Backward, 255)
basic.pause(1000)
edubitMotors.brakeMotor(MotorChannel.M2)
// Move Servo 1 to 0 degree.
edubitMotors.setServoPosition(ServoChannel.S1, 0)
basic.pause(1000)
// Disable Servo 1.
edubitMotors.disableServo(ServoChannel.S1)
// Move Servo 2 to 180 degrees.
edubitMotors.setServoPosition(ServoChannel.S2, 180)
basic.pause(1000)
// Disable Servo 2.
edubitMotors.disableServo(ServoChannel.S2)
// Move Servo 3 to 0 degree.
edubitMotors.setServoPosition(ServoChannel.S3, 0)
basic.pause(1000)
// Disable Servo 3.
basic.pause(1000)
edubitMotors.disableServo(ServoChannel.S3)
})