Devices & Components
Arduino Nano
Buzzer
Shift Register- Serial to Parallel
7 Segment LED Display, Red
9V battery (generic)
5 mm LED: Red
Resistor 221 ohm
5 mm LED: Green
Hardware & Tools
Drill, Screwdriver
Soldering iron (generic)
Project description
Code
score_display.ino
arduino
1byte seg_digits[10] = 2{ 3 B11111100, // = 0 4 B01100000, // = 1 5 B11011010, // = 2 6 B11110010, // = 3 7 B01100110, // = 4 8 B10110110, // = 5 9 B10111110, // = 6 10 B11100000, // = 7 11 B11111110, // = 8 12 B11100110 // = 9 13}; 14 15 16 17 18 19void displayDigit(int x) 20{ 21 digitalWrite(latchPin, LOW); 22 shiftOut(dataPin, clockPin, LSBFIRST, seg_digits[x]); 23 digitalWrite(latchPin, HIGH); 24} 25 26void displayInitialSetup() 27{ 28 pinMode(latchPin, OUTPUT); 29 pinMode(dataPin, OUTPUT); 30 pinMode(clockPin, OUTPUT); 31 displayDigit(0); 32} 33
game.ino
arduino
1 2 3 4void gameInitialSetup() 5{ 6 pinMode(STOP_LED, OUTPUT); 7 pinMode(GO_LED, OUTPUT); 8 pinMode(BUZZ, OUTPUT); 9 pinMode(TOUCH, HIGH); 10 digitalWrite(TOUCH, LOW); 11} 12 13 14void failAlarm() 15{ 16 digitalWrite(STOP_LED, HIGH); 17 beep(); 18 delay(150); 19 20 digitalWrite(STOP_LED, LOW); 21 digitalWrite(BUZZ, LOW); 22 delay(500); 23} 24 25void beep() 26{ 27 for(int i=0; i<3; i++) 28 { 29 digitalWrite(BUZZ, HIGH); 30 delay(50); 31 digitalWrite(BUZZ, LOW); 32 delay(50); 33 } 34} 35
nervous_meter_score.ino
arduino
1int latchPin = 3; // ST_CP [RCK] on 74HC595 2int clockPin = 4; // SH_CP [SCK] on 74HC595 3int dataPin = 2; // DS [S1] on 74HC595 4const int STOP_LED = 6; 5const int GO_LED = 7; 6const int BUZZ = 8; 7const int TOUCH = 10; 8 9const int fail_threshold = 9; 10 11enum Status 12{ 13 STOP = 0, 14 GO = 1 15}; 16 17 18void setup() { 19 Serial.begin(9600); 20 displayInitialSetup(); 21 gameInitialSetup(); 22} 23 24 25Status status = GO; 26int failCounter = 0; 27 28void loop() { 29 30 31 while (failCounter > fail_threshold) 32 { 33 gameover(); 34 } 35 36 switch (status) 37 { 38 case GO: 39 digitalWrite(GO_LED, HIGH); 40 digitalWrite(STOP_LED, LOW); 41 digitalWrite(BUZZ, LOW); 42 if (digitalRead(TOUCH) == HIGH) 43 { 44 status = STOP; 45 } 46 break; 47 48 case STOP: 49 digitalWrite(GO_LED, LOW); 50 failCounter++; 51 if (failCounter > fail_threshold) 52 break; 53 displayDigit(failCounter); 54 Serial.println(failCounter); 55 failAlarm(); 56 status = GO; 57 break; 58 } 59 60} 61 62 63byte seg_spin[6] = 64{ 65 B10000000, 66 B01000000, 67 B00100000, 68 B00010000, 69 B00001000, 70 B00000100 71}; 72void gameover() 73{ 74 for (int i=0; i<6; i++) 75 { 76 digitalWrite(BUZZ, HIGH); 77 delay(5); 78 digitalWrite(BUZZ, LOW); 79 delay(50); 80 digitalWrite(latchPin, LOW); 81 shiftOut(dataPin, clockPin, LSBFIRST, seg_spin[i]); 82 digitalWrite(latchPin, HIGH); 83 delay(10); 84 } 85} 86
score_display.ino
arduino
1byte seg_digits[10] = 2{ 3 B11111100, // = 0 4 B01100000, // = 1 5 B11011010, // = 2 6 B11110010, // = 3 7 B01100110, // = 4 8 B10110110, // = 5 9 B10111110, // = 6 10 B11100000, // = 7 11 B11111110, // = 8 12 B11100110 // = 9 13}; 14 15 16 17 18 19void displayDigit(int x) 20{ 21 digitalWrite(latchPin, LOW); 22 shiftOut(dataPin, clockPin, LSBFIRST, seg_digits[x]); 23 digitalWrite(latchPin, HIGH); 24} 25 26void displayInitialSetup() 27{ 28 pinMode(latchPin, OUTPUT); 29 pinMode(dataPin, OUTPUT); 30 pinMode(clockPin, OUTPUT); 31 displayDigit(0); 32} 33
game.ino
arduino
1 2 3 4void gameInitialSetup() 5{ 6 pinMode(STOP_LED, OUTPUT); 7 pinMode(GO_LED, OUTPUT); 8 pinMode(BUZZ, OUTPUT); 9 pinMode(TOUCH, HIGH); 10 digitalWrite(TOUCH, LOW); 11} 12 13 14void failAlarm() 15{ 16 digitalWrite(STOP_LED, HIGH); 17 beep(); 18 delay(150); 19 20 digitalWrite(STOP_LED, LOW); 21 digitalWrite(BUZZ, LOW); 22 delay(500); 23} 24 25void beep() 26{ 27 for(int i=0; i<3; i++) 28 { 29 digitalWrite(BUZZ, HIGH); 30 delay(50); 31 digitalWrite(BUZZ, LOW); 32 delay(50); 33 } 34} 35
Downloadable files
Schematic
Just keep in mind the D10 getting connected to the 5V, will constitute a failure causing the buzzer to beep and counter to count. In the schematic there wasn't a way to show it. So build up your wires and structure accordingly :)
Schematic

Schematic
Just keep in mind the D10 getting connected to the 5V, will constitute a failure causing the buzzer to beep and counter to count. In the schematic there wasn't a way to show it. So build up your wires and structure accordingly :)
Schematic

Comments
Only logged in users can leave comments