// this is a function I modified from this site to do away with for multiple loops
// I hope this helps someone
// need forward declarations here
void FromTo(void (*), int From, int To, int Step);
void setup() {
Serial.begin(9600);
// put your setup code here, to run once:
}
void loop() {
// no need to use multiple for loops
FromTo(PrintOut, 0, 10,1);//example forward loop
FromTo(PrintOut, 10, 0,2);//example Backward loop with step of 2
}
void FromTo(void (*function)(int Value), int From, int To, int Step) {
if (From < To) {
Serial.println("UP");
for ( int i = From; i < To; i+=Step) {
(*function)(i);
}
} else {
Serial.println("DOWN");
for ( int i = From; i > To; i-=Step) {
(*function)(i);
}
}
delay(5000);
}
void PrintOut(int Value) {
Serial.println(Value); //watch on your serial monitor
}