For some reason (It's attaching for the first time?) it ignores the delay in Q the first time, but not any time after....
Thoughts?
case 'q':case'Q': servo1.attach(9); servo2.attach(10);servo1.write(20);delay(350);servo2.write(180);Serial.println("Claws enabled");break;
// For some reason it fires BOTH instantly, even with more delays
case 'e':case'E': servo2.write(0);delay(500);servo1.write(180);Serial.println("Close");break;
When you initially attach the servo it will move to whatever position it's currently set to if it isn't already there, usually 90 degrees, but note that you can set the desired position before the attach. Your delay is likely being executed correctly, but you may be mistaking this possible initial move on attach for 'It's ignoring my delay'. Hard to be sure just seeing that fragment of code.
mine would not drift, but shouldn't move when powered up without that delay, because they collide (Layer over each other when closed)
(And if I make them attach on their own line, they jump to 90 degrees for no reason (Never featured in code)
case 'q':case'Q': servo1.attach(9); servo2.attach(10);Serial.println("Claws enabled");break; //Jump to 90 and whack into each other,
case 'r':case'R': servo1.write(20);delay(350);servo2.write(180);break;
case 'e':case'E': servo2.write(0);delay(500);servo1.write(180);break;
And if I make them attach on their own line, they jump to 90 degrees for no reason
There is a reason. You just don't understand it.
You can, and should, call servo.write() before servo.attach(). Then, when you do call servo.attach(), they will go to the position they were told to go to, instead of wherever they feel like.
It's really not that random. Look at the servo.write() code, and see what it does.
Now this DOES work, but I'd still rather be attaching them separately instead of being forced to move them when I attach,
I insist there's something wrong there... nothing should be making it jump to a position that was never declared,
uint8_t Servo::attach(int pin)
{
return this->attach(pin, MIN_PULSE_WIDTH, MAX_PULSE_WIDTH);
}
uint8_t Servo::attach(int pin, int min, int max)
{
if(this->servoIndex < MAX_SERVOS ) {
pinMode( pin, OUTPUT) ; // set servo pin to output
servos[this->servoIndex].Pin.nbr = pin;
// todo min/max check: abs(min - MIN_PULSE_WIDTH) /4 < 128
this->min = (MIN_PULSE_WIDTH - min)/4; //resolution of min/max is 4 uS
this->max = (MAX_PULSE_WIDTH - max)/4;
// initialize the timer if it has not already been initialized
timer16_Sequence_t timer = SERVO_INDEX_TO_TIMER(servoIndex);
if(isTimerActive(timer) == false)
initISR(timer);
servos[this->servoIndex].Pin.isActive = true; // this must be set after the check for isTimerActive
}
return this->servoIndex ;
}