code arduino
code arduino
void setup()
{ Serial.begin(9600);
// servo connections
// name.attacht(pin);
horizontal.attach(9);
vertical.attach(10);
horizontal.write(90);
vertical.write(45);
delay(3000);
void loop()
{ int lt = analogRead(ldrlt); // top left // đọc giá trị cảm biến
int dhoriz = avl - avr;// check the diffirence og left and rigt
Serial.print(avt);
Serial.print(" ");
Serial.print(avd);
Serial.print(" ");
Serial.print(avl);
Serial.print(" ");
Serial.print(avr);
Serial.print(" ");
Serial.print(dtime);
Serial.print(" ");
Serial.print(tol);
Serial.println(" ");
if (-1*tol > dvert || dvert > tol) // check if the diffirence is in the tolerance
else change vertical angle
servov = ++servov;
delay(100);
servov = servovLimitHigh;
}
servov= --servov;
delay(100);
servov = servovLimitLow;
vertical.write(servov);
if (-1*tol > dhoriz || dhoriz > tol) // check if the diffirence is in the tolerance
else change horizontal angle
servoh = --servoh;
delay(100);
servoh = servohLimitLow;
servoh = ++servoh;
delay(100);
servoh = servohLimitHigh;
}
// nothing
horizontal.write(servoh);
delay(dtime);