Hello, I’m new in this comunity! I feel a little bit embarassed to post a so simple question but after a few hours of triyng, I haven’t yet found an answer.
I’m working on a project that uses a number of servos. I’m trying to initialize them by using this code:
#include <Servo.h>
const int numOfServos = 1;
const int servosPins = {9};
const int servosPosition = {0};
Servo servosArray[numOfServos];
(in this case i’m using just one servo, but the idea is to extend that number as far as it works)
Up to that I have no problem, but the error occurs in the Setup function:
void setup() {
for(int k = 0; k < numOfServos; k++) {
servosArray[k].attach(servosPins[k]);
servosArray[k].write(servosPosition[k]);
}
}
Especially with the argument of the attach and write methods.
I get the error: “invalid types ‘const int[int]’ for array subscript”