Google T-rex Game on LCD

by 704292 in Circuits > Arduino

229 Views, 1 Favorites, 0 Comments

Google T-rex Game on LCD

google idnodsaur.png

In this intractable, I will be showing you how to make the Google T-rex game on a LCD.

Supplies

image_123986672.JPG

Connect Components to Breadboard

step 1111.png

The first step you'd want to take is to connect all of the components to the breadboard. This would include the RGB led, Buzzer, Slide Switch, and the Push Button. You can connect these anywhere on thee breadboard, copying the. image above is not necessary. You will have to connect them to the power and ground rails on the side of the bread board as well, make sure to connect them to the right rail as if you don't it will not work properly and may even damage your parts.

Connect Components to Arduino

stpe 22.png

Next, you will have to connect the components to the Arduino. You can connect each component to whichever pin you decide, just make sure to change the code accordingly. You could also connect the breadboard to the GND and 5V pins right now as well.

Connect LCD

step 303.png

Now, you will need to connect the LCD. The GND pin will be connected to the ground rail, the VCC pin to the power rail, the SDA to pin A4 on the Arduino, and the SCL to pin A5 on the Arduino.

Step 1 of Code

The first step of the code is to declare all of components, create the bytes for the Dino. and tree, and declare the LCD. Remember to download the LiquidCrystal I2C library, otherwise it will not work.


#include <Wire.h>

#include <LiquidCrystal_I2C.h>


LiquidCrystal_I2C lcd(0x27, 16, 2);


byte dino[8] = {

 B11110,

 B01011,

 B01100,

 B01111,

 B10110,

 B11111,

 B01110,

 B00111,

};


byte Tree[8] = {

 0b00010,

 0b00010,

 0b00110,

 0b10110,

 0b10110,

 0b11111,

 0b00110,

 0b00110

};


int onOFF = 10;

int Button = 8;

int buzzer = 9;

int Red = 5;

int Green = 6;

int Blue = 7;


Step 2 of Code

Next, you will need fill out the void setup function. This is where you. need to declare the pin mode as either input or output for all the components and setup the backlight for the LCD.


void setup()

{

 lcd.init();

 lcd.backlight();

 pinMode(Button, INPUT);

 pinMode(onOFF, INPUT);

 pinMode(buzzer, OUTPUT);

 pinMode(redPin, OUTPUT);

 pinMode(greenPin, OUTPUT);

 pinMode(bluePin, OUTPUT);

}

Step 3 of Code

Next, you will need to create the void setColor function. This function will help you to change the colour of the RGB led

to whichever colour you may want them to be.

void setColor(int red, int green, int blue)

{

 red = 255 - red;

 green = 255 - green;

 blue = 255 - blue;


 analogWrite(redPin, red);

 analogWrite(greenPin, green);

 analogWrite(bluePin, blue);

}

Step 4 of Code

For the final step of the code, you will be creating the void loop function. This function Is where the main parts of the code that make the game work will be contained.


void loop()

{

 lcd.createChar(3, dino);

 lcd.createChar(4, Tree);




 if (digitalRead(onOFF) == HIGH) {


  if ((digitalRead(Button) == HIGH)) {

   tone(buzzer, 700, 100);

   setColor(0, 0, 255);

   lcd.setCursor(2, 1);

   lcd.print(" ");

   delay(1);



   lcd.setCursor(2, 0);

   lcd.write(3);

   delay(500);

   lcd.setCursor(2, 0);

   lcd.print(" ");

   lcd.setCursor(2, 1 );

   lcd.setCursor(2, 1);

   lcd.write(3);

   delay(500);

  }

  else {



   setColor(0, 0, 150);

   lcd.setCursor(2, 1);

   lcd.write(3);

   delay(10);




  }

 }


 else {

  setColor(255, 0, 0);

  lcd.setCursor(2, 1);

  lcd.print(" ");

  lcd.setCursor(15, 1);

  lcd.print(" ");

  lcd.setCursor(3, 0);

  lcd.print("Press Start");

 }

}

Upload Code to Arduino

Lastly, you will need to connect the Arduino whatever you wrote the code on and upload it to the Arduino, and that's it! You have made your very own version of the T-rex game by Google.