-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexampleRobotbit.ts
36 lines (32 loc) · 1.4 KB
/
exampleRobotbit.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
/**
* Robotbit example
*/
// Initialization for motors and servos
uxMotion.initializePhaseWidthModulationDriver()
// Initialization for LEDs
uxDisplays.intializeOnboardPixelsRobotbit()
uxMotion.setOrangeGreenGeekservoSpeed(uxMotion.SERVO.ROBOTBIT_SERVO1, 0)
uxMotion.setGreyGeekservoAngle(uxMotion.SERVO.ROBOTBIT_SERVO2, 0)
uxMotion.setLargeGreyGeekservoAngle(uxMotion.SERVO.ROBOTBIT_SERVO3, 0)
uxMotion.setServoPulseWidth(uxMotion.SERVO.ROBOTBIT_SERVO4, 0)
// Sensor and motion example
basic.forever(function () {
let distance = uxSensors.ultrasonicDistanceCatShapedSensor(ux.PIN_NUMBER.PIN10)
if (distance < 5) {
uxMotion.setMotor(uxMotion.MOTOR.ROBOTBIT_M1A, -4095)
uxMotion.setMotor(uxMotion.MOTOR.ROBOTBIT_M1B, -4095)
uxMotion.setOrangeGreenGeekservoSpeed(uxMotion.SERVO.ROBOTBIT_SERVO1, -1024)
uxMotion.setGreyGeekservoAngle(uxMotion.SERVO.ROBOTBIT_SERVO2, 225)
uxMotion.setLargeGreyGeekservoAngle(uxMotion.SERVO.ROBOTBIT_SERVO3, 360)
uxMotion.setServoPulseWidth(uxMotion.SERVO.ROBOTBIT_SERVO4, 2646)
}
else if (distance < 10) {
uxDisplays.setAllOnboardPixels(128, 0, 0)
uxDisplays.refreshOnboardPixels()
} else {
uxMotion.setMotor(uxMotion.MOTOR.ROBOTBIT_M1A, 4095)
uxMotion.setMotor(uxMotion.MOTOR.ROBOTBIT_M1B, 4095)
uxDisplays.setAllOnboardPixels(10, 0, 0)
uxDisplays.refreshOnboardPixels()
}
})