Controlling a servo
dcgartin
Posts: 6
Hello,
I have modified a servo for 360 degrees of continuous rotation, and I have written some code to make the servo rotate 1 degree every time I press a button on the keyboard and press enter. The problem is I have to hit enter each time and repeatedly hit the key to keep it going. Is there a way to program it so I can just hold the key down and it continue to move till I take my finger off?
Thanks,
Chadd
I have modified a servo for 360 degrees of continuous rotation, and I have written some code to make the servo rotate 1 degree every time I press a button on the keyboard and press enter. The problem is I have to hit enter each time and repeatedly hit the key to keep it going. Is there a way to program it so I can just hold the key down and it continue to move till I take my finger off?
Thanks,
Chadd
Comments
You could use a pushbutton (either bought or homemade with a paperclip and a few screws on a block of wood. The "What's a Microcontroller?" tutorial shows how to use a pushbutton in a program. The BoeBot uses something similar (whiskers they call them) for detecting obstacles.
Are you using a Basic Stamp to do this?
What code are you using?
Here's a link to a tutorial about posting code in the forum.
A Basic Stamp can only do one thing at a time but I'd think if should be able to do what you want but it would be a lot easier to show how to modify your code to do so than to write a program from scratch.
My guess is you'd want to include a check for serial input between commands to pulse the servo.
I'm not sure, but I think there should be time for this within the servo's refresh period. Let's see the code you have so far.
Edit: Mike bet me to it and with a better answer. I almost suggested using a button.
Another tip, if you are using the keyboard to control something in real time you will want to go into control panel and change the repeat rate of your keyboard to it's lowest setting.
The only time the Stamp will accept an incoming character from the PC is when the SERIN is actually executing. You can use a timeout, but the Stamp will ignore any incoming characters when it's executing other statements like the PULSOUT you're using for servo control. While the Stamp is waiting for a character to be received, it won't be able to produce pulses for the servo and the servo will eventually shut off until the next pulse comes in.