Hello gentlemen.
I tried to reproduce this project:
I followed the same diagram, obviously I had some problems. I didn't find a solution, so I only extracted part of the program(this is for common anode):
#define latchPin 5
#define clockPin 6
#define dataPin 4
int thousands;
int hundreds;
int tens;
int unit;
void setup ()
{
pinMode(9,OUTPUT);//digit 4
pinMode(10,OUTPUT);//digit 1
pinMode(11,OUTPUT);//digit 2
pinMode(12,OUTPUT);//digit 3
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
}
void loop ()
{
int number = 1234;// may be formed of one digit or two digits
int thousands = number/1000%10;
int hundreds = number/100%10;
int tens = number/10%10;
int unit = number%10;
int t= unit;
int u= tens;
int v= hundreds;
int w= thousands;
//Converting the individual digits into corresponding number for passing it through the shift register so LEDs are turned ON or OFF in seven segment
switch (t)
{
case 0:
unit = 64;
break;
case 1:
unit = 121;
break;
case 2:
unit = 36;
break;
case 3:
unit = 48;
break;
case 4:
unit = 25;
break;
case 5:
unit = 18;
break;
case 6:
unit = 2;
case 7:
unit = 120;
break;
case 8:
unit = 00;
break;
case 9:
unit = 16;
break;
}
switch (u)
{
case 0:
tens = 64;
break;
case 1:
tens = 121;
break;
case 2:
tens = 36;
break;
case 3:
tens = 48;
break;
case 4:
tens = 25;
break;
case 5:
tens = 18;
break;
case 6:
tens = 2;
case 7:
tens = 120;
break;
case 8:
tens = 00;
break;
case 9:
tens = 16;
break;
}
switch (v)
{
case 0:
hundreds = 64;
break;
case 1:
hundreds = 121;
break;
case 2:
hundreds = 36;
break;
case 3:
hundreds = 48;
break;
case 4:
hundreds = 25;
break;
case 5:
hundreds = 18;
break;
case 6:
hundreds = 2;
case 7:
hundreds = 120;
break;
case 8:
hundreds = 00;
break;
case 9:
hundreds = 16;
break;
}
switch (w)
{
case 0:
thousands = 64;
break;
case 1:
thousands = 121;
break;
case 2:
thousands = 36;
break;
case 3:
thousands = 48;
break;
case 4:
thousands = 25;
break;
case 5:
thousands = 18;
break;
case 6:
thousands = 2;
case 7:
thousands = 120;
break;
case 8:
thousands = 00;
break;
case 9:
thousands = 16;
break;
}
digitalWrite(9, LOW);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST,thousands);
digitalWrite(latchPin, HIGH);
digitalWrite(9, HIGH);
delay(5); // delay for multiplexing
digitalWrite(10, LOW);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST,hundreds );
digitalWrite(latchPin, HIGH);
digitalWrite(10, HIGH);
delay(5);
digitalWrite(11, LOW);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST,tens);
digitalWrite(latchPin, HIGH);
digitalWrite(11, HIGH);
delay(5);
digitalWrite(12, LOW);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST,unit);
digitalWrite(latchPin, HIGH);
digitalWrite(12, HIGH);
delay(5);
}
I don`t understand how to display a number on the 7 segment display digit by digit. This number represents the value measured with a dht11 or another sensor. For example number = 32, I want to display 3 on digit 1 and 2 on digit 2, but it lights up like an 8. How to correctly represent a number on this display? Or, maybe you have some suggestions about the clock, using common anode display.