First-click triggered LED (for multiple purposes)
When I started doing this project, I wanted to incorporate some randomness into it. I am very used to coding and I find it the most fascinating when something is non-deterministic. This means that it is either random or has unpredictable events, like when two players face each other. Also, to continue this unpredictable idea, I decided to use no variables for the project. Which makes a program unable of remembering past states, previous outcome, or even input. This motivated me to do a trigger reaction system that would show which one of two users is the first one to click on a button. It can be used just as a simple reflex game or as the turn-assignment computer on games like jeopardy, etc.
Materials:
-Arduino Uno Starter Kit
-Arduino board
-Piezo Buzzer
-3 LEDs
-2 switch-buttons
Set up:
To set up the buzzer:
To set up the LEDs:
To set up the switch-buttons:
Follow the sample sketches provided pluging all the elements in at the same time.
Code:
void setup() {
pinMode(9, OUTPUT); // Set buzzer – pin 9 as an output
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
pinMode(2, INPUT);
pinMode(4, INPUT);
}
void loop() {
//peep
digitalWrite(11, HIGH);
tone(9, 1000); // Send 1KHz sound signal…
delay(500);
digitalWrite(11, LOW);
noTone(9);
delay(500);
//peep
digitalWrite(11, HIGH);
tone(9, 1000); // Send 1KHz sound signal…
delay(500);
digitalWrite(11, LOW);
noTone(9);
delay(500);
//peeeeeeep
digitalWrite(11, HIGH);
tone(9, 1000); // Send 1KHz sound signal…
delay(1000);
digitalWrite(11, LOW);
noTone(9);
if (digitalRead(2) == HIGH) {
digitalWrite(13, HIGH);
digitalWrite(12, LOW);
}
if (digitalRead(4) == HIGH) {
digitalWrite(12, HIGH);
digitalWrite(13, LOW);
}
delay(5000);
}
Finished product:
The board after setting up the LEDs and buttons with their wires and resistors.
Close up on the wiring of the board’s buttons.
Finished project after the yellow button was pressed first and the green LED was a triggered response.
Finished project during the game’s initial countdown sequence (which is repeated in every loop to allow for multiple runs) while blue LED is on and the buzzer is beeping.
Related