Alright, I've got this program down pat for my servo controller:
Code:
// Controlling a servo position using a temperature sensor
// by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>
// edited 5-12-2010 by Will Lyon to include base setting for servo if voltage not detected on pin 7
#include <Servo.h>
#define CONTROL 7
Servo myservo; // create servo object to control a servo
int temps = 0; // analog pin used to connect the temp sensor
int val; // variable to read the value from the analog pin
void setup()
{
pinMode (CONTROL, INPUT); // sets the control pin to input
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop()
{
val = digitalRead(CONTROL); //read input of pin 7 and store it
if (val == HIGH){ // reads whether or not 5v is present on pin 7, if 5v present, continue:
val = analogRead(temps); // reads the value of the temp sensor (value between 0 and 1023)
val = map(val, 350, 700, 75, 105); // scale it to use it with the servo (value between 0 and 180)
myservo.write(val); // sets the servo position according to the scaled value
delay(25); // waits for the servo to get there
} else {
if (val == LOW); // if no voltage present on pin 7, continue
myservo.write(50); //sets servo position to 50 if no voltage is detected on pin 7
}
}
when I take power away from pin 7 the servo is to go to a preset position. It does this, but it jitters before it goes. once its there its ok. anyone have any ideas?