The arrays are constants.
So yes the size will always be the same.
Since you are all here I may as well increase the scope of my problem. I am trying to create a system which allows me to ‘play’ certain sequences of numbers which are fed to a servo. I have recorded my numbers which are stored(currently) in 2 arrays, x and y.
I created a function which enables me to loop over and ‘play’ these individual ‘motions’ but now I want to create a function which takes an array of numbers which represent individual motions and the timing value between them.
The problem I am having is thinking of how I can reference these ‘complex’ motions without doing a whole bunch of if statements. Would creating a motion object be the right approach?
I will include some of my current code to try and illustrate how I am thinking so far. The first function works, the second one is just a sketch. In the xMotions[] and yMotions[] array i want to store a reference to the xPos01[] yPos01[] etc. arrays. This is where i am struggling. If anyone understand what i am getting at and has a suggestion that would be fantastic. Thanks. Danny.
const byte xPos01[] = {105, 104, 101, 96, 92, 86, 81, 76, 69, 67, 63, 62, 60, 60, 59, 59, 59, 59, 59, 59, 59, 60, 61, 64, 70, 79, 85, 96, 101, 103, 104, 104, 105, 106, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107};
const byte yPos01[] = {62, 63, 64, 68, 70, 72, 75, 75, 75, 74, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 74, 74, 76, 76, 75, 73, 70, 68, 67, 66, 64, 62, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61};
const byte Motion02Size = sizeof(xPos02);
void playMotion(const byte xPos[], const byte yPos[], const byte s) {//function takes the array of positions
for (int i = 0; i < s; i++) { //loop over both the x and y arrays, writing the values to the servo
int yM = map(yPos[i], 0, 180, 180, 0); //invert the y value
xServo.write(xPos[i]);
yServo.write(yM);
delay(20);
}
}
byte xMotions[];//array containing the references to the motions
byte yMotions[];
byte motionSizes[];
int timings[];
void playSequence(byte xMotions[],byte yMotions[],byte motionSizes[],int timings[]), {//loop over the array of motions and play them with the delay inbetween
for (int i = 0; i < s; i++){
playMotion(xMotions[i], yMotions[i], motionSizes[i]);//find the motion to play in the array
delay(timing[i]);//fetch the timing value from the array
}
}