Switching Between Multiple Functions with For Loops Embedded


hi, i'm using arduino uno , have been trying figure out problem quite time now. have several functions use loops inside of them. have interrupt button increments every time pressed. thought process though function running, button should increment, , go onto next function. not case though. have been using serial monitor try debugging can't seem figure out.

i new programming, , appreciate on this. thought process @ least correct here?

any appreciated, i've looked online , every situation doesn't use loops, simpler situation. know code doesn't anything, trying concept down. trying loop through array of colors led strip. each function different 'chases' or effects.

thank in advance!

code: [select]
int buttonint = 0;

volatile int buttonpresses = 0;


void setup(){
 serial.begin(9600);
 attachinterrupt(buttonint, swap, rising);
 serial.println("program begins");
}

void swap(){
  serial.println("button pressed");
  buttonpresses = buttonpresses + 1;
serial.println(buttonpresses);
switch(buttonpresses){
case 1:
 serial.println("case 1");
 loop1();
 break;
case 2:
 serial.println("case 2");
 loop2();
 break;
 case 3:
 serial.println("case 3");
 loop3();
 buttonpresses = 0;
 break;
}
}



void loop(){

  }
 
void loop1(){
 serial.print("loop 1 begins");
 for(int = 0; < 200; i++){
   serial.print("i = ");
   serial.println(i);
   delay(100);
 }
}
 
void loop2(){
 serial.print("loop 1 begins");
 for(int j = 0; j < 200; j++){
   serial.print("j = ");
   serial.println(j);
   delay(100);
 }
}
 
void loop3(){
 serial.print("loop 1 begins");
 for(int k = 0; k < 200; k++){
   serial.print("k = ");
   serial.println(k);
   delay(100);
 }
}
 

you don't need interrupts this.

in each of sub loops, check if button pressed. return function if criteria met. main loop @ button count , decide function call next.


Arduino Forum > Using Arduino > Project Guidance > Switching Between Multiple Functions with For Loops Embedded


arduino

Comments

Popular posts from this blog

invalid use of void expresion in FlexiTimer2 library

error: a function-definition is not allowed here before '{' token

LED Strip Code