I'm new and experimenting with servos using the servo.h. with version 17 of the Arduino compiler. I'm trying to learn arrays and for loops to help with reducing coded lines on repeated tasks. I maybe going about this all wrong and ther could be easier ways, just learning for now. Anyway I'm getting this error and not sure why. I've search for references but have not found anything. Is it because I'm trying to do nested for loops with string arrays? Not sure what's wrong here. I have seen many examples of numeric nested arrays that work. Help and please explain if possible. I do want to learn and understand. Not looking for a person to just fix it.
error: too many initializers for 'char []' In function 'void panelopen()':
#include <Servo.h>
char domePie[]= {"servoD1","servoD2","servoD3","servoD4"};
int pinArray[]= {9, 10, 11, 12, 13};
int pos; // variable to store the servo position
int closepos = 10; // panel closed position (in degrees from 0-180)
int openpos = 100; // Panel full open position
int servostep = 1; // Servo stepping in degrees per step
int i;
int count;
void setup()
{
for (i=0; 1 < 4; i++)
{
Servo domePie[i];
domePie[i].attach(pinArray[i]);
}
}
void panelopen()
{
for(pos =closepos; pos < openpos; pos += servostep)
{
for (count=0;count < 4;count++)
{
domePie[i].write(pos); // cycle through each servo (1-4) }
}
delay(15); // waits 15ms for the servo to move. Higher the number slower servo moves
}
void loop()
{
panelopen(); // Just calling functions for now
}
[edit]
A more or less informative explanation of why you cant do the for loop you had.
//no domePie exists
//every reference to domePie is undefined before this
for (i=0; i<4; i++)
{
Servo domePie[i]; //an array of size i gets allocated
domePie[i].attach(pinArray[i]); //you try to index at an illegal index
//an array of size 3, has no index 3, only 0,1,2
//here the domePie array gets destructed
//before either iterating the for loop again or exiting it
}//every reference to domePie is undefined after this
Thanks for taking the time to spell it our for me, and that is much appriciated. I will need to take a step back and pull this all apart and digest it line by line as I need to grasp the information so I can do this on my own. For starters it's even more simplified as now I could change even fewer lines to add more servos as needed. I was thinking along those lines for later development. Looks like I should have started that way to begin with.