how to add delay in switch case

good day all. first of all, im a web developer without experience in C, my language is php, thats why i need your help.(i am an absolute beginner)

what im trying to implement is to add a 7 segment counter on each case. i know delay cant use in switch case, here is my code attached…

switch (state) {
case 1:
digitalWrite(ledB36, HIGH); ////
digitalWrite(ledB38, HIGH); // //
digitalWrite(ledB40, HIGH); /////
digitalWrite(ledB42, LOW); //
digitalWrite(ledB44, LOW); ////
digitalWrite(ledB46, HIGH);
digitalWrite(ledB48, HIGH);
old = state;
break;
case 2:
digitalWrite(ledB36, HIGH); ////
digitalWrite(ledB38, HIGH); // //
digitalWrite(ledB40, HIGH); ////
digitalWrite(ledB42, HIGH); // //
digitalWrite(ledB44, HIGH); ////
digitalWrite(ledB46, HIGH);
digitalWrite(ledB48, HIGH);
old = state;
break;
case 3:
digitalWrite(ledB36, HIGH); //////
digitalWrite(ledB38, HIGH); //
digitalWrite(ledB40, HIGH); //
digitalWrite(ledB42, LOW); //
digitalWrite(ledB44, LOW); //
digitalWrite(ledB46, LOW);
digitalWrite(ledB48, LOW);
old = state;
break;
default:
{
digitalWrite(ledB36, HIGH); //// this 7 line will output a number 6
digitalWrite(ledB38, LOW); //
digitalWrite(ledB40, HIGH); ////
digitalWrite(ledB42, HIGH); // //
digitalWrite(ledB44, HIGH); ////
digitalWrite(ledB46, HIGH);
digitalWrite(ledB48, HIGH);
delay(500); // i know this delay wwill not work, just for reference

digitalWrite(ledB36, HIGH); ////////
digitalWrite(ledB38, HIGH); //
digitalWrite(ledB40, HIGH); //
digitalWrite(ledB42, LOW); //
digitalWrite(ledB44, LOW); //
digitalWrite(ledB46, LOW);
digitalWrite(ledB48, LOW);
delay(500); //i know this delay will not work, just for reference
// an so on…
}
old = 0;
break;

mycode.ino (2.61 KB)

spend my whole night googling and experimenting, unfortunately, i still cant implement what i want due to lack of experience and knowledge.

You can add delay() wherever you want as long as it is inside another function.

But delay() will stop executing other part of your code for the duration. To allow your code to be responsible, learn to use millis() for timing. Check out the example “BlinkWithoutDelay” for reference.

Show us something that will compile. It should have setup() and loop() as a minimum.

Then tell us what it does and what you want it to do different.

Use code tags to post code. The regulars will not read your code any other way.

arduino_new:
You can add delay() wherever you want as long as it is inside another function.

But delay() will stop executing other part of your code for the duration. To allow your code to be responsible, learn to use millis() for timing. Check out the example "BlinkWithoutDelay" for reference.

`

yes i noticed that delay stops me from getting to another case. so the closest option is to learn to use millis();
i thought there is easiest way to implement this, thank you

Yes, but what is the "this" which you wish to implement? You said you want numbers and delays but not much else.

MorganS:
Show us something that will compile. It should have setup() and loop() as a minimum.

Then tell us what it does and what you want it to do different.

Use code tags to post code. The regulars will not read your code any other way.

that code compiles successfully. but not working, it stays on default case, not switching to another case.

The problem is in the code you didn’t post.

sorry, this is the full code

#define ledB36 36
#define ledB38 38
#define ledB40 40
#define ledB42 42 
#define ledB44 44 
#define ledB46 46
#define ledB48 48

#define button 3

//---------------------------------
int state = 0;
int old = 0;
int buttonPoll = 0;
//----------------------------------


void setup() {
  pinMode(ledB36, OUTPUT);
  pinMode(ledB38, OUTPUT);
  pinMode(ledB40, OUTPUT);
  pinMode(ledB42, OUTPUT);
  pinMode(ledB44, OUTPUT);
  pinMode(ledB46, OUTPUT);
  pinMode(ledB48, OUTPUT);
  pinMode(button, INPUT);

}

void loop() {
buttonPoll = digitalRead(button);
if(buttonPoll == 1) {
  delay(50);
  buttonPoll = digitalRead(button);
  if(buttonPoll == 0){
    state = old + 1;
  }}
    else{
  delay(100);
    }
  switch (state)
 {
    
    case 1:
  digitalWrite(ledB36, HIGH);                  ////
  digitalWrite(ledB38, HIGH);                //   //
  digitalWrite(ledB40, HIGH);                //////
  digitalWrite(ledB42, LOW);                    //
  digitalWrite(ledB44, LOW);                 ////
  digitalWrite(ledB46, HIGH);
  digitalWrite(ledB48, HIGH);
  old = state;
  break;
  case 2:
   digitalWrite(ledB36, HIGH);                  ////
  digitalWrite(ledB38, HIGH);                 //   //
  digitalWrite(ledB40, HIGH);                  ////
  digitalWrite(ledB42, HIGH);                //   //
  digitalWrite(ledB44, HIGH);                 ////
  digitalWrite(ledB46, HIGH);
  digitalWrite(ledB48, HIGH);
  old = state;
  break;
  case 3:
  digitalWrite(ledB36, HIGH);          //////
  digitalWrite(ledB38, HIGH);            //
  digitalWrite(ledB40, HIGH);           //
  digitalWrite(ledB42, LOW);           //
  digitalWrite(ledB44, LOW);          //
  digitalWrite(ledB46, LOW);
  digitalWrite(ledB48, LOW);
  old = state;
  break;
  default:
  digitalWrite(ledB36, LOW);               //  //
  digitalWrite(ledB38, HIGH);             //  //
  digitalWrite(ledB40, HIGH);            //////
  digitalWrite(ledB42, LOW);                //
  digitalWrite(ledB44, LOW);               //
  digitalWrite(ledB46, HIGH);
  digitalWrite(ledB48, HIGH);
  delay(500);
  digitalWrite(ledB36, HIGH);               //////
  digitalWrite(ledB38, HIGH);                  //
  digitalWrite(ledB40, HIGH);               ////
  digitalWrite(ledB42, HIGH);                //
  digitalWrite(ledB44, LOW);             /////
  digitalWrite(ledB46, LOW);
  digitalWrite(ledB48, HIGH);
  delay(500);
   digitalWrite(ledB36, HIGH);               //////
  digitalWrite(ledB38, HIGH);                  //
  digitalWrite(ledB40, LOW);              //////
  digitalWrite(ledB42, HIGH);            //
  digitalWrite(ledB44, HIGH);           /////
  digitalWrite(ledB46, LOW);
  digitalWrite(ledB48, HIGH);
  delay(500);
   digitalWrite(ledB36, LOW);              //
  digitalWrite(ledB38, HIGH);             //
  digitalWrite(ledB40, HIGH);            //
  digitalWrite(ledB42, LOW);            //
  digitalWrite(ledB44, LOW);           //
  digitalWrite(ledB46, LOW);
  digitalWrite(ledB48, LOW);
  old = 0;
  break;
  old = 0;
  break;
  }
  }  // end of this working code

updated; i add code tags. sorry guys

Bingo! No code tags.

Read "how to use this forum" and edit your post.