Hey all
I have got an Arduino mega 2560, and I have connected 4 servo's to the PWM pins( 4-7) . I am using the servo libary to move my servos, however if i am reducing the delay less then 500 ms than it doesn't work. Is there a way to reduce the delay? ( I need a response in the surrounding of 200ms).
Thanks Naty
Attaching the code :
#include <Servo.h>
Servo RetServoL;
Servo AngServoL;
Servo RetServoR;
Servo AngServoR;
void setup() {
pinMode(13,OUTPUT);
#define POT_PIN_L 0
#define POT_PIN_R 1
pinMode(1,OUTPUT);
AngServoL.attach(4);
RetServoL.attach(6); //analog pin 1
AngServoR.attach(5);
RetServoR.attach(7); //analog pin 1
Serial.begin(19200);
Serial.println("Ready");
}
int potValR ;
int potValL;
int RetServoLneu=90;
int Retrection=60;
int potNeuVal=508;
int potThresh=10;
int retState=0;
void loop()
{
AngServoL.write(100);
AngServoR.write(90);
potValL = analogRead(POT_PIN_L);
potValR = analogRead(POT_PIN_R);
/*if (abs(potValL - potNeuVal) < potThresh) {
RetServoL.write(RetServoLneu-Retrection);
digitalWrite(13,HIGH);
delay(10000);
potValL = analogRead(POT_PIN_L);
} if (abs(potValL - potNeuVal) < potThresh) {
RetServoL.write(RetServoLneu+Retrection);
// digitalWrite(13,LOW);
delay(10000);
}
*/
if (abs(potValL - potNeuVal) < potThresh){
retState = 1 - retState;
digitalWrite(13,HIGH);
if (retState == 1){
RetServoL.write(RetServoLneu-Retrection);
delay(500);
}
else{
RetServoL.write(RetServoLneu+Retrection);
delay(500);
}
}
if (abs(potValR - potNeuVal) < potThresh){
retState = 1 - retState;
digitalWrite(13,HIGH);
if (retState == 1){
RetServoR.write(RetServoLneu-Retrection);
delay(500);
}
else{
RetServoR.write(RetServoLneu+Retrection);
delay(500);
}
}
// Servo::refresh();
pinMode(POT_PIN_R, INPUT);
pinMode(POT_PIN_L, INPUT);
potValR = analogRead(POT_PIN_R);
Serial.print("\n PotR = " );
Serial.print(potValR);
Serial.print("\t PotL = " );
Serial.print(potValL);
}