Demultiplexer with latch bcd to 7 segment decoder

void setup() {
 // pinMode(2,OUTPUT);
 // pinMode(5,OUTPUT);
 // pinMode(3,OUTPUT);
 // pinMode(7,OUTPUT);
 //// pinMode(5,OUTPUT);
 // pinMode(9,OUTPUT);
   for(int pin=2;pin<=9;pin++){//pin starts from pin 2,if less than or equal to 8 incraese the pin
    pinMode(pin,OUTPUT);//sets pin as output
    digitalWrite(pin,HIGH);//turns segment on
    delay(250);//delays by quarter of a second
    digitalWrite(pin,LOW);//switches segment off
}
}

void loop() {
 disp1(d1);
 disp2(d2);
 disp3(d3);
 disp4(d4);
 disp5(d5);
 disp6(d6);
 delay(100);
 
}
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. 
  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. 
  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 disp3(int num){ //this method entails making 0-9 combinations using the BCD pins by sending different outputs to turn each segment on or off. 
  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 disp4(int num){ //this method entails making 0-9 combinations using the BCD pins by sending different outputs to turn each segment on or off. 
  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, 


Hello everyone!I'm trying to display numbers on my 7 segments but all that is displayed are 0s.

I don't know what the variable 'd1' is, and I don't know the value for 'D1', because the sketch is not complete.
The picture is too small to see what logic chips they are.

Tinkercad used to have a button to make a circuit public, so others can copy it and try to change things. That button is now changed to invite others to work on your project (don't show that share-link on this forum, because others could change things in your project). If you know a way to make a copy, then I can try a few things in Tinkercad myself.

I can see CD4511 but the Fritzing is not suitable for understanding or troubleshooting the circuit or software. Please provide a standard style schematic, even if it is hand drawn.

Thanks for you reply D1 is a databus will d1 was just a variable created for the 7 segment to display numbers .I will try making a copy thank you!

The circuit was provided by my lecturer,I only have a schematic for my hardware circuit but I was using this one because I wasn't able to control my hardware and I prefer tinkercad.I can show you my schematic it works the same way but in the tinkercad there are more ICs and 7 segments.

Hi,
If you have a proper schematic in Tinkercad, then you should be able to EXPORT a jpg image suitable for the forum.

Thanks.. Tom.. :grinning: :+1: :coffee: :australia:

I think they have removed the feature I can't share anymore unlike last year





They wouldn't let me export so I had to take a screenshot sorry about this!

Provided as an example or mandated for your use? You do know all this can be done with 1 chip?

Yes I know it can be done with a single chip but it was mandatory to use the circuit

Your lecturer is cruel and sadistic! I can't even figure out how it's supposed to work. The layout of the schematic seems to deliberately obfuscate the circuit.

There's a cd4511 7-seg decoder/driver for each digit. Then there's a bunch of inverter gates and quad input nand gates. I guess these are forming a 6-way decoder/multiplexer to select one of the digits.

Those schematics are really bad, they are the worst :poop: The automatically generated schematics work only for very small projects. I hope you don't think that a schematic should look like that. If you think that it is almost impossible to see what that schematic does, then you are right.

A real schematic is for example this: https://learn.adafruit.com/assets/53093

Your question is why you only see zeros. Since the values that you show are in the "d1", "d2", and so on, variables. Perhaps they are all zero. So I asked about that and then you say that it is just a variable :scream:

In the settings of a Tinkercad project, it can be set as "Private" or "Public", perhaps I can make a copy for myself when it is public.

[ADDED] @PaulRB Tinkercad can make a schematic from the circuit that is made with drag and drop. It fails for a larger project. I tried a 8x8 led matrix with individual leds and Tinkercad has no idea that it is a matrix. I'm glad that we both agree that these schematics are useless.

Are you ever going to post your complete sketch as requested early in the thread?

Hahaha you said it! But here is a handdrawn schematic to show how it works though I used a 74hct238 and 74hct4543 and they are only two segments

Sorry what do you mean by complete sketch?

Not a part of the sketch, but the full sketch.
Maybe we can try to compile and test that.
There is a website for it: https://snippets-r-us.com/

Yes I know about the private and public feature but the problem is that its no longer there just the license public domain which I set it to and I'm still not able to share it. :sob:

I think its because I'm a student enrolled in the class so I'm automatically in safe mode

char secLsd = 7; 
char secMsd = 5;
char minLsd = 9;
char minMsd = 5;
char hrsLsd = 3;
char hrsMsd = 2;
const int AA2 = 5; 
const int AA1 = 4;
const int AA0 = 3;
const int E3 = 2;
const int D3 = 11;
const int D2 = 10;
const int D1 = 9;
const int D0 = 8;
int d1;
int d2;
int d3;
int d4;
int d5;
int d6;

void setup() {
 // pinMode(2,OUTPUT);
 // pinMode(5,OUTPUT);
 // pinMode(3,OUTPUT);
 // pinMode(7,OUTPUT);
 //// pinMode(5,OUTPUT);
 // pinMode(9,OUTPUT);
   for(int pin=2;pin<=9;pin++){//pin starts from pin 2,if less than or equal to 8 incraese the pin
    pinMode(pin,OUTPUT);//sets pin as output
    digitalWrite(pin,HIGH);//turns segment on
    delay(250);//delays by quarter of a second
    digitalWrite(pin,LOW);//switches segment off
}
}

void loop() {
 disp1(d1);
 disp2(d2);
 disp3(d3);
 disp4(d4);
 disp5(d5);
 disp6(d6);
 delay(100);
 
}
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. 
  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. 
  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 disp3(int num){ //this method entails making 0-9 combinations using the BCD pins by sending different outputs to turn each segment on or off. 
  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 disp4(int num){ //this method entails making 0-9 combinations using the BCD pins by sending different outputs to turn each segment on or off. 
  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 disp5(int num){ //this method entails making 0-9 combinations using the BCD pins by sending different outputs to turn each segment on or off. 
  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 disp6(int num){ //this method entails making 0-9 combinations using the BCD pins by sending different outputs to turn each segment on or off. 
  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
  }
}

 

 
 

 
 

 
 

 

Sorry I didn't know that it wasn't a full sketch at the beginning my deepesest apologies!