-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexamplePowerbrick.ts
36 lines (32 loc) · 1.5 KB
/
examplePowerbrick.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
/**
* Powerbrick example
*/
// Initialization for motors and servos
uxMotion.initializePhaseWidthModulationDriver()
// Powerbrick display example
uxDisplays.intializePowerbrickPixels(ux.PIN_NUMBER.PowerbrickPort3_DigitalA)
uxMotion.setOrangeGreenGeekservoSpeed(uxMotion.SERVO.POWERBRICK_SERVO1, 0)
uxMotion.setGreyGeekservoAngle(uxMotion.SERVO.POWERBRICK_SERVO2, 0)
uxMotion.setLargeGreyGeekservoAngle(uxMotion.SERVO.POWERBRICK_SERVO3, 0)
uxMotion.setServoPulseWidth(uxMotion.SERVO.POWERBRICK_SERVO4, 0)
// Sensor and motion example
basic.forever(function () {
let distance = uxSensors.ultrasonicDistancePowerbrickUltrasonicModule(ux.PIN_NUMBER.PowerbrickPort2_DigitalA)
if (distance < 5) {
uxMotion.setMotor(uxMotion.MOTOR.POWERBRICK_M1, -4095)
uxMotion.setMotor(uxMotion.MOTOR.POWERBRICK_M2, -4095)
uxMotion.setOrangeGreenGeekservoSpeed(uxMotion.SERVO.POWERBRICK_SERVO1, -1024)
uxMotion.setGreyGeekservoAngle(uxMotion.SERVO.POWERBRICK_SERVO2, 225)
uxMotion.setLargeGreyGeekservoAngle(uxMotion.SERVO.POWERBRICK_SERVO3, 360)
uxMotion.setServoPulseWidth(uxMotion.SERVO.POWERBRICK_SERVO4, 2646)
}
else if (distance < 10) {
uxDisplays.setPowerbrickAllPixels(128, 0, 0)
uxDisplays.refreshPowerbrickPixels()
} else {
uxMotion.setMotor(uxMotion.MOTOR.POWERBRICK_M1, 4095)
uxMotion.setMotor(uxMotion.MOTOR.POWERBRICK_M2, 4095)
uxDisplays.setPowerbrickAllPixels(10, 0, 0)
uxDisplays.refreshPowerbrickPixels()
}
})