Hi all,
HazardsMind:
Are you using the servo library?
#include<Servo.h>
Yeah, that what the script I based if on said to do.
zoomkat:
Rule #1 is to post the code that is not worling for you if you want more than just guesses as to the problem.
Sorry, slipped my mind! Here's the code:
#inlcude <Servo.h>
Servo servoTest1;
int servoPin = 9;
int distPin = 0;
int distPin2 = 1;
void setup()
{
servoTest1.attach(servoPin);
}
void loop()
{
int dist = analogRead(distPin);
int dist2 = analogRead(distPin2);
//int pos = map(dist, 0, 1023, 0, 180);
// servoTest1.write(pos);
int pos
if (dist - dist2 = 0) //are both distances equal
{dist = dist2} //if so, they are both eqaul
else // otherwise
{int pos2 = dist - dist2; // calculate their distance
int pos = pos2 * -1;} // invert it, and make it the servo's new possition
int servoPossition = map(pos, 0, 1023, 0, 180);
}
Basically I'm trying to create a script that measures 2 distances, calculates if they're equal, then adjusts the servo position until the sensors on it are equal distances from the object thereby following the object as it moves.
Thanks again!
Jack