Hello everyone! I wrote this code and inside the for I get this error:
'servo' was not declared in this scope
#include <Servo.h>
int n_servo = 3;
Servo servo[n_servo];
void setup()
{
for(int i = 0; i < n_servo; i += 1){
servo[i].attach(11 + i);
}
}
If I declare Servo inside the setup it works, but I would like to keep the global variable and use it in some functions.
Thank you so much! it works!
New problem:
#include <Servo.h>
const int n_servo = 3;
Servo servo[n_servo];
void moveTO(int n_sync, int idx[], int degree[]){
//code.........
}
void setup()
{
for(int i = 0; i < n_servo; i += 1){
servo[i].attach(11 + i);
}
moveTo(3, {0, 1, 2}, {0, 0, 180});
}
in this line: moveTo(3, {0, 1, 2}, {0, 0, 180});
this error: 'moveTo' was not declared in this scope
lesept
5
Check 'moveTO' vs 'moveTo' (capital O)
sometimes i sleep when i coding, thanks, work!
(11 + i);
Much better to use an array of pin numbers. Then you aren't restricted to using physically adjacent pins.