2018-10-22 22:22:50 +02:00
|
|
|
# Servo Calibrator
|
2017-03-27 06:22:40 +02:00
|
|
|
|
2017-06-21 20:17:25 +02:00
|
|
|
Use this program to calibrate the angles of a servo.
|
|
|
|
Press ``A`` to reduce the angle by 5 and ``B`` to
|
|
|
|
increase it by 5.
|
|
|
|
|
|
|
|
The current angle is displayed on the screen
|
|
|
|
in a loop.
|
|
|
|
|
2017-03-27 06:22:40 +02:00
|
|
|
```blocks
|
|
|
|
let angle = 90
|
|
|
|
input.onButtonPressed(Button.A, () => {
|
2018-09-12 22:26:39 +02:00
|
|
|
angle = Math.max(0, angle - 5)
|
2017-03-27 06:22:40 +02:00
|
|
|
pins.servoWritePin(AnalogPin.P0, angle)
|
|
|
|
led.stopAnimation()
|
|
|
|
})
|
|
|
|
input.onButtonPressed(Button.B, () => {
|
2018-09-12 22:26:39 +02:00
|
|
|
angle = Math.min(180, angle + 5)
|
2017-03-27 06:22:40 +02:00
|
|
|
pins.servoWritePin(AnalogPin.P0, angle)
|
|
|
|
led.stopAnimation()
|
|
|
|
})
|
|
|
|
basic.forever(() => {
|
|
|
|
basic.showNumber(angle)
|
|
|
|
})
|
|
|
|
pins.servoWritePin(AnalogPin.P0, angle)
|
|
|
|
```
|
2019-03-15 21:47:47 +01:00
|
|
|
|
|
|
|
## See also
|
|
|
|
|
|
|
|
[Brief Guide to Servos](https://www.kitronik.co.uk/pdf/a-brief-guide-to-servos.pdf)
|