I am able to make it pan and tilt, the "panning" is ok but the problem is in the "tilting"...here the code that i used....is there anything wrong ?? or do i have some setting problem ??
Another question is, why is it that the servo is moving relatively slow compare to what i see in youtube when tracking the object?? is it the type of servo ??
#include <Servo.h>
Servo panservo;
Servo tiltservo;
char incomingData[4] = {0, 0, 0, 0};
int distancePan = 0;
int distanceTilt = 0;
int currentAnglePan = 90;
int currentAngleTilt = 20;
int i = 0;
void setup()
{
Serial.begin(9600);
Serial.println("Serialport ready");
panservo.attach(9); // attaches the servo on pin 9 to the servo object
tiltservo.attach (10);
tiltservo.write(currentAngleTilt);
panservo.write(currentAnglePan);
}
void loop(){
if (Serial.available()){
while (i < 30){
incomingData[i] = Serial.read();
i++;
}
distancePan = atoi(incomingData);
if (distancePan < -15){
currentAnglePan++;
currentAnglePan = constrain(currentAnglePan, 0, 180);
panservo.write(currentAnglePan);
}
else if (distancePan > 15){
currentAnglePan--;
currentAnglePan = constrain(currentAnglePan, 0, 180);
panservo.write (currentAnglePan);
}
Serial.println(currentAnglePan);
}
i = 0;
delay(50);
if (Serial.available()){
while (i < 30){
incomingData[i] = Serial.read();
i++;
}
distanceTilt = atoi(incomingData);
if (distanceTilt < -15){
currentAngleTilt++;
currentAngleTilt = constrain(currentAngleTilt, 0, 180);
tiltservo.write(currentAngleTilt);
}
else if (distanceTilt > 15){
currentAngleTilt--;
currentAngleTilt = constrain(currentAngleTilt, 0, 180);
tiltservo.write (currentAngleTilt);
}
Serial.println(currentAngleTilt);
}
i = 0;
delay(50);
}
thank in advance ~~