Finger- On- The- Button

by DanMath321 in Circuits > Arduino

115 Views, 2 Favorites, 0 Comments

Finger- On- The- Button

Screenshot 2024-09-19 113926.png
Brilliant Duup.png

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

71p-M3sPhhL.jpg
Screen+Shot+2021-02-17+at+18.00.37.png
6177CmL0Q1L.jpg
61cbjhBLaXL.jpg
images.jpeg
0J11597.1200.jpg
images (7).jpeg
  1. 10 Wires,
  2. 2 Push- Button 
  3. 1 buzzer, 
  4. 1 breadboard, 
  5. 1 Arduino UNO, 
  6. 1 resistor, 
  7. 1 USB cable, 
  8. And 1 computer with an Arduino IDE.

Assembling the Right Components

Brilliant Duup.png

With the Arduino and Breadboard I have 10 wires, two buttons, two LEDs, two 330s resistors, and a speaker.

  1. 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.
  2. Then the light- blue wire connected to the Arduino, in the spot labeled: GND, is in the negative column of the breadboard.
  3. Connect the two resistors to the negative column. Then place the LEDs where those resistors are.
  4. Connect speaker to Breadboard, red wire to Arduino 2, black wire to Breadboard negative column.
  5. Connect the buttons to the same row as 13, and Tx>1.
  6. Then wire buttons to another negative column, and connect that negative column to the other.
  7. Then plug in the Arduino C++ code.


If you would like a reference, here it is...

https://www.tinkercad.com/things/4A4j3m7MGaj-brilliant-duup/editel?sharecode=kOjcmtU-iPkB7mtJ9cRY8_inDQo5Ythsy8wzytie7ZE

Code

  1. Here’s the code for our project once finished with installation…// Pin assignments
  2. // Changing the numbers changes which pin holes you use
  3. int ButtonPlayer2 = 1; // Green Player  
  4. int ButtonPlayer1 = 13; // Red Player
  5. int Green = 11; // Green Light
  6. int Red = 12;// Red Light
  7. int buzzerPin = 2; // Buzzer

  8. void setup() {
  9.   pinMode(ButtonPlayer2, INPUT_PULLUP);
  10.   pinMode(ButtonPlayer1, INPUT_PULLUP);
  11.    // This tells the button that it's going to receive a pulse and that is should detect that
  12.   pinMode(Green, OUTPUT);
  13.   pinMode(Red, OUTPUT);
  14.   pinMode(buzzerPin, OUTPUT);
  15. // this tells the Leds that it's going to wait for power to be given to it
  16.  
  17. }

  18. void loop() {
  19.   WaitToStartGame();

  20.     while (digitalRead(ButtonPlayer1) == LOW && digitalRead(ButtonPlayer2) == LOW)
  21.   {} // What this does is it is stuck in a loop that does nothing until one of the buttons is let go
  22. // The following code checks to see which person let goed of their button
  23.   if (digitalRead(ButtonPlayer1) == HIGH) { // this checks if it was the red player that let go
  24.     for(int i = 0; i<3; i++){ // Does the following code 3 times
  25.       digitalWrite(buzzerPin, HIGH); // rings the buzzer
  26.       digitalWrite(Red, LOW);// flashes the light
  27.       delay(400);
  28.       digitalWrite(buzzerPin, LOW);
  29.       digitalWrite(Red, HIGH);
  30.       delay(400);
  31.     }
  32.      digitalWrite(Green, LOW);
  33.   }
  34.   else if (digitalRead(ButtonPlayer2) == HIGH) { // checks if the green player was the one that let go
  35.     for(int i = 0; i<3; i++){
  36.       digitalWrite(buzzerPin, HIGH);
  37.       digitalWrite(Green, LOW);
  38.       delay(400);
  39.       digitalWrite(buzzerPin, LOW);
  40.       digitalWrite(Green, HIGH);
  41.       delay(400);
  42.     }
  43.      digitalWrite(Red, LOW);
  44.   }

  45.   digitalWrite(Red, LOW); // This resets the game turning both players lights off
  46.   digitalWrite(Green, LOW);
  47.   delay(2000); // this delay is here to avoid issues of starting a new game too quickly.
  48. }
  49.   void WaitToStartGame() {
  50.     while(digitalRead(ButtonPlayer1) == HIGH || digitalRead(ButtonPlayer2) == HIGH) {}
  51.     // What the above function does is it waits for both buttons to be pressed
  52.     //if only one or no buttons are pressed the function will continue to do nothing until you do so
  53.     digitalWrite(Green, HIGH);
  54.     digitalWrite(Red, HIGH);
  55.     //this turns on both lights signifying that the game has started
  56.   }

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