-
Notifications
You must be signed in to change notification settings - Fork 2
/
exampleSuperbit.ts
46 lines (41 loc) · 1.82 KB
/
exampleSuperbit.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
/**
* Superbit example
*/
let b = false
let a = false
// Initialization for motors and servos
uxMotion.initializePhaseWidthModulationDriver()
// Initialization for LEDs
uxDisplays.intializeOnboardPixelsSuperbit()
uxMotion.setOrangeGreenGeekservoSpeed(uxMotion.SERVO.SUPERBIT_SERVO1, 0)
uxMotion.setGreyGeekservoAngle(uxMotion.SERVO.SUPERBIT_SERVO2, 0)
uxMotion.setLargeGreyGeekservoAngle(uxMotion.SERVO.SUPERBIT_SERVO3, 0)
uxMotion.setServoPulseWidth(uxMotion.SERVO.SUPERBIT_SERVO4, 0)
// Motion example
basic.forever(function () {
a = input.buttonIsPressed(Button.A)
b = input.buttonIsPressed(Button.B)
if (a && !(b)) {
uxMotion.setMotor(uxMotion.MOTOR.SUPERBIT_M1, -4095)
uxMotion.setMotor(uxMotion.MOTOR.SUPERBIT_M2, -4095)
} else if (b && !(a)) {
uxMotion.setMotor(uxMotion.MOTOR.SUPERBIT_M1, 4095)
uxMotion.setMotor(uxMotion.MOTOR.SUPERBIT_M2, 4095)
uxDisplays.setAllOnboardPixels(128, 0, 0)
uxDisplays.refreshOnboardPixels()
} else if (a && b) {
uxDisplays.setAllOnboardPixels(10, 0, 10)
uxDisplays.refreshOnboardPixels()
uxMotion.setOrangeGreenGeekservoSpeed(uxMotion.SERVO.SUPERBIT_SERVO1, -1024)
uxMotion.setGreyGeekservoAngle(uxMotion.SERVO.SUPERBIT_SERVO2, 225)
uxMotion.setLargeGreyGeekservoAngle(uxMotion.SERVO.SUPERBIT_SERVO3, 359)
uxMotion.setServoPulseWidth(uxMotion.SERVO.SUPERBIT_SERVO4, 2646)
} else {
uxDisplays.setAllOnboardPixels(0, 10, 10)
uxDisplays.refreshOnboardPixels()
uxMotion.setOrangeGreenGeekservoSpeed(uxMotion.SERVO.SUPERBIT_SERVO1, 1024)
uxMotion.setGreyGeekservoAngle(uxMotion.SERVO.SUPERBIT_SERVO2, -45)
uxMotion.setLargeGreyGeekservoAngle(uxMotion.SERVO.SUPERBIT_SERVO3, 0)
uxMotion.setServoPulseWidth(uxMotion.SERVO.SUPERBIT_SERVO4, 5946)
}
})