Error pushbutton case switch()

Hello,

i'd like to make a project that using the push button in multi click, but the if statement in case switch() don't work!!

int a=1;
int b=2;
int c=3;
int d=4;
int e=5;
int f=6;
int g=7;
int ab=A2;
int bb=A3;
int cb=A4;
int db=A5;
const int buttonPin = A5; // the pin that the pushbutton is attached to
const int ledPin = 13; // the pin that the LED is attached to

// Variables will change:
int buttonPushCounter = 0; // counter for the number of button presses
int buttonState = 0; // current state of the button
int lastButtonState = 0;
unsigned long time;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(a, OUTPUT);
pinMode(b, OUTPUT);
pinMode(c, OUTPUT);
pinMode(d, OUTPUT);
pinMode(e, OUTPUT);
pinMode(f, OUTPUT);
pinMode(g, OUTPUT);
pinMode(ab, INPUT);
pinMode(bb, INPUT);
pinMode(cb, INPUT);
pinMode(db, INPUT);
pinMode(8, OUTPUT);
pinMode(A4, INPUT);
pinMode(A5, INPUT);

}
void satu(){
digitalWrite(a, LOW);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(f, LOW);
digitalWrite(g, LOW);
}
void dua(){
digitalWrite(a, HIGH);
digitalWrite(b, LOW);
digitalWrite(c, HIGH);
digitalWrite(d, HIGH);
digitalWrite(e, LOW);
digitalWrite(f, HIGH);
digitalWrite(g, HIGH);
}
void tiga(){
digitalWrite(a, HIGH);
digitalWrite(b, LOW);
digitalWrite(c, HIGH);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(f, HIGH);
digitalWrite(g, LOW);
}
void empat(){
digitalWrite(a, HIGH);
digitalWrite(b, HIGH);
digitalWrite(c, LOW);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(f, LOW);
digitalWrite(g, LOW);
}
void lima(){
digitalWrite(a, HIGH);
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, LOW);
digitalWrite(e, HIGH);
digitalWrite(f, HIGH);
digitalWrite(g, LOW);
}
void enam(){
digitalWrite(a, HIGH);
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, LOW);
digitalWrite(e, HIGH);
digitalWrite(f, HIGH);
digitalWrite(g, HIGH);
}
void tujuh(){
digitalWrite(a, LOW);
digitalWrite(b, LOW);
digitalWrite(c, HIGH);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(f, LOW);
digitalWrite(g, LOW);
}
void delapan(){
digitalWrite(a, HIGH);
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(f, HIGH);
digitalWrite(g, HIGH);
}
void sembilan(){
digitalWrite(a, HIGH);
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(f, HIGH);
digitalWrite(g, LOW);
}
void i(){
digitalWrite(a, HIGH);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(f, LOW);
digitalWrite(g, LOW);
}
void nol(){
digitalWrite(a, LOW);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(f, LOW);
digitalWrite(g, LOW);
}
void software_Reset()
// Restarts program from beginning but
// does not reset the peripherals and registers
{
asm volatile (" jmp 0");
}
void loop() {
// read the pushbutton input pin:
buttonState = digitalRead(buttonPin);

// compare the buttonState to its previous state
if (buttonState != lastButtonState) {
// if the state has changed, increment the counter
if (buttonState == HIGH) {
// if the current state is HIGH then the button
// wend from off to on:
buttonPushCounter++;
Serial.println("on");
Serial.print("number of button pushes: ");
Serial.println(buttonPushCounter);
if(buttonPushCounter>9){
software_Reset();
}
switch(buttonPushCounter){
case 1:
satu();
break;

while(digitalRead(A4)==HIGH){
digitalWrite(8, HIGH);
delay(1000);
}
case 2:
dua();
break;
case 3:
tiga();
break;
case 4:
empat();
break;
case 5:
lima();
break;
case 6:
enam();
break;
case 7:
tujuh();
break;
case 8:
delapan();
break;
case 9:
sembilan();
break;
}

} else {
// if the current state is LOW then the button
// wend from on to off:
Serial.println("off");
}
// Delay a little bit to avoid bouncing
delay(50);
}
// save the current state as the last state,
//for next time through the loop
lastButtonState = buttonState;

// turns on the LED every four button pushes by
// checking the modulo of the button push counter.
// the modulo function gives you the remainder of
// the division of two numbers:
if (buttonPushCounter % 4 == 0) {
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
}

}

You don't have an if in any of the case statement that I can see.

What should it do? What does it do?
Mark

im not sure what you are trying to do but the open and closed {} look odd

you are only running the switch(buttonPushCounter){

when (buttonState != lastButtonState) & when the (buttonState == HIGH)

when do you want to run the switch as digitalWrite doesn't care is its run once or thousands of times as it will stay at the last setting or just repeat what its already doing.

Are you planning to take a number of pushes then run the switch or cycle through the switch every time the button is pushed?

just noticed

int db=A5;
const int buttonPin = A5; // the pin that the pushbutton is attached to

so you are using A5 twice and buttonPin is not listed by name but pinMode(A5, INPUT); and pinMode(db, INPUT); are listed?

changed butoonPin to a INPUT_PULLUP to remove false reads and deleted references to A5 then tested and the code seems to cycle the switch(buttonPushCounter). If you have a resistor being used as a pull down then switch the INPUT_PULLUP to INPUT and change LOW to HIGH in the code. If you don't have a resistor as a pull down then I surgest you rewire and use the on board resistor and keep with INPUT_PULLUP as your problem may be a false input read

int a = 1;
int b = 2;
int c = 3;
int d = 4;
int e = 5;
int f = 6;
int g = 7;
int ab = A2;
int bb = A3;
int cb = A4;

const int  buttonPin = A5;    // the pin that the pushbutton is attached to
const int ledPin = 13;       // the pin that the LED is attached to

// Variables will change:
int buttonPushCounter = 0;   // counter for the number of button presses
int buttonState = 0;         // current state of the button
int lastButtonState = 0;
unsigned long time;
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(a, OUTPUT);
  pinMode(b, OUTPUT);
  pinMode(c, OUTPUT);
  pinMode(d, OUTPUT);
  pinMode(e, OUTPUT);
  pinMode(f, OUTPUT);
  pinMode(g, OUTPUT);
  pinMode(ab, INPUT);
  pinMode(bb, INPUT);
  pinMode(cb, INPUT);
  pinMode(buttonPin, INPUT_PULLUP);//a5 connected to ground via button
  pinMode(8, OUTPUT);
  pinMode(A4, INPUT);


}
void satu() {
  digitalWrite(a, LOW);
  digitalWrite(b, LOW);
  digitalWrite(c, LOW);
  digitalWrite(d, HIGH);
  digitalWrite(e, HIGH);
  digitalWrite(f, LOW);
  digitalWrite(g, LOW);
}
void dua() {
  digitalWrite(a, HIGH);
  digitalWrite(b, LOW);
  digitalWrite(c, HIGH);
  digitalWrite(d, HIGH);
  digitalWrite(e, LOW);
  digitalWrite(f, HIGH);
  digitalWrite(g, HIGH);
}
void tiga() {
  digitalWrite(a, HIGH);
  digitalWrite(b, LOW);
  digitalWrite(c, HIGH);
  digitalWrite(d, HIGH);
  digitalWrite(e, HIGH);
  digitalWrite(f, HIGH);
  digitalWrite(g, LOW);
}
void empat() {
  digitalWrite(a, HIGH);
  digitalWrite(b, HIGH);
  digitalWrite(c, LOW);
  digitalWrite(d, HIGH);
  digitalWrite(e, HIGH);
  digitalWrite(f, LOW);
  digitalWrite(g, LOW);
}
void lima() {
  digitalWrite(a, HIGH);
  digitalWrite(b, HIGH);
  digitalWrite(c, HIGH);
  digitalWrite(d, LOW);
  digitalWrite(e, HIGH);
  digitalWrite(f, HIGH);
  digitalWrite(g, LOW);
}
void enam() {
  digitalWrite(a, HIGH);
  digitalWrite(b, HIGH);
  digitalWrite(c, HIGH);
  digitalWrite(d, LOW);
  digitalWrite(e, HIGH);
  digitalWrite(f, HIGH);
  digitalWrite(g, HIGH);
}
void tujuh() {
  digitalWrite(a, LOW);
  digitalWrite(b, LOW);
  digitalWrite(c, HIGH);
  digitalWrite(d, HIGH);
  digitalWrite(e, HIGH);
  digitalWrite(f, LOW);
  digitalWrite(g, LOW);
}
void delapan() {
  digitalWrite(a, HIGH);
  digitalWrite(b, HIGH);
  digitalWrite(c, HIGH);
  digitalWrite(d, HIGH);
  digitalWrite(e, HIGH);
  digitalWrite(f, HIGH);
  digitalWrite(g, HIGH);
}
void sembilan() {
  digitalWrite(a, HIGH);
  digitalWrite(b, HIGH);
  digitalWrite(c, HIGH);
  digitalWrite(d, HIGH);
  digitalWrite(e, HIGH);
  digitalWrite(f, HIGH);
  digitalWrite(g, LOW);
}
void i() {
  digitalWrite(a, HIGH);
  digitalWrite(b, LOW);
  digitalWrite(c, LOW);
  digitalWrite(d, LOW);
  digitalWrite(e, LOW);
  digitalWrite(f, LOW);
  digitalWrite(g, LOW);
}
void nol() {
  digitalWrite(a, LOW);
  digitalWrite(b, LOW);
  digitalWrite(c, LOW);
  digitalWrite(d, LOW);
  digitalWrite(e, LOW);
  digitalWrite(f, LOW);
  digitalWrite(g, LOW);
}
void software_Reset()
// Restarts program from beginning but
// does not reset the peripherals and registers
{
  asm volatile ("  jmp 0");
}
void loop() {
  // read the pushbutton input pin:
  buttonState = digitalRead(buttonPin);
  //Serial.println( buttonState);

  // compare the buttonState to its previous state
  if (buttonState != lastButtonState) {
    // if the state has changed, increment the counter
    if (buttonState == LOW) {//when pressed it will be low
      // if the current state is HIGH then the button
      // wend from off to on:
      buttonPushCounter++;
      Serial.println("on");
      Serial.print("number of button pushes:  ");
      Serial.println(buttonPushCounter);
      if (buttonPushCounter > 9) {
        software_Reset();
      }
      switch (buttonPushCounter) {
        case 1:
          satu();
          Serial.println("switch one running");
          break;

          while (digitalRead(A4) == HIGH) {
            digitalWrite(8, HIGH);
            delay(1000);
          }
        case 2:
          dua();
            Serial.println("switch two running");
          break;
        case 3:
          tiga();
            Serial.println("switch three running");
          break;
        case 4:
          empat();
           Serial.println("switch four running");
          break;
        case 5:
          lima();
          break;
        case 6:
          enam();
          break;
        case 7:
          tujuh();
          break;
        case 8:
          delapan();
          break;
        case 9:
          sembilan();
          break;
      }


    } else {
      // if the current state is HIGH then the button
      // wend from on to off:
      Serial.println("off");
    }
    // Delay a little bit to avoid bouncing
    delay(50);
  }
  // save the current state as the last state,
  //for next time through the loop
  lastButtonState = buttonState;


  // turns on the LED every four button pushes by
  // checking the modulo of the button push counter.
  // the modulo function gives you the remainder of
  // the division of two numbers:
  if (buttonPushCounter % 4 == 0) {
    digitalWrite(ledPin, HIGH);
  } else {
    digitalWrite(ledPin, LOW);
  }
}

If the push button is >9, then you do a hard assembly-level reset. I have no idea what this will do - won't it restart the bootloader or something? Seems like a horrible idea to me, sledgehammer to crack a walnut. Why not just reset your variables and continue on?

In any event, I don't see any 'if statement in the case switch'. I see a while() loop, but you unconditionally break out of the switch before this, so that loop will never get executed.