I have the following switch case code which sends data received on serial to a unique servo:
switch (servo) {
case 1:
servo8.write(pos); // move servo1 to 'pos'
break;
case 2:
servo9.write(pos);
break;
case 3:
servo10.write(pos);
break;
case 4:
servo11.write(pos);
break;
case 5:
servo12.write(pos);
break;
}
delay(10);
In most cases servos should have 15 ms to reach their destination before receiving new data for the new destination. If I introduce a "delay(15)" before each break will that apply only to the servo that receives the data, or does it also delay the other cases from receiving information? I would like to have the servos get a chance to go to their destination.
If you add any delay statements, the whole program will delay while any servo moves. You could set a flag for each servo that indicates whether it is ready to move again, and only command it, if it is ready to move.
That would involve a queue class, though, to be able to queue up commands for each servo.
How far does any servo move in each operation? It may not really be necessary to have any delays beyond that of the serial processing, if the moves always small.
The servo library works interrupt driven. When you set a new value for a servo, the value will be sent out to the servo with the next refresh cycle (usually about 20 ms) and the servo is moved to the final destination at full speed. For this reason, doing
will in most cases make no difference to just having the last servo.write, because the function only updates a variable and the actual output is done in the next update cycle by the interrupt handler.