BCD to 7 segment for hardware code issue

Hello everyone!I have a hardware for a bcd to 7 segment.I am trying to make the common cathode count from 0 to 9 and the common anode from 9 to 0 using two switches for each of them.They dont count properly and display random numbers when it counts.

#define buzzer 5 

#define LED1 6 

#define LED2 7 

#define SW1 8

#define SW2 9

#define Freq 2 

const int E3= 3 ;

const int AA0= 4;
 
const int D0= 10;

const int D1 =11 ;

const int D2= 12;

const int D3= 13 ; 
int seg1=9;
int seg2=0;


void setup(){
pinMode(buzzer,OUTPUT); 
pinMode(LED1,OUTPUT); 
pinMode(LED2,OUTPUT); 
pinMode(SW1,INPUT); 
pinMode(SW2,INPUT);
pinMode(AA0, OUTPUT);
pinMode(E3, OUTPUT);
pinMode(D3, OUTPUT);
pinMode(D2, OUTPUT);
pinMode(D1, OUTPUT);
pinMode(D0, OUTPUT);


  digitalWrite(LED1,LOW);//active low because it turns it on
  delay(250);
  digitalWrite(LED1,HIGH);
  tone(buzzer,440,250);//RED
  delay(250);

  digitalWrite(LED2,LOW);//active low because it turns it on
  delay(250);
  digitalWrite(LED2,HIGH);
   tone(buzzer,294,250);//RED
  delay(250);
}
void loop()  

{ 
  
  
 if(digitalRead(SW1)==HIGH){
 while(digitalRead(SW1)==HIGH){}//while the button is pressed
 for(int i=0;i<=seg1;i++){ 
 disp1(i);
 delay(1000);
  }
 //seg1++;
  
 }
  if(digitalRead(SW2)==HIGH){//Switch is active LOW
  while(digitalRead(SW2)==HIGH){}//while the button is pressed
  //seg2--; 
 for(int a=9;a>=seg2;a--){
 disp2(a); 
 delay(1000); 
  } 
  }
}
/*void disp(byte digit, byte num)
{
  digitalWrite(D0, num & 1);
  digitalWrite(D1, num & 2);
  digitalWrite(D2, num & 4);
  digitalWrite(D3, num & 8);

  // Select which BCD to 7SEG chip to load
  digitalWrite(AA0, digit & 1);
  digitalWrite(E3, HIGH);
  digitalWrite(E3, LOW);
}*/
void disp1(int num){ //this method entails making 0-9 combinations using the BCD pins by sending different outputs to turn each segment on or off.
  digitalWrite(AA0,LOW);
  digitalWrite(E3, HIGH); 
  if(num == 0)//0000
  {
    digitalWrite(D0, LOW); 
    digitalWrite(D1, LOW);
    digitalWrite(D2, LOW);
    digitalWrite(D3, LOW);
  }
  if(num == 1)//0001
  {
    digitalWrite(D0, HIGH);
    digitalWrite(D1, LOW);
    digitalWrite(D2, LOW);
    digitalWrite(D3, LOW);
  }
  if(num == 2)//0010
  {
    digitalWrite(D0, LOW);//0
    digitalWrite(D1, HIGH);//1
    digitalWrite(D2, LOW);//0
    digitalWrite(D3, LOW);//0
  }
  if(num == 3)//0011
  {
    digitalWrite(D0, HIGH);//1
    digitalWrite(D1, HIGH);//1
    digitalWrite(D2, LOW);//0
    digitalWrite(D3, LOW);//0
  }
  if(num == 4)//0100
  {
    digitalWrite(D0, LOW);//0
    digitalWrite(D1, LOW);//0
    digitalWrite(D2, HIGH);//1
    digitalWrite(D3, LOW);//0
  }
  if(num == 5)//0101
  {
    digitalWrite(D0, HIGH);//1
    digitalWrite(D1, LOW);//0
    digitalWrite(D2, HIGH);//1
    digitalWrite(D3, LOW);//0
  }
  if(num == 6)//0110
  {
    digitalWrite(D0, LOW);//0
    digitalWrite(D1, HIGH);//1
    digitalWrite(D2, HIGH);//1
    digitalWrite(D3, LOW);//0
  }
  if(num == 7) //0111
  {
    digitalWrite(D0, HIGH);//1
    digitalWrite(D1, HIGH);//1
    digitalWrite(D2, HIGH);//1
    digitalWrite(D3, LOW);//0
  }
  if(num == 8) //1000
  {
    digitalWrite(D0, LOW);//0
    digitalWrite(D1, LOW);//0
    digitalWrite(D2, LOW);//0
    digitalWrite(D3, HIGH);//1
  }
  if(num == 9)//1001
  {
    digitalWrite(D0, HIGH);//1
    digitalWrite(D1, LOW);//0
    digitalWrite(D2, LOW);//0
    digitalWrite(D3, HIGH);//1
  }
}

void disp2(int num){ //this method entails making 0-9 combinations using the BCD pins by sending different outputs to turn each segment on or off. 
  digitalWrite(AA0,HIGH);
  digitalWrite(E3, HIGH);
  if(num == 0)//0000
  {
    digitalWrite(D0, LOW); 
    digitalWrite(D1, LOW);
    digitalWrite(D2, LOW);
    digitalWrite(D3, LOW);
  }
  if(num == 1)//0001
  {
    digitalWrite(D0, HIGH);
    digitalWrite(D1, LOW);
    digitalWrite(D2, LOW);
    digitalWrite(D3, LOW);
  }
  if(num == 2)//0010
  {
    digitalWrite(D0, LOW);//0
    digitalWrite(D1, HIGH);//1
    digitalWrite(D2, LOW);//0
    digitalWrite(D3, LOW);//0
  }
  if(num == 3)//0011
  {
    digitalWrite(D0, HIGH);//1
    digitalWrite(D1, HIGH);//1
    digitalWrite(D2, LOW);//0
    digitalWrite(D3, LOW);//0
  }
  if(num == 4)//0100
  {
    digitalWrite(D0, LOW);//0
    digitalWrite(D1, LOW);//0
    digitalWrite(D2, HIGH);//1
    digitalWrite(D3, LOW);//0
  }
  if(num == 5)//0101
  {
    digitalWrite(D0, HIGH);//1
    digitalWrite(D1, LOW);//0
    digitalWrite(D2, HIGH);//1
    digitalWrite(D3, LOW);//0
  }
  if(num == 6)//0110
  {
    digitalWrite(D0, LOW);//0
    digitalWrite(D1, HIGH);//1
    digitalWrite(D2, HIGH);//1
    digitalWrite(D3, LOW);//0
  }
  if(num == 7) //0111
  {
    digitalWrite(D0, HIGH);//1
    digitalWrite(D1, HIGH);//1
    digitalWrite(D2, HIGH);//1
    digitalWrite(D3, LOW);//0
  }
  if(num == 8) //1000
  {
    digitalWrite(D0, LOW);//0
    digitalWrite(D1, LOW);//0
    digitalWrite(D2, LOW);//0
    digitalWrite(D3, HIGH);//1
  }
  if(num == 9)//1001
  {
    digitalWrite(D0, HIGH);//1
    digitalWrite(D1, LOW);//0
    digitalWrite(D2, LOW);//0
    digitalWrite(D3, HIGH);//1
  }
}
  

How is this different to your last topic? There is a forum rule about cross-posting and I think you may be breaking it by starting another topic about the same project.

Oh I apologize I thought I should make another topic because this one wasn't for the circuit on tinkercad but a different circuit for the hardware.

Should I delete this topic?

You got lots of great help and advice on the other topic from several forum members. You never updated that topic to let those people know if you succeeded or failed, or to thank them and pay your final circuit and code. Now you are asking for more help. The forum members will be less happy to help this time because they might think they wasted their time helping you on the other topic.

Oh but I said thank you and I will try it and marked the message as a solution I didn't know I was supposed to do that again my deepest apologies!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.