Pumpkin Arcade Game

by G202_2122_MMJA in Circuits > Arduino

212 Views, 1 Favorites, 0 Comments

Pumpkin Arcade Game

DSC_0208.JPG
DSC_0202.JPG
DSC_0179.JPG
DSC_0241.JPG
DSC_0224.JPG
DSC_0247.JPG
DSC_0218.JPG
DSC_0238.JPG
DSC_0233.JPG

Hey! We are Anna Juanicó, Maíta Gomila and MªJesús de Pouplana and we have done an interactive game inspired by the old arcade that we all love.

The game lasts 30 seconds and consists of a random pumpkin (which has a button on the base) that you have to press so that it turns off and the next random one lights up. This adds points to your score that you can see on the screen. The faster you go, the more points you can earn. If you make the wrong pumpkin, points are deducted and an error sound is heard. In addition, you can also see the record of previous games on the screen (as long as you do not turn off the Arduino, otherwise all the code will be reset and the point memory will be lost).


Here you have some pictures and a video where you can see the final result and how it works.


This project has been carried out for the subject of Academic Uses and English Terminology, taught at ELISAVA, as a result of the commission presented by it.

Supplies

electronic parts-01-2-2-min.png
comprar-placa-protoboard-mediana-400-contactos-precio-oferta.jpg
tools and materials-02.png

To carry out this project we have used the following electronic components, tools and materials:

Electronic parts:

1- Resistors x9 (220Ω)

2- LEDS x9

3- LCD and LCD adapter (i2C)

4- Wire x 5m

5- Arduino Mega

6- Buzzer

7- Buttons x10

8- Battery

9- Protoboard (optional)


Tools and Materials:

1- Glue gun

2- Drill

3- Soldering iron and tin

4- Pumpkins x9 (7*7cm)

5- Eva rubber A4

6- White glue

7- Paint

8- Wood dm (140*60*0,4cm)

*The electronics are essential for the project to work, as well as the pumpkins. The other materials can be substituted by similar alternatives.

Fritzing Scheme

Mesa de trabajo 1.png
gifinal.gif
gif2.gif
gif3.gif
DSC_0321.jpg
gif55.gif
gif249.gif

Fritzing is an open-source initiative to design the electronics hardware, to support designers and artists to move from experimenting with a prototype to building a more permanent circuit. In our case we have use it to simulate the circuit that we are using for the game. You can see the key at the lower left corner to understand the connections between components according to the colors.

To check if the hardware works correctly, it is necessary to test the components one by one with a more basic code. We have used examples from the Arduino library ("Blink" for LEDS and "Button" for buttons, *). The electrical connections of these tests are what you can see in the GIFs and pictures.

To join the different components to the Arduino, we have soldered them to the cable and to the resistor if necessary. Once we have the cable soldered to the components, to connect it to the Arduino we use some Dupont pins to be able to make the male-female connection that Arduino has. After this, we have protected the cables with electrical tape.


To use the display without using 16 pins it is necessary to connect an i2C adapter. For the correct functioning of this we use the LiquidCrystal_i2c library. You can download it here:

https://www.arduinolibraries.info/libraries/liquid-crystal-i2-c


*For testing the buzzer we have created a basic code attached below.

Downloads

Flow Diagram & Arduino Code

FlowDiagram.png

As you can see, we have made a flow diagram from which we have written the code. This diagram has helped us to organize the information and, in this way, write the code in a more orderly and easier way.


CODE WITH COMMENTS:

#include <LiquidCrystal_I2C.h> //We add the libraries for the LCD screen with your i2c adapter

#include <Wire.h>


#define pinBuzzer 12 //Buzzer pin

#define NUMCAL 9 //number of pumpkins

int led[NUMCAL] = {32, 34, 36, 38, 40, 42, 44, 46, 48}; // LEDs pins

int botton[NUMCAL] = {33, 35, 37, 39, 41, 43, 45, 47, 49}; //Buttons pins

int lastState[NUMCAL] = {HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH}; //Last state of the buttons


#define bottonStart 24 // Start Button pin

#define Buzzer 51 //Buzzer pin


int score = 0; //start variable score

int timer_max = 30000; //time of the game

int record = 0; //start variable record


int currentLed; //actual high led

int lastRoundButton = -1; //variable used as a memory of the last button pressed


bool gameStarted = false; //state of the game

unsigned long t; //moment of time when you start the game

bool play = false; //state of the`play


LiquidCrystal_I2C lcd(0x27, 16, 2); //definition of LCD



void setup() {

 Serial.begin(9600);  //start the serial


 for (int i = 0; NUMCAL > i; i++) //define all the elements of the button array as output

 {

 {

  pinMode(led[i], OUTPUT); 

 }


 for (int j = 0; NUMCAL > j; j++) //define all the elements of the button array as input pullup

 {

  pinMode(botton[j], INPUT_PULLUP);

 }


 pinMode(bottonStart , INPUT_PULLUP); //definition of the buttonStart as an input pullup

  

 lcd.init(); // initialize the LCD

 lcd.backlight(); //turn on the backlight of the LCD.


 lcd.print("UATEA HALLOWEEN"); 

 lcd.setCursor(0, 1); // place the cursor in the first position of the second line (column:0; line:1) 

 lcd.print("ANNA, MAITA y MJ"); 

}


void loop() {

 if (digitalRead(bottonStart) == LOW && !gameStarted) // condition to know when to start the game

 {

  gameStarted = true; // game state variable initialization 

  lcd.clear(); // clean the information of the LCD screen

  lcd.print("START!");

  lcd.setCursor(0, 1);

  lcd.print("Last record ");

  lcd.print(record); //show the last record 

  delay(2000); // time between button start pressed and when the game starts

  t = millis(); //definition of the time that starts the game (start button pressed+2s)

  currentLed = newLed(-1);

  lcd.clear();

 }


 if (gameStarted && millis() - t < timer_max) //condition to know if the game has started and the time is less than 30s (timer_max)

 {

  int times = (30000 - (millis() - t)) / 1000; //countdown from timer_max to 0s

  lcd.setCursor(0, 0);

  lcd.print("Tiempo ");

  if (times < 10) //correction of the countdown when there is only one digit 

  {

   lcd.setCursor(8, 0);

   lcd.print(" ");

   lcd.setCursor(7, 0);

  }

  lcd.print(times);

  lcd.setCursor(0, 1); 

  lcd.print("Score "); 

  lcd.print(score); //show the actualized score


  digitalWrite(led[currentLed], HIGH); //turn on a random LED


  int buttonRead = readButtons(); //call the function readButton to create a new random number

  if (buttonRead >= 0) //to control when the first random LED is turned on.

  {

   if (buttonRead == currentLed) //condition to know if you press the correct button

   {

    digitalWrite(led[currentLed], LOW); //turn off the LED

    score++; // increase the score (+1)

    lastRoundButton = currentLed; // update the variable lastRoundButton

    currentLed = newLed(currentLed); // create a new random number

   }

   else if (buttonRead != currentLed && buttonRead != lastRoundButton) //condition to know if a wrong button has been pressed

   {

    digitalWrite(led[currentLed], LOW); //turn off the led

    score--; // decrease the score (-1)

    tone(pinBuzzer, 200); //to make the error sound with the buzzer 

    delay(500); //time that the sound is on

    noTone(pinBuzzer); //stop the sound

   }

  }

  delay(100); //used to improve LCD performance

 }

 else if (gameStarted && millis() - t > timer_max) //condition to know if the play has finished 

 {

  for (int h = 0; NUMCAL > h; h++)

  {

   digitalWrite(led[h], LOW); //turn off all the LEDs 

  }


  lcd.clear();

  if (score > record) //condition to know if the user has made a record

  {

   record = score; //update the variable record with the newest score 

   lcd.print("NEW RECORD!");

   lcd.setCursor(0, 1); 

   lcd.print(score); //print final score in the LCD

  }


  else //no new record

  {

   lcd.print("Score");

   lcd.setCursor(0, 1); 

   lcd.print(score); 

  }

  delay(5000);

  lcd.clear();

  lcd.print("Press start to"); //message that indicates how to start a new play

  lcd.setCursor(0, 1); 

  lcd.print("play again");

  gameStarted = false; //finish the play

  score = 0; //update the score (restart the variable)

 }

}


int newLed(int current) //function to create random number without repeating the last one

{

 int newLed = random(0, NUMCAL);

 while (current == newLed)

 {

  newLed = random(0, NUMCAL);

 }

 return newLed;

}


int readButtons () //function to know which button has been pressed

{

 int newReading;

 for (int i = 0; i < NUMCAL; i++)

 {

  newReading = digitalRead(botton[i]);

  if (lastState[i] == HIGH && newReading == LOW)

  {

   lastState[i] = newReading;

   Serial.print("Button pressed ");

   Serial.println(i);

   return i;

  }

  lastState[i] = newReading;

 }

 return -1;

}


*Something that may help you is to add numbers to the cables to make it easier to identify each one since if you make a mistake when putting the cables on the pins the code will not work.


The Arduino file is attached just below.

How to Build It

1635942979648.jpg
1635942980063.jpg
1635942979498.jpg
1635942980002.jpg
1635942979471.jpg
1635942979430.jpg
DSC_0223.JPG
1635942979485.jpg
DSC_0219.JPG
1635942979704.jpg
DSC_0220.JPG
1635942979415.jpg
1635942979399.jpg
1635942979689.jpg
DSC_0252.JPG
DSC_0249.JPG
1635942979868.jpg

To assemble the halloween arcade machine we have followed the following steps:

  1. Draw the measurements on the cardboard or wood according to the tools available for the cutting process.
  2. In our case we have drawn the plans in Illustrator to cut the wood with a laser printer.
  3. Drill holes for the 9 pumpkins buttons, the 'START' button and the LCD screen.
  4. Make holes (diameter 3mm) to the pumpkins and close to the button holes to be able to pass the two wires that connect the LEDs with the arduino.
  5. Apply a primer coat (if wood is used) and paint in the desired color.
  6. In our case, the color black has been used
  7. Glue the caps of the pumpkins and the sides of the structure.
  8. Fit the upper pieces and glue them to achieve a rigid structure, although not completely closed.
  9. Put the buttons and the LDC screen in place.
  10. Assemble the electronic circuit.
  11. Connect the LEDs to the resistors through the positive leg (long) and to the even pins that go from 30-46 (both included) through the negative leg (short). The LEDs and resistors are located inside the pumpkins, so the cable must be inserted into the structure.
  12. Connect the buttons to the ground and to the odd pins that go from 31-47 (both included).
  13. Connect the start button to the ground and to pin 53 of the arduino MEGA.
  14. Connect the buzzer to the ground and to pin 51.
  15. Solder the adapter to the LCD screen.
  16. Connect the LCD screen through the adapter to the ground, to the 5V and to the SCL and SDA pins.
  17. Finish gluing the structure (base and rear covers) of the set with white glue.
  18. Glue the pumpkins with silicone to the top of the buttons.
  19. Decorate as you like!


*You can see some pictures of the process here. Also, we have attached the illustrator with the measurements of the wood that we used to cut it with the laser machine and a video of the laser machine.