Hi, I have problem with setting speed in my 12 servos. I don't want to use delay() function, but timers.
My programs on Arduino using messenger library to read 12 values of angles, and currently, I'm controlling speed of move servos by sending this values at some frequency. It's not reliable, because I have to use pause() function in program on PC who is sending messages, so sometimes something goes wrong.
I want to send example angles 130 20 30 40 50 33 etc. and Arduino set them with some speed (defined by frequency set in timer.attach() ). With one servo function using timers looks like this:
#include <Timers.h>
Timers timer;
void servoMove()
{
static byte angle = 0;
servo.write(angle);
angle++;
}
void setup()
{
servo.attach(SERVO_PIN);
// connect function running every 0,02s
timer.attach(0, 20, servoMove);
}
void loop()
{
// timer update
timer.process();
}
But how to create the same with 12 servos

? Servos must be set in similar time (they move part of legs in my robot)
My current function looks like this:
void setServo()
{
int angle [12];
for (int i=0;i<12;i=i++)
{
angle[i] = message.readInt(); // function from Messenger library
if ((angle[i]>180) || (angle[i] < 0))
{
SendERROR();
return;
}
else if (angle[i] == servos[i].read())
{
Serial.print("won't write angle number( ");
Serial.print(i+1);
Serial.println(") = ");
}
else
{
servos[i].write(angle[i]);
Serial.print("written angle number (");
Serial.print(i+1);
Serial.print(") = ");
Serial.println(angle[i], DEC);
}
}
}