int clockPin = 2;
int latchPin = 3;
int dataPin = 4;
int num;
int byte1;
int byte2_1 = 0b00010000, byte2_2 = 0b00100000, byte2_3 = 0b01000000, byte2_4 = 0b10000000;
void setup() {
// put your setup code here, to run once:
pinMode(clockPin, OUTPUT);
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
}
byte numchecker(int a) {
if (a == 1) {
byte1 = 0b10011111;
}
else if (a == 2) {
byte1 = 0b00100101;
}
else if (a == 3) {
byte1 = 0b00001101;
}
else if (a == 4) {
byte1 = 0b10011001;
}
else if (a == 5) {
byte1 = 0b01001001;
}
else if (a == 6) {
byte1 = 0b01000001;
}
else if (a == 7) {
byte1 = 0b00011111;
}
else if (a == 8) {
byte1 = 0b00000001;
}
else if (a == 9) {
byte1 = 0b00001001;
}
else if (a == 0) {
byte1 = 0b00000011;
}
}
void byteconv(int num){
int num1 = 0, num2 = 0, num3 = 0, num4 = 0;
if (num >= 0 && num < 10){
num1 = num;
}
else if (num >= 10 && num < 100){
num2 = num/10;
num1 = num - (num2*10);
}
else if (num >= 100 && num < 1000){
num3 = num/100;
num2 = (num - (num3*100))/10 ;
num1 = (num - (num3*100) - (num2*10));
}
else if (num >= 1000 && num <= 9999){
num4 = num/1000;
num3 = (num - (num4*1000))/100 ;
num2 = (num - (num4*1000) - (num3*100))/10 ;
num1 = (num - (num4*1000) - (num3*100)-(num2*10)) ;
}
else if (num > 9999){
num1 = num2 = num3 = num4 = 0 ;
}
numchecker(num1);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, byte2_1);
shiftOut(dataPin, clockPin, LSBFIRST, byte1);
digitalWrite(latchPin, HIGH);
numchecker(num2);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, byte2_2);
shiftOut(dataPin, clockPin, LSBFIRST, byte1);
digitalWrite(latchPin, HIGH);
numchecker(num3);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, byte2_3);
shiftOut(dataPin, clockPin, LSBFIRST, byte1);
digitalWrite(latchPin, HIGH);
numchecker(num4);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, byte2_4);
shiftOut(dataPin, clockPin, LSBFIRST, byte1);
digitalWrite(latchPin, HIGH);
return 0;
}
void loop() {
// put your main code here, to run repeatedly:
num = millis()/1000;
byteconv(num);
}