Getting out of a Loop on a button press


hello, searched on cant find can tailor project.

basically, have single button controls 8 leds.

i want controls be> start leds off->push button leds flash-> push button leds steady on> push button off.

i cant seem figure out how program button break flashing function , move on steadyon function. have tested functions independently , there code fine.

code: [select]
void loop()
{
  buttonstate = digitalread(switchpin);
  // compare buttonstate previous state
  if (buttonstate != lastbuttonstate) {
    // if state has changed, increment counter
    if (buttonstate == low) {
      buttonpushcounter++;
      serial.print("number of button pushes:  ");
      serial.println(buttonpushcounter);

      delay(20);     // delay button debouncing (works enough)
            if (buttonpushcounter == 0){
                  serial.println("light setting 1 (off)");
                  serial.println(buttonpushcounter);
                  switchoff();
              }
            if (buttonpushcounter == 1){             
                  serial.println("light setting 2");
                  serial.println(buttonpushcounter);
                  wigwag(); //getting stuck in loop
            }
            if (buttonpushcounter == 2){
                  serial.println("light setting 3");
                  serial.println(buttonpushcounter);
                  steadyon();
            }   
    }         
   
  }
  if (buttonpushcounter >=3) {
      buttonpushcounter = 0;
     serial.println(buttonpushcounter);

   lastbuttonstate = buttonstate;
}

show of code.  wigwag code checking button between blinks or using delay()?


Arduino Forum > Using Arduino > Project Guidance > Getting out of a Loop on a button press


arduino

Comments

Popular posts from this blog

Connecting Raspberry Pi 2 to P10(1R)-V706 LED Dot Matrix - Raspberry Pi Forums

TypeError: <unknown> is not a numpy array - Raspberry Pi Forums

datso and removing imagetitle - Joomla! Forum - community, help and support