Maybe it is best to breakdown the syntax of a "for" loop.
for (int i = 0; i < loopTimes; ++i)
could also be written as:
int i = 0;
while (i < loopTimes) {
//the body of you loop goes here
i = i + 1;
}
So, we have four distinct parts;
1)the initialisation, (int i = 0;)
2)the condition for keeping looping, ( i < loopTimes)
3)the body of the loop,
4)and the action to perform at the end of each loop before going back to 2). (i = i + 1)
way hey it works! Thanks for that! Just for my reference, and as i am playing with arduino's capabilities, i still confused as to why this is in the set up.
What if i was using that to respond to an analog input from a potentiometer? How would you 'call' it up or activate your loop in void loop?
I used to do PBasic years ago and have therfore got an urge for a " goto loop " sorry, I'm just trying to get my head around this!
What if i was using that to respond to an analog input from a potentiometer?
If you mean "how do I set the number of loops, based on the value read from a potentiometer?", very simply:
int loopTimes = map (analogRead (POTPIN), 0, 1023, 0, 20);
This reads an analogue input (which returns a value in the range 0...1023) and maps that range onto 0..20.
Then use "loopTimes" as the loop control as you already are doing.