byte digits[] = {0x7e, 0x30, 0x6d, 0x79, 0x33, 0x5b, 0x5f, 0x70, 0x7f, 0x7b};
byte cathodePins[] = {0x70, 0xb0, 0xd0, 0xe0};
int dataPin = 2;
int clockPin = 3;
int latchPin = 4;
void setup() {
// put your setup code here, to run once:
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(latchPin, OUTPUT);
}
void loop() {
for(int i = 0; i < 100; i++){
printDigits(i);
delay(100);
}
}
void printDigits(int num){
if(num >= 0 || num <=99){
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, digits[num % 10]);
shiftOut(dataPin, clockPin, MSBFIRST, cathodePins[0]);
digitalWrite(latchPin, HIGH);
delay(33);
if(num > 9 ){
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, digits[(num/10) % 10]);
shiftOut(dataPin, clockPin, MSBFIRST, cathodePins[1]);
digitalWrite(latchPin, HIGH);
delay(33);
if(num > 99){
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, digits[(num/100) % 10]);
shiftOut(dataPin, clockPin, MSBFIRST, cathodePins[2]);
delay(33);
}
}
}
}
/*void printDigits(int num){
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, digits[num % 10]);
shiftOut(dataPin, clockPin, MSBFIRST, cathodePins[0]);
digitalWrite(latchPin, HIGH);
delay(33);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, digits[(num/10) % 10]);
shiftOut(dataPin, clockPin, MSBFIRST, cathodePins[1]);
digitalWrite(latchPin, HIGH);
delay(33);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, digits[(num/100) % 10]);
shiftOut(dataPin, clockPin, MSBFIRST, cathodePins[2]);
digitalWrite(latchPin, HIGH);
delay(33);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, digits[(num/1000) % 10]);
shiftOut(dataPin, clockPin, MSBFIRST, cathodePins[3]);
digitalWrite(latchPin, HIGH);
delay(33);
}*/