I'm using an arduino uno and some 7 segment displays to count from 0000 to 9999, i'm using the decoder cd4511 to save some ports, but in order to have the thousands in my counter, i needed to use the analog pins just like this:the leftmost display is connected to the analog pins
//BCD 1
int a1 = 4; //Bit 0 Decoder 1
int a2 = 5; //Bit 1 Decoder 1
int a3 = 6; //Bit 2 Decoder 1
int a4 = 7; //Bit 3 Decoder 1
//BCD 2
int b1 = 8; //Bit 0 Decoder 2
int b2 = 9; //Bit 1 Decoder 2
int b3 = 10; //Bit 2 Decoder 2
int b4 = 11; //Bit 3 Decoder 2
//BCD 3
int c1 = 0; //Bit 0 Decoder 3
int c2 = 1; //Bit 1 Decoder 3
int c3 = 2; //Bit 2 Decoder 3
int c4 = 3; //Bit 3 Decoder 3
//BCD 4
int m1 = 14; //Bit 0 Decoder 4
int m2 = 15; //Bit 1 Decoder 4
int m3 = 16; //Bit 2 Decoder 4
int m4 = 17; //Bit 3 Decoder 4
int n=0; //Setting initial value of n to 0
int d1;
int d2;
int d3;
int d4;
int teste;
int teste1;
int teste2;
int teste3;
void setup()
{
pinMode(0,OUTPUT);
pinMode(1,OUTPUT);
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
pinMode(11,OUTPUT);
pinMode(A0, OUTPUT);
pinMode(A1, OUTPUT);
pinMode(A2, OUTPUT);
pinMode(A3, OUTPUT);
}
void loop()
{
delay(1000); // Delay of 1 Second
n++;
if(n==1000)
{
n=0;
}
d1=n%10; // This will divide n by 10 and the remainder will be stored in d1
teste=n%100;
teste1=d1;
teste2=teste-teste1;
teste3=teste2/10;
d2=teste3; // This will divide n by 10 and the value before decimal will be stored in d2
d3=n/100;
d4=d1;
disp1(d1);
disp2(d2);
disp3(d3);
disp4(d4);
}
void disp3(int num)
{
if(num == 0)//0000
{
digitalWrite(c1, LOW);
digitalWrite(c2, LOW);
digitalWrite(c3, LOW);
digitalWrite(c4, LOW);
}
if(num == 1)//0001
{
digitalWrite(c1, HIGH);
digitalWrite(c2, LOW);
digitalWrite(c3, LOW);
digitalWrite(c4, LOW);
}
if(num == 2)//0010
{
digitalWrite(c1, LOW);//0
digitalWrite(c2, HIGH);//1
digitalWrite(c3, LOW);//0
digitalWrite(c4, LOW);//0
}
if(num == 3)//0011
{
digitalWrite(c1, HIGH);//1
digitalWrite(c2, HIGH);//1
digitalWrite(c3, LOW);//0
digitalWrite(c4, LOW);//0
}
if(num == 4)//0100
{
digitalWrite(c1, LOW);//0
digitalWrite(c2, LOW);//0
digitalWrite(c3, HIGH);//1
digitalWrite(c4, LOW);//0
}
if(num == 5)//0101
{
digitalWrite(c1, HIGH);//1
digitalWrite(c2, LOW);//0
digitalWrite(c3, HIGH);//1
digitalWrite(c4, LOW);//0
}
if(num == 6)//0110
{
digitalWrite(c1, LOW);//0
digitalWrite(c2, HIGH);//1
digitalWrite(c3, HIGH);//1
digitalWrite(c4, LOW);//0
}
if(num == 7) //0111
{
digitalWrite(c1, HIGH);//1
digitalWrite(c2, HIGH);//1
digitalWrite(c3, HIGH);//1
digitalWrite(c4, LOW);//0
}
if(num == 8) //1000
{
digitalWrite(c1, LOW);//0
digitalWrite(c2, LOW);//0
digitalWrite(c3, LOW);//0
digitalWrite(c4, HIGH);//1
}
if(num == 9)//1001
{
digitalWrite(c1, HIGH);//1
digitalWrite(c2, LOW);//0
digitalWrite(c3, LOW);//0
digitalWrite(c4, HIGH);//1
}
}
void disp1(int num)
{
if(num == 0)//0000
{
digitalWrite(a1, LOW);
digitalWrite(a2, LOW);
digitalWrite(a3, LOW);
digitalWrite(a4, LOW);
}
if(num == 1)//0001
{
digitalWrite(a1, HIGH);
digitalWrite(a2, LOW);
digitalWrite(a3, LOW);
digitalWrite(a4, LOW);
}
if(num == 2)//0010
{
digitalWrite(a1, LOW);//0
digitalWrite(a2, HIGH);//1
digitalWrite(a3, LOW);//0
digitalWrite(a4, LOW);//0
}
if(num == 3)//0011
{
digitalWrite(a1, HIGH);//1
digitalWrite(a2, HIGH);//1
digitalWrite(a3, LOW);//0
digitalWrite(a4, LOW);//0
}
if(num == 4)//0100
{
digitalWrite(a1, LOW);//0
digitalWrite(a2, LOW);//0
digitalWrite(a3, HIGH);//1
digitalWrite(a4, LOW);//0
}
if(num == 5)//0101
{
digitalWrite(a1, HIGH);//1
digitalWrite(a2, LOW);//0
digitalWrite(a3, HIGH);//1
digitalWrite(a4, LOW);//0
}
if(num == 6)//0110
{
digitalWrite(a1, LOW);//0
digitalWrite(a2, HIGH);//1
digitalWrite(a3, HIGH);//1
digitalWrite(a4, LOW);//0
}
if(num == 7) //0111
{
digitalWrite(a1, HIGH);//1
digitalWrite(a2, HIGH);//1
digitalWrite(a3, HIGH);//1
digitalWrite(a4, LOW);//0
}
if(num == 8) //1000
{
digitalWrite(a1, LOW);//0
digitalWrite(a2, LOW);//0
digitalWrite(a3, LOW);//0
digitalWrite(a4, HIGH);//1
}
if(num == 9)//1001
{
digitalWrite(a1, HIGH);//1
digitalWrite(a2, LOW);//0
digitalWrite(a3, LOW);//0
digitalWrite(a4, HIGH);//1
}
}
void disp2(int num)
{
if(num == 0)//0000
{
digitalWrite(b1, LOW);//
digitalWrite(b2, LOW);//0
digitalWrite(b3, LOW);//0
digitalWrite(b4, LOW);//0
}
if(num == 1)//0001
{
digitalWrite(b1, HIGH);//1
digitalWrite(b2, LOW);//0
digitalWrite(b3, LOW);//0
digitalWrite(b4, LOW);//0
}
if(num == 2)//0010
{
digitalWrite(b1, LOW);//0
digitalWrite(b2, HIGH);//1
digitalWrite(b3, LOW);//0
digitalWrite(b4, LOW);//0
}
if(num == 3)//0011
{
digitalWrite(b1, HIGH);//1
digitalWrite(b2, HIGH);//1
digitalWrite(b3, LOW);//0
digitalWrite(b4, LOW);//0
}
if(num == 4)//0100
{
digitalWrite(b1, LOW);//0
digitalWrite(b2, LOW);//0
digitalWrite(b3, HIGH);//1
digitalWrite(b4, LOW);//0
}
if(num == 5) //0101
{
digitalWrite(b1, HIGH);//1
digitalWrite(b2, LOW);//0
digitalWrite(b3, HIGH);//1
digitalWrite(b4, LOW);//0
}
if(num == 6) //0110
{
digitalWrite(b1, LOW);//0
digitalWrite(b2, HIGH);//1
digitalWrite(b3, HIGH);//1
digitalWrite(b4, LOW);//0
}
if(num == 7) //0111
{
digitalWrite(b1, HIGH);//1
digitalWrite(b2, HIGH);//1
digitalWrite(b3, HIGH);//1
digitalWrite(b4, LOW);//0
}
if(num == 8) //1000
{
digitalWrite(b1, LOW);//0
digitalWrite(b2, LOW);//0
digitalWrite(b3, LOW);//0
digitalWrite(b4, HIGH);//1
}
if(num == 9)//1001
{
digitalWrite(b1, HIGH);//1
digitalWrite(b2, LOW);//0
digitalWrite(b3, LOW);//0
digitalWrite(b4, HIGH);//1
}
}
void disp4(int num)
{
if(num == 0)//0000
{
digitalWrite(m1, LOW);//0
digitalWrite(m2, LOW);//0
digitalWrite(m3, LOW);//0
digitalWrite(m4, LOW);//0
}
if(num == 1)//0001
{
digitalWrite(m1, HIGH);//1
digitalWrite(m2, LOW);//0
digitalWrite(m3, LOW);//0
digitalWrite(m4, LOW);//0
}
if(num == 2)//0010
{
digitalWrite(m1, LOW);//0
digitalWrite(m2, HIGH);//1
digitalWrite(m3, LOW);//0
digitalWrite(m4, LOW);//0
}
if(num == 3)//0011
{
digitalWrite(m1, HIGH);//1
digitalWrite(m2, HIGH);//1
digitalWrite(m3, LOW);//0
digitalWrite(m4, LOW);//0
}
if(num == 4)//0100
{
digitalWrite(m1, LOW);//0
digitalWrite(m2, LOW);//0
digitalWrite(m3, HIGH);//1
digitalWrite(m4, LOW);//0
}
if(num == 5)//0101
{
digitalWrite(m1, HIGH);//1
digitalWrite(m2, LOW);//0
digitalWrite(m3, HIGH);//1
digitalWrite(m4, LOW);//0
}
if(num == 6)//0110
{
digitalWrite(m1, LOW);//0
digitalWrite(m2, HIGH);//1
digitalWrite(m3, HIGH);//1
digitalWrite(m4, LOW);//0
}
if(num == 7) //0111
{
digitalWrite(m1, HIGH);//1
digitalWrite(m2, HIGH);//1
digitalWrite(m3, HIGH);//1
digitalWrite(m4, LOW);//0
}
if(num == 8) //1000
{
digitalWrite(m1, LOW);//0
digitalWrite(m2, LOW);//0
digitalWrite(m3, LOW);//0
digitalWrite(m4, HIGH);//1
}
if(num == 9)//1001
{
digitalWrite(m1, HIGH);//1
digitalWrite(m2, LOW);//0
digitalWrite(m3, LOW);//0
digitalWrite(m4, HIGH);//1
}
}
I tried to do in BCD4 the same i did with the other BCDs, as well as creating the function disp4 like the other ones, but it doesn't seem to recognize a single signal from the analog pins and when i start the simulation the leftmost display just shows the number 8, since all the segments are running.here's what happens when i start the simulation on tinkercad
Nothing to do with the fact that pins A0-A4 are (also) analog input: they are above all digital I/O. I rather think that you were wrong in your wiring. The CD4511 in question is not connected to VCC, look here: