User Manual

This example uses one range for deciding where to go when making a transition, then it waits for the
servo to leave a slightly larger range before making another transition. As long as the difference (10 in
this example) is larger than the amount of noise, this will prevent the random jumping.
Note that this example will only work if you connect your potentiometer to one of the analog input
capable channels (channels 0–11). The inputs on the other channels are digital.
Using a button or switch to control servos
It is possible to connect a button or switch to a Maestro and detect the state of the button in your script.
The script below moves a servo through a predefined sequence of movements, advancing to the next
step each time the button is pushed. It uses channel 0 for the button and channel 1 for the servo.
The button channel must be configured as an input and wired correctly. See Section 7.b for
instructions on how to wire a button to your Maestro using a pull-up resistor, so that the input is
normally high, and when the button is pressed it goes low.
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
# Set the servo to 4000, 6000, or 8000 depending on an analog input, with hysteresis.
begin
4000 0 300 servo_range
6000 300 600 servo_range
8000 600 1023 servo_range
repeat
# usage: <pos> <low> <high> servo_range
# If the pot is in the range specified by low and high,
# keeps servo 0 at pos until the pot moves out of this
# range, with hysteresis.
sub servo_range
pot 2 pick less_than logical_not # >= low
pot 2 pick greater_than logical_not # <= high
logical_and
if
begin
pot 2 pick 10 minus less_than logical_not # >= low - 10
pot 2 pick 10 plus greater_than logical_not # <= high + 10
logical_and
while
2 pick 0 servo
repeat
endif
drop drop drop
return
sub pot
1 get_position
return
?
Pololu Maestro Servo Controller User’s Guide © 2001–2019 Pololu Corporation
6. The Maestro Scripting Language Page 83 of 102