Finger- On- The- Button
In our latest project, we developed an interactive game called Finger-on-the-Button. This game operates similarly to the last-man-standing concept, where players compete to be the last one holding the button. When a player pushes the button, the LED lights up, and the person who releases the button is eliminated. The ultimate winner is the last person holding the button. This game promises hours of fun and friendly competition.
Supplies
- 10 Wires,
- 2 Push- Button
- 1 buzzer,
- 1 breadboard,
- 1 Arduino UNO,
- 1 resistor,
- 1 USB cable,
- And 1 computer with an Arduino IDE.
Assembling the Right Components
With the Arduino and Breadboard I have 10 wires, two buttons, two LEDs, two 330s resistors, and a speaker.
- Put wires in the Arduino sections labeled, 13, 12, ~11, Tx>1. In the schematic with TinkerCad these are the wire colored, 13 = Magenta, 12 = Red, ~11 = Green, Tx>1 = Light Blue. Put these in their spots on the Breadboard.
- Then the light- blue wire connected to the Arduino, in the spot labeled: GND, is in the negative column of the breadboard.
- Connect the two resistors to the negative column. Then place the LEDs where those resistors are.
- Connect speaker to Breadboard, red wire to Arduino 2, black wire to Breadboard negative column.
- Connect the buttons to the same row as 13, and Tx>1.
- Then wire buttons to another negative column, and connect that negative column to the other.
- Then plug in the Arduino C++ code.
If you would like a reference, here it is...
Code
- Here’s the code for our project once finished with installation…// Pin assignments
- // Changing the numbers changes which pin holes you use
- int ButtonPlayer2 = 1; // Green Player
- int ButtonPlayer1 = 13; // Red Player
- int Green = 11; // Green Light
- int Red = 12;// Red Light
- int buzzerPin = 2; // Buzzer
- void setup() {
- pinMode(ButtonPlayer2, INPUT_PULLUP);
- pinMode(ButtonPlayer1, INPUT_PULLUP);
- // This tells the button that it's going to receive a pulse and that is should detect that
- pinMode(Green, OUTPUT);
- pinMode(Red, OUTPUT);
- pinMode(buzzerPin, OUTPUT);
- // this tells the Leds that it's going to wait for power to be given to it
- }
- void loop() {
- WaitToStartGame();
- while (digitalRead(ButtonPlayer1) == LOW && digitalRead(ButtonPlayer2) == LOW)
- {} // What this does is it is stuck in a loop that does nothing until one of the buttons is let go
- // The following code checks to see which person let goed of their button
- if (digitalRead(ButtonPlayer1) == HIGH) { // this checks if it was the red player that let go
- for(int i = 0; i<3; i++){ // Does the following code 3 times
- digitalWrite(buzzerPin, HIGH); // rings the buzzer
- digitalWrite(Red, LOW);// flashes the light
- delay(400);
- digitalWrite(buzzerPin, LOW);
- digitalWrite(Red, HIGH);
- delay(400);
- }
- digitalWrite(Green, LOW);
- }
- else if (digitalRead(ButtonPlayer2) == HIGH) { // checks if the green player was the one that let go
- for(int i = 0; i<3; i++){
- digitalWrite(buzzerPin, HIGH);
- digitalWrite(Green, LOW);
- delay(400);
- digitalWrite(buzzerPin, LOW);
- digitalWrite(Green, HIGH);
- delay(400);
- }
- digitalWrite(Red, LOW);
- }
- digitalWrite(Red, LOW); // This resets the game turning both players lights off
- digitalWrite(Green, LOW);
- delay(2000); // this delay is here to avoid issues of starting a new game too quickly.
- }
- void WaitToStartGame() {
- while(digitalRead(ButtonPlayer1) == HIGH || digitalRead(ButtonPlayer2) == HIGH) {}
- // What the above function does is it waits for both buttons to be pressed
- //if only one or no buttons are pressed the function will continue to do nothing until you do so
- digitalWrite(Green, HIGH);
- digitalWrite(Red, HIGH);
- //this turns on both lights signifying that the game has started
- }
How this works is that the given code outlines the pin assignments and setup for a game involving two players. The pins are assigned to buttons for each player, LEDs for indicating player turns, and a buzzer for sound output. In the setup, the pins are defined as input or output. The main loop of the game involves waiting for both players to initiate the game, and then the game starts when either player presses their button. Depending on which player pressed their button, the corresponding LED will blink, and the opposing LED will turn off. The game will loop until both buttons are released and the process of waiting for both players to press their buttons will start again.
Finallizing Everything
Once finished, make sure that you upload the code through the Arduino with a laptop and play the game. Enjoy!!!
Our Source/ Citation...
Here is a reference of our source from where we got it from...
Matthew. (n.d.). I Created The Mr. Beast Burger “Happy Meal” Toy (Finger On The Circle). YouTube. https://www.youtube.com/watch?v=mtZU0JPwGpw&t=289s&pp=ygUjdW5uZWNlc3NhcnkgaW52ZW50aW9ucyBtcmJlYXN0IGdhbWU%3D