Controlling a servo
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.
#include <Servo.h> Servo servo_base; Servo servo_r_tread; Servo servo_l_tread; Servo servo_shoulder; Servo servo_elbow; Servo servo_claw; byte commandByte; int servoangle_base = servo_base.read(); int servoangle_r_tread = servo_r_tread.read(); int servoangle_l_tread = servo_l_tread.read(); int servoangle_shoulder = servo_shoulder.read(); int servoangle_elbow = servo_elbow.read(); int servoangle_claw = servo_claw.read(); void setup() { Serial.begin(9600); servo_base.attach(8); servo_base.write(servoangle_base); servo_r_tread.attach(9); servo_r_tread.write(servoangle_r_tread); servo_l_tread.attach(10); servo_l_tread.write(servoangle_l_tread); servo_shoulder.attach(11); servo_shoulder.write(servoangle_shoulder); servo_elbow.attach(12); servo_elbow.write(servoangle_elbow); servo_claw.attach(13); servo_claw.write(servoangle_claw); } void loop() { if(Serial.available() > 0) { commandByte = Serial.read(); if(commandByte == 'Q') { servoangle_l_tread = servoangle_l_tread+10; servo_l_tread.write(servoangle_l_tread); } if(commandByte == 'A') { servoangle_l_tread = servoangle_l_tread-10; servo_l_tread.write(servoangle_l_tread); } if(commandByte == 'W') { servoangle_r_tread = servoangle_r_tread + 10; servo_r_tread.write(servoangle_r_tread); } if(commandByte == 'S') { servoangle_r_tread = servoangle_r_tread - 10; servo_r_tread.write(servoangle_r_tread); } if(commandByte == '>') { servoangle_base++; servo_base.write(servoangle_base); } if(commandByte == '<') { servoangle_base--; servo_base.write(servoangle_base); } if(commandByte == 'T') { servoangle_shoulder++; servo_shoulder.write(servoangle_shoulder); } if(commandByte == 'Y') { servoangle_shoulder--; servo_shoulder.write(servoangle_shoulder); } if(commandByte == 'U') { servoangle_elbow++; servo_elbow.write(servoangle_elbow); } if(commandByte == 'I') { servoangle_elbow--; servo_elbow.write(servoangle_elbow); } if(commandByte == 'O') { servoangle_claw++; servo_claw.write(servoangle_claw); } if(commandByte == 'P') { servoangle_claw--; servo_claw.write(servoangle_claw); } } }// ---------- Initialization code (for Arduino, this goes in setup) state = 0; // Initially in state 0. state is a byte variable // ---------- Repeated execution (for Arduino, this goes in loop) if (commandByte == '.') { if (state == 0) { // In state 0 // Start the servo moving state = 1; // Go to next state } else { // In state 1 // Stop the servo moving state = 0; // Go to initial state }