Devices & Components
Arduino Uno Rev3
5 mm LED: Red
Tactile Switch, Top Actuated
5 mm LED: Green
5 mm LED: Yellow
Buzzer
Resistor 1k ohm
Breadboard (generic)
Project description
Code
Fastest Finger First
arduino
Arduino code
1// Paul Brace 2// 8 Jan 2021 3 4// fastest finger first 5// 3 6 buttons - first one pressed lights their light and hears their tone 7// Reset 8 button flashes all lights twice (proves they are working) 9// then waits. 10 11int 12 redButton = 1; 13int greenButton = 2; 14int amberButton = 3; 15int redLED = 4; 16int 17 greenLED = 5; 18int amberLED = 6; 19int buzzer = 7; 20int resetButton = 8; 21bool 22 waiting = false; 23int redNote = 262; 24int greenNote = 523; 25int amberNote 26 = 1047; 27int duration = 250; 28 29void setup() { 30 pinMode(redButton, INPUT_PULLUP); 31 32 pinMode(greenButton, INPUT_PULLUP); 33 pinMode(amberButton, INPUT_PULLUP); 34 35 pinMode(resetButton, INPUT_PULLUP); 36 pinMode(redLED, OUTPUT); 37 pinMode(greenLED, 38 OUTPUT); 39 pinMode(amberLED, OUTPUT); 40 pinMode(buzzer, OUTPUT); 41 // Flash 42 4 times (each call flashes twice) to show ready 43 for (int i = 0; i < 2; i++) 44 { 45 FlashLEDs(); 46 } 47} 48 49void FlashLEDs() { 50 for (int i = 0; 51 i < 2; i++){ 52 digitalWrite(redLED, HIGH); 53 digitalWrite(greenLED, HIGH); 54 55 digitalWrite(amberLED, HIGH); 56 delay(500); 57 digitalWrite(redLED, 58 LOW); 59 digitalWrite(greenLED, LOW); 60 digitalWrite(amberLED, LOW); 61 62 delay(500); 63 } 64 waiting = true; 65} 66 67bool checkButtons(){ 68 69 // Check to see if a button has been pressed 70 // If there is a dead heat (very 71 unlikely) both lights will show 72 bool pressed = false; 73 if (digitalRead(amberButton) 74 == LOW){ 75 digitalWrite(amberLED, HIGH); 76 tone(buzzer, amberNote, duration); 77 78 pressed = true; 79 } 80 if (digitalRead(redButton) == LOW){ 81 digitalWrite(redLED, 82 HIGH); 83 tone(buzzer, redNote, duration); 84 pressed = true; 85 } 86 87 if (digitalRead(greenButton) == LOW){ 88 digitalWrite(greenLED, HIGH); 89 90 tone(buzzer, greenNote, duration); 91 pressed = true; 92 } 93 return(pressed); 94} 95 96void 97 loop() { 98 if (digitalRead(resetButton) == LOW) 99 { 100 FlashLEDs(); 101 102 } 103 if (waiting){ 104 waiting = !checkButtons(); 105 } 106} 107
Downloadable files
Fastest Finger First
Fastest Finger First
Fastest Finger First - Breadboard
Fastest Finger First - Breadboard

Fastest Finger First Schematic
Fastest Finger First Schematic

Fastest Finger First Schematic
Fastest Finger First Schematic

Fastest Finger First
Fastest Finger First
Fastest Finger First - Breadboard
Fastest Finger First - Breadboard

Comments
Only logged in users can leave comments