Introduction: Simple Arduino LCD Game!

Hello World! Pure Carbon here and today I will be showing you how to make an extremely simple game that can be played on an LCD Button Shield for Arduino. Unfortunately its not actually a game because all you will be able to do is make a character walk back and forth using the buttons on the shield and in order for something to be considered a game in my opinion there need to be some sort of objective or goal to work towards. The sketch that I created was modified from the example code that can be found here. I made a video going through the code where I explain what everything does, so enjoy you silly humans!

Video:

important announcement: I was recently sent some really neat items from this cool website called 1 Byone.com which I will be doing a review on in the future, so be sure to keep an eye out for that. This website also sells tons of really cool things like phone accessories, speakers, stage lights, as well as many other really cool things. So be sure to check that out!

Thank you for all your support, and tips to help me improve my Instructables. Without you guys I wouldn't be doing this right now, you can expect many more Instructables in the future so don't forget to follow me and/or favorite this Instructable. If you have any question or concerns then be sure to comment, or if you just want tell me how awesome this is, that's fine too! Here it is, hope you enjoy it and once again thank you.

Check me out on: YouTube: https://www.youtube.com/channel/UCp1Iy_qqZl-TBWrw...

Channel ad:

Facebook: https://www.facebook.com/Pure-Carbon-398550910296...

Twitter: https://www.facebook.com/Pure-Carbon-398550910296...

Also Support me on Patreon where contributors get early access to all the videos I make along with free PDF downloads of all my upcoming Instructables: https://www.facebook.com/Pure-Carbon-398550910296...

Step 1: Materials

Here are the items you will need to do this project:

Step 2:

Now copy and paste the following code into the Arduino IDE, plug in the Arduino to your computer, adjust the settings (board, port, etc.) And upload the sketch to the board. Keep in mind there my be a few things that you need to adjust like the spacing. If you have any problems then leave a comment down below an I will do my best to help you out.

///////////////////////////////////////////////////////////////////////////////////////////////////

#include

LiquidCrystal lcd(8, 13, 9, 4, 5, 6, 7);

int lcd_key = 0;

int adc_key_in = 0;

#define btnRIGHT 0

#define btnLEFT 3

#define btnNONE 5

int read_LCD_buttons()

{ adc_key_in = analogRead(0);

if (adc_key_in < 50) return btnRIGHT;

if (adc_key_in < 650) return btnLEFT;

return btnNONE;

}

byte mario1 [8] = {

B01110,

B11111,

B01110,

B11111,

B01110,

B01010,

B10001,

};

byte mario2 [8] = {

B01110,

B11111,

B01110,

B11111,

B01110,

B00100,

B00100,

};

void marioStand (){

lcd.write((byte)0);

}

void marioRun (){

lcd.setCursor(3,1);

lcd.write((byte)0);

delay(300);

lcd.setCursor(3,1);

lcd.write((byte)1);

delay(300);

}

void setup() {

lcd.begin(16, 2);

lcd.createChar(0,mario1);

lcd.createChar(1,mario2);

}

void loop() {

lcd.setCursor(3,1);

lcd_key = read_LCD_buttons();

switch (lcd_key)

{

case btnRIGHT:

{

marioRun();

lcd.scrollDisplayRight();

break;

}

case btnLEFT:

{

marioRun();

lcd.scrollDisplayLeft();

break;

}

default:

marioStand();

break;

}

}

Step 3:

Now you're done! To control your character press either the button labeled left or right and you should see your character move one space for every time you press one of those buttons.

Like I said earlier if you have any comments, questions, or concerns then leave them in the comment section down below and I will be more than happy to respond. If you like this then please be sure to subscribe to me here and to my YouTube channel for more awesome content like this. there is link on my page to it so be sure to check it out. Thank you for checking out my Instructable and be sure to favorite it, once again thank you.

Comments

author
Sembot (author)2017-08-04

Fantastic, I have a question: Is it possible if you press the right button that instead of Mario1 and then Mario2 in the same box, Mario2 is placed in the next box, but I do not know how to do this programming can someone help me with that please

Kind Regards

author
angadsachdeva (author)2016-05-18

i love eshaa

author

k

author
angadsachdeva (author)2016-05-18

which buttons are u using

author

The right and left buttons.

author
trevorman33 (author)2016-04-14

I fixed the first one now it gives me this

Arduino: 1.6.8 (Windows 7), Board: "Arduino/Genuino Uno"

Build options changed, rebuilding all

C:\Users\Rittel\AppData\Local\Temp\arduino_modified_sketch_217991\HelloWorld.ino:3:28: warning: extra tokens at end of #include directive [enabled by default]

#include "LiquidCrystal.h" lcd(8, 13, 9, 4, 5, 6, 7);

^

C:\Users\Rittel\AppData\Local\Temp\arduino_modified_sketch_217991\HelloWorld.ino: In function 'void marioStand()':

HelloWorld:65: error: 'lcd' was not declared in this scope

lcd.write((byte)0);

^

C:\Users\Rittel\AppData\Local\Temp\arduino_modified_sketch_217991\HelloWorld.ino: In function 'void marioRun()':

HelloWorld:71: error: 'lcd' was not declared in this scope

lcd.setCursor(3, 1);

^

C:\Users\Rittel\AppData\Local\Temp\arduino_modified_sketch_217991\HelloWorld.ino: In function 'void setup()':

HelloWorld:87: error: 'lcd' was not declared in this scope

lcd.begin(16, 2);

^

C:\Users\Rittel\AppData\Local\Temp\arduino_modified_sketch_217991\HelloWorld.ino: In function 'void loop()':

HelloWorld:97: error: 'lcd' was not declared in this scope

lcd.setCursor(3, 1);

^

exit status 1

'lcd' was not declared in this scope

This report would have more information with

"Show verbose output during compilation"

option enabled in File -> Preferences.

author
trevorman33 (author)2016-04-14

It gives me this error

Arduino: 1.6.8 (Windows 7), Board: "Arduino/Genuino Uno"

Build options changed, rebuilding all

HelloWorld:3: error: #include expects "FILENAME" or <FILENAME>

#include

^

exit status 1

#include expects "FILENAME" or <FILENAME>

This report would have more information with

"Show verbose output during compilation"

option enabled in File -> Preferences.

author
mymeep (author)2016-02-29

what is the code

author
IsaacPierce (author)2016-02-14

How do you create your own character??

author
moo06 (author)IsaacPierce2016-02-17

if you make the charecter

https://omerk.github.io/lcdchargen/ then you replace the one you want to replace and rename it to what it originaly was in the code

author
IsaacPierce (author)moo062016-02-17

thank you!!

and your instructable is cool!

About This Instructable

11,691views

101favorites

License:

Bio: My whole life I have thought of ways to make things that you can only go out and buy, follow me and I will teach ... More »
More by Pure Carbon:DIY World Map Computer Decal Worlds First Remote Control Human Through the InternetSimple Arduino LCD Game!
Add instructable to: