Code for a 7-segment display sequence with LEDs

Hi, i am really new at coding, so i don’t really know how to deal with this. So i got this scheme which consists of 8 LEDs and a 7-segment display with a BCD decoder. I need 8 states each using the 8 LEDs to light up so they show a binary number for every state (state 1 lights up the LEDs to show 0001; state 2 1101;etc.) and the 7-segment display to show the number of the state ( 1,2,3,etc. until 8).
This is the scheme

So far i came up this but it’s not working

const int A=13;
const int B=12;
const int C=11;
const int D=10;

int led0 = 9;
int led1 = 8;
int led2 = 7;
int led3 = 6;
int led4 = 5;
int led5 = 4;
int led6 = 3;
int led7 = 2;

void setup() {
  pinMode(A3, INPUT);
  pinMode(A, OUTPUT);
  pinMode(B, OUTPUT);
  pinMode(C, OUTPUT);
  pinMode(D, OUTPUT);

  pinMode(led0, OUTPUT);
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
  pinMode(led5, OUTPUT);
  pinMode(led6, OUTPUT);
  pinMode(led7, OUTPUT);
}

int count = 0; //variabila folosita pentru afisarea numarului

void loop() {
  if (digitalRead(A3) == LOW) //daca butonul e apasat
    {
    count++; 
    delay(200); //the delay prevent from button bouncing
    if (count == 10) //we want to count from 0 to 9!
      count = 0;
    to_BCD(); //convert to binary
    }
   
  if (count == 10)
    count = 0;

digitalWrite(led0, LOW);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, HIGH);
digitalWrite(led4, HIGH);
digitalWrite(led5, HIGH);
digitalWrite(led6, HIGH);
digitalWrite(led7, HIGH);
delay(229.4);

digitalWrite(led0, LOW);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
digitalWrite(led7, HIGH);
delay(7.4);

digitalWrite(led0, LOW);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, HIGH);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
digitalWrite(led7, LOW);
delay(118.4);

digitalWrite(led0, LOW);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, HIGH);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
digitalWrite(led7, LOW);
delay(59.2);

digitalWrite(led0, LOW);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, HIGH);
digitalWrite(led5, LOW);
digitalWrite(led6, HIGH);
digitalWrite(led7, HIGH);
delay(81.4);

digitalWrite(led0, LOW);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, HIGH);
digitalWrite(led4, LOW);
digitalWrite(led5, HIGH);
digitalWrite(led6, LOW);
digitalWrite(led7, HIGH);
delay(155.4);

digitalWrite(led0, LOW);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
digitalWrite(led7, LOW);
delay(0);

digitalWrite(led0, LOW);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, HIGH);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
digitalWrite(led7, LOW);
delay(118.4);
}

void to_BCD()
{
    if (count == 0) //write 0000
	{
      digitalWrite(A, LOW);
      digitalWrite(B, LOW);
      digitalWrite(C, LOW);
      digitalWrite(D, LOW);
    }
    
    if (count == 1) //write 0001
	{
      digitalWrite(A, HIGH);
      digitalWrite(B, LOW);
      digitalWrite(C, LOW);
      digitalWrite(D, LOW);
    }
    
    if (count == 2) //write 0010
	{
      digitalWrite(A, LOW);
      digitalWrite(B, HIGH);
      digitalWrite(C, LOW);
      digitalWrite(D, LOW);
    }
    
    if (count == 3) //write 0011
	{
      digitalWrite(A, HIGH);
      digitalWrite(B, HIGH);
      digitalWrite(C, LOW);
      digitalWrite(D, LOW);
    }
    
    if (count == 4) //write 0100
	{
      digitalWrite(A, LOW);
      digitalWrite(B, LOW);
      digitalWrite(C, HIGH);
      digitalWrite(D, LOW);
    }
    
    if (count == 5) //write 0101
	{
      digitalWrite(A, HIGH);
      digitalWrite(B, LOW);
      digitalWrite(C, HIGH);
      digitalWrite(D, LOW);
    }
    
    if (count == 6) //write 0110
	{
      digitalWrite(A, LOW);
      digitalWrite(B, HIGH);
      digitalWrite(C, HIGH);
      digitalWrite(D, LOW);
    }
    
    if (count == 7) //write 0111
	{
      digitalWrite(A, HIGH);
      digitalWrite(B, HIGH);
      digitalWrite(C, HIGH);
      digitalWrite(D, LOW);
    }
    
    if (count == 8) //write 1000
	{
      digitalWrite(A, LOW);
      digitalWrite(B, LOW);
      digitalWrite(C, LOW);
      digitalWrite(D, HIGH);
    }
    
    if (count == 9) //write 1001
	{
      digitalWrite(A, HIGH);
      digitalWrite(B, LOW);
      digitalWrite(C, LOW);
      digitalWrite(D, HIGH);
    } 
}

The digitalWrite highs and lows in the void loop represent each binary number i need the LEDs to show for each state.

2 posts were merged into an existing topic: 7 segment BCD binary counter