So say i have 100 or more comparisons to do.....and each of the 100 values, needs to move the stepper/servos to some location, i would have to write 100 'if' statements?
that might be possible, but there are two generic solution:
- arrays => use the index of the found value to set the value of a servo
- formulas => you might be able to catch the logic in a (simple?) formula so you can calculate the position
array's example
#define MAXSERVOS 2
float arrayValues[] = { 2.25, 3.3, 4.75, 5.22, 6.12 }; // I added 1.0 to all the values of the original array
byte servoAngle[MAXSERVOS ][5] = { // 5 angles per servo
{ 0, 45, 90, 135, 180 },
{ 0,10,20,30,40 } };
...
// find the value in the array
for( x=0; x<4 && measuredValue <=arrayValues[x]; x++);
// use the index to set the servo's
for (int s=0; s< MAXSERVOS; s++)
{
servo[s].set(servoAngle[s][x]); // note the servos are in an array too!
}
...
that is in essence all (but you still have to type the whole array
formula example
measurement = analogRead(0);
// set the servo's
for (int s=0; s< MAXSERVOS; s++)
{
servo[s].set(func(s, measurement));
}
// the func(int s, float measurement) has to be elaborated, this is just an example.
float func(int s, float measurement)
{
float x = (measurement-512)/512.0; // map unto -1 .. 1
float angle = (asin(x) + s * 30) % 180;
return angle;
}
Mostly the array option is the easiest...