// These are connected to 74HC595 shift register (used to show game score):
const int LATCH_PIN = A1; // 74HC595 pin 12
const int DATA_PIN = A0; // 74HC595pin 14
const int CLOCK_PIN = A2; // 74HC595 pin 11
12, 4, 19
/* Digit table for the 7-segment display */
const uint8_t digitTable[] = {
0b11000000,
0b11111001,
0b10100100,
0b10110000,
0b10011001,
0b10010010,
0b10000010,
0b11111000,
0b10000000,
0b10010000,
};
void setup() {
Serial.begin(9600);
pinMode(LATCH_PIN, OUTPUT);
pinMode(CLOCK_PIN, OUTPUT);
pinMode(DATA_PIN, OUTPUT);
}
int i =0;
void loop() {
displayScore(i);
i++;
delay(100);
}
void sendScore(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 displayScore(int value) {
int high = value % 100 / 10;
int low = value % 10;
sendScore(high ? digitTable[high] : 0xff, digitTable[low]);
}