Pololu Robotics & Electronics
My account Comments or questions? About Pololu Contact Ordering information Distributors

Slowly Move when button is pressed until it reaches limit


Does anyone know how/if you can script a servo to slowly move in a specific direction when a button is pressed and continue to move until it is released (unless it hits a maximum limit). Also since this forum seems to be primarily comprised of Pololu employees I would like to suggest that you offer button adapters in you store (with bare wires at the end to attach a switch or longer wires). Its not that its difficult to do its just that I think at least a few people would be willing to pay to have it pre done professionally just to have it a bit more compact and with proper plugs.

Thx- James


Hello, James.

Probably the simplest way to do something like that would be to do a while loop that runs when the button is pushed and inside the while loop, you can use the get_position command to read the current position of the servo, add some small value to it, and send that as the new target position. Doing it like this will automatically constrain the target position to the limits of the servo channel (configured in the “Channel Settings” tab of the Maestro Configuration Utility). For example, your while loop could look like this:

begin 1 get_position 500 less_than while   #check the button on channel 1
0 get_position 				               #when it is being pressed, check the position of the servo on channel 0
1 plus 0 servo				               #increase the target position by 1 and update the servo
#5 delay				                   #uncommenting the delay here can make it move even slower

Please note that for this to work, it should be placed inside of a main BEGIN/REPEAT' loop. Also, you will probably want to send the servo to an initial position before the mainBEGIN/REPEAT` loop so it always starts enabled and from a valid target location. If you have problems getting this to work, you can post your script here with a description of the problem and I would be glad to help.