Can anyone help with this..

Hi, I’m new in Arduino Programming can’t any help with my problem.
I’m creating a code that consist of 3 buttons and 4 7-Segment Display (common Anode)
1st button = start
2nd button = Up/Down with 2 LED (Up = Green LED , Down = Red LED)
3rd button = Set

I don’t know where should I put the code of the 3 buttons. please help.

here’s my code

byte disp[] = {B11000000, B11111001, B10100100, B10110000, B10011001, B10010010, B10000011, B11111000, B10000000, B10011000};
int a = 11;
int b = 10;
int c = 9;
int d = 8;
const int start = A3;
const int UpDown = A4;
const int set = A5;
const int ledred = A2;
const int ledgreen = A1;

void setup(){
 DDRD = B11111111;
 pinMode(a, OUTPUT);
 pinMode(b, OUTPUT);
 pinMode(c, OUTPUT);
 pinMode(d, OUTPUT);
 pinMode(start, INPUT);
 pinMode(UpDown, INPUT);
 pinMode(set, INPUT);
 pinMode(ledred, OUTPUT);
 pinMode(ledgreen, OUTPUT););
}

void loop(){
 for (int thousandsDigit = 0; thousandsDigit < 10; thousandsDigit++){
   for (int hundredsDigit = 0; hundredsDigit < 10; hundredsDigit++){
     for (int tensDigit = 0; tensDigit < 6; tensDigit++){
       for (int onesDigit = 0; onesDigit < 10; onesDigit++){
         for (int multi = 0; multi < 100; multi++){
           displayNum(onesDigit);
           displayDigit(1);
           displayNum(tensDigit);
           displayDigit(2);
           displayNum(hundredsDigit);
           displayDigit(3);
           displayNum(thousandsDigit);
           displayDigit(4);
         }
       }
     }
   }
 }
}

void displayNum(int num){
 switch(num){
   case 0:
   PORTD = disp[0];
   break;
   case 1:
   PORTD = disp[1];
   break;
   case 2:
   PORTD = disp[2];
   break;
   case 3:
   PORTD = disp[3];
   break;
   case 4:
   PORTD = disp[4];
   break;
   case 5:
   PORTD = disp[5];
   break;
   case 6:
   PORTD = disp[6];
   break;
   case 7:
   PORTD = disp[7];
   break;
   case 8:
   PORTD = disp[8];
   break;
   case 9:
   PORTD = disp[9];
   break;
 }
}

void displayDigit(int dig){
 switch(dig){
   case 1:
   digitalWrite(a, HIGH);
   delay(3);
   digitalWrite(a, LOW);
   break;
   
   case 2:
   digitalWrite(b, HIGH);
   delay(3);
   digitalWrite(b, LOW);
   break;
   
   case 3:
   digitalWrite(c, HIGH);
   delay(3);
   digitalWrite(c, LOW);
   break;
   
   case 4:
   digitalWrite(d, HIGH);
   delay(3);
   digitalWrite(d, LOW);
 }
}

Did you put that smilley there? Please edit your post and include code tags. See How to use this forum.

But some tips:

Don't for-loop over every thing you want, do that in the loop and just keep track of which number to print.

Now you have time in the loop to check the buttons :) Don't forget debounce. Tip, grab a library to do that like Bounce2 ;)

Use better variable names, a b c d are just nonsens. A one letter variable is only good very local for example as counter in a for-loop. At global level a good variable name is at least 6 characters. It should FULLY explain what the variable is.

Let me short a function:

void displayNum(byte num){
  PORTD = disp[num];
}

And you can do the same for the digits...

But why reinvent the wheel? Grab a library to do the work like SevSeg Library.

I don't know where should I put the code of the 3 buttons. please help.

Put the code in the loop()...

Hi.

I’m new in Arduino programming, I have a problem with the code I created.

here is my code:

byte disp[] = {B11000000, B11111001, B10100100, B10110000, B10011001, B10010010, B10000011, B11111000, B10000000, B10011000};
int a = 8;
int b = 9;
int c = 10;
int d = 11;

const int buttonPin = 17;
boolean buttonState = LOW;
int pressed = 0;
void setup(){
    DDRD = B11111111;
    pinMode(a, OUTPUT);
    pinMode(b, OUTPUT);
    pinMode(c, OUTPUT);
    pinMode(d, OUTPUT);
    pinMode(buttonPin, INPUT);
    PORTD = disp[0];
    digitalWrite(a, HIGH) ;
    digitalWrite(b, HIGH); 
    digitalWrite(c, HIGH) ;
    digitalWrite(d, HIGH);
}

boolean debounceButton(boolean state){
  boolean stateNow = digitalRead(buttonPin);
  if(state != stateNow){
    delay(5);
    stateNow = digitalRead(buttonPin);
  }
  return stateNow;
}

void loop(){
  if(debounceButton(buttonState) == HIGH && buttonState == LOW && pressed == 0){
    pressed = 1;
    while(pressed){
      for(int fourth = 0; fourth < 10; fourth++){
        for(int third = 0; third < 10; third++){
          for(int second = 0; second < 6; second++){
            for(int first = 0; first < 10; first++){
              for(int m = 0; m < 100; m++){
                if(pressed == 1){
                  displayNum(first);
                  displayDigit(1);
                  displayNum(second);
                  displayDigit(2);
                  displayNum(third);
                  displayDigit(3);
                  displayNum(fourth);
                  displayDigit(4);
                }
                if(debounceButton(buttonState) == LOW && buttonState == HIGH && pressed == 1){
                  pressed = 0;
                  if(pressed == 0){
                    displayNum(1);
                    displayDigit(first);
                    displayNum(2);
                    displayDigit(second);
                    displayNum(3);
                    displayDigit(third);
                    displayNum(4);
                    displayDigit(fourth);
                    break;
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
         
void displayNum(byte num){
    PORTD = disp[num]; 
}

void displayDigit(int dig){
  switch(dig){
    case 1:
    digitalWrite(a, HIGH);
    delay(5);
    digitalWrite(a, LOW);
    break;
    
    case 2:
    digitalWrite(b, HIGH);
    delay(5);
    digitalWrite(b,LOW);
    break;
    
    case 3:
    digitalWrite(c, HIGH);
    delay(5);
    digitalWrite(c, LOW);
    break;
    
    case 4:
    digitalWrite(d, HIGH);
    delay(5);
    digitalWrite(d,LOW);
   }
}

I have a problem in pausing the counting sequence and creating a code for 2 LED (LED 1 is initially on and LED 2 is initially off) 1 button that toggled the switching of the 2 LED

thanks for anyone would help me

@shion, please do not cross-post. Threads merged.