#define DATA_PIN A0 // Pin connected to DS of 74HC595
#define LATCH_PIN A1 // Pin connected to STCP of 74HC595
#define CLOCK_PIN A2 // Pin connected to SHCP of 74HC595
const uint8_t digitTable[] = {
0b11000000,
0b11111001,
0b10100100,
0b10110000,
0b10011001,
0b10010010,
0b10000010,
0b11111000,
0b10000000,
0b10010000,
};
void sendDigit(uint8_t high, uint8_t low) {
digitalWrite(LATCH_PIN, LOW);
shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, low);
shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, high);
digitalWrite(LATCH_PIN, HIGH);
}
void displayDigit(int num) {
int high = num % 100 / 10;
int low = num % 10;
sendDigit(high ? digitTable[high] : 0xff, digitTable[low]);
}
void clearDisplay(void)
{
sendDigit(0xff, 0xff);
}
void setup() {
pinMode(DATA_PIN, OUTPUT);
pinMode(CLOCK_PIN, OUTPUT);
pinMode(LATCH_PIN, OUTPUT);
}
void loop()
{
displayDigit(26);
delay(2000);
clearDisplay();
delay(2000);
}