/**
Simon Game for Arduino with Score display
Copyright (C) 2022, Uri Shaked
Released under the MIT License.
*/
/* Constants - define pin numbers for LEDs,
buttons and speaker, and also the game tones: */
// 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
/**
Set up the Arduino board and initialize Serial communication
*/
void setup() {
Serial.begin(9600);
for (byte i = 0; i < 4; i++) {
}
pinMode(LATCH_PIN, OUTPUT);
pinMode(CLOCK_PIN, OUTPUT);
pinMode(DATA_PIN, OUTPUT);
// The following line primes the random number generator.
// It assumes pin A3 is floating (disconnected):
}
/* Digit table for the 7-segment display */
const uint8_t digitTable[] = {
0b11000000,
0b11111001,
0b10100100,
0b10110000,
0b10011001,
0b10010010,
0b10000010,
0b11111000,
0b10000000,
0b10010000,
};
const uint8_t DASH = 0b10111111;
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 high = 8;
int low = 8;
sendScore(high ? digitTable[high] : 0xff, digitTable[low]);
}
void loop() {
displayScore();
}