Description
For this project we were asked to design a program that allowed an Arduino board to make a show. We were introduced to this project by being told that robots will take over the world, and we have to decide what the art will be when all humans are gone. We had a very open and free set of guidelines for this project, so we could do anything cool that we wanted to develop with the Arduino Board. Before we even got to making our project we had to learn about current and electricity in circuits. We had a packet that we worked on for weeks, and after we finished, we moved on to a breadboard exercise packet. This packet helped us understand how circuits work inside a breadboard, and started the basic understanding how an Arduino board works. Then we had to complete the task of making a light blink on a breadboard. After we completed it successfully, we started the Arduino/programming part. We worked for weeks on completing an art show, and it ended up being successful. We made a video game using the LCD display and buttons, that added a unique feature to the art show.
Our Code and Game Features
Our Game is based after the Google Dino-Run game that occurs when the internet goes out. In our game we have a Dino appearing on the left side of the screen and cactus' scrolling along from the right to the left. When you press the button on the Arduino board the Dino moves up to the coordinate (0,0) on the LCD. We added a section of code, so you cannot hold the button down, and if you try to cheat, you will die and the game will restart. The score consists of a timer and the only time the timer is shown is when you die. To start the game over again you have to press the reset button on the Arduino board. Here is the code:
#include <LiquidCrystal.h> //opening lcd library
#define BUTTON_PIN A5 //shows the button pin
#define MAX_CACTII 16 //shows how many cactus' there can be
int buttonState = 0;
//the location of the button if not pressed
int iCactus2 [MAX_CACTII] = {30, 35, 42, 47, 52, 59, 64, 70, 79, 81, 85, 97, 100, 106, 111, 120};
//one array of spawned cactus' and the numbers represent time
int icounter = 0;
int charLocation = 0;
//where the character starts
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);//the connections we used on the breadboard
byte Cacti[8] = {
B00000,
B00100,
B10100,
B11101,
B00111,
B00100,
B00100,
B00100
};
byte lizard[8] = {
B00110,
B00111,
B00111,
B10100,
B10110,
B11100,
B00100,
B00111
};
//these codes show where the lcd will display the blocks on each square (cactus and a lizard)
void setup() {//the code that is used only once
lcd.begin(16,2);// showing how big the lcd is (16 by 2)
lcd.createChar(0, lizard);
lcd.createChar(1, Cacti);
pinMode(BUTTON_PIN, INPUT);
}
void loop() {//the code that can be used more than once
buttonState = digitalRead(BUTTON_PIN);
delay(200);
lcd.clear();
icounter++;
if ((icounter%2) == 0){//this is the code for the jumping of the lizard. It shows that when the button is pressed it will move up one and the remainder when divided by two will do the other command.
if(buttonState == HIGH){
charLocation = 1;
lcd.setCursor(0, charLocation);
lcd.write(byte(0));
for(int k = 0; k < MAX_CACTII; k++)
{
iCactus2[k] = iCactus2 [k] -1;
if(iCactus2[k] <= 15){
lcd.setCursor(iCactus2[k]+1 , 1);
lcd.write(byte(1));
if(iCactus2[k] < 0) {
iCactus2[k] = 103;
}
}
}
}
else{
charLocation = 0;
lcd.setCursor(0, charLocation);
lcd.write(byte(0));
for(int k = 0; k < MAX_CACTII; k++)
{
iCactus2[k] = iCactus2 [k] -1;
iCactus2[k] + iCactus2 [k] -1;
if(iCactus2[k] <= 15){
lcd.setCursor(iCactus2[k] , 1);
lcd.write(byte(1));
if(iCactus2[k] < 0) {
iCactus2[k] = 103;
}
}
if (iCactus2[k] == 0 && charLocation == 0){
//this code says that if a cactus and a lizard are in the same space it will cancel out, therefore "killing" the lizard
lcd.clear();
lcd.setCursor(0,1);
lcd.write(byte(2));
delay(25);
lcd.clear();
lcd.setCursor(3,0);
lcd.print(" YOU ARE DIE ");
delay(2000);
lcd.clear();
lcd.print("Time Survived:");
lcd.setCursor(0,8);
lcd.print( millis() /1000);
delay(3000);
lcd.clear();
lcd.print(" Press Reset for");
lcd.setCursor(3,1);
lcd.print( "Another Game ");
delay(100000);
lcd.clear();
}
if (iCactus2[k] == 0 && charLocation == 1){
//this code says that if a cactus and a lizard are in the same space it will cancel out, therefore "killing" the lizard
lcd.clear();
lcd.setCursor(0,1);
lcd.write(byte(2));
delay(25);
lcd.clear();
lcd.setCursor(3,0);
lcd.print("YOU ARE DIE ");
delay(2000);
lcd.clear();
lcd.print("Time Survived:");
lcd.setCursor(0,8);
lcd.print( millis() /1000);
delay(3000);
lcd.clear();
lcd.print("Press Reset For");
lcd.setCursor(3,1);
lcd.print( "Another Game ");
delay(100000);
lcd.clear();
// the code for the end once the lizard dies. this code enables the lcd to display the words with a sligh delay between each one.
iCactus2[k] =103;
}
}
}
}
}
#include <LiquidCrystal.h> //opening lcd library
#define BUTTON_PIN A5 //shows the button pin
#define MAX_CACTII 16 //shows how many cactus' there can be
int buttonState = 0;
//the location of the button if not pressed
int iCactus2 [MAX_CACTII] = {30, 35, 42, 47, 52, 59, 64, 70, 79, 81, 85, 97, 100, 106, 111, 120};
//one array of spawned cactus' and the numbers represent time
int icounter = 0;
int charLocation = 0;
//where the character starts
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);//the connections we used on the breadboard
byte Cacti[8] = {
B00000,
B00100,
B10100,
B11101,
B00111,
B00100,
B00100,
B00100
};
byte lizard[8] = {
B00110,
B00111,
B00111,
B10100,
B10110,
B11100,
B00100,
B00111
};
//these codes show where the lcd will display the blocks on each square (cactus and a lizard)
void setup() {//the code that is used only once
lcd.begin(16,2);// showing how big the lcd is (16 by 2)
lcd.createChar(0, lizard);
lcd.createChar(1, Cacti);
pinMode(BUTTON_PIN, INPUT);
}
void loop() {//the code that can be used more than once
buttonState = digitalRead(BUTTON_PIN);
delay(200);
lcd.clear();
icounter++;
if ((icounter%2) == 0){//this is the code for the jumping of the lizard. It shows that when the button is pressed it will move up one and the remainder when divided by two will do the other command.
if(buttonState == HIGH){
charLocation = 1;
lcd.setCursor(0, charLocation);
lcd.write(byte(0));
for(int k = 0; k < MAX_CACTII; k++)
{
iCactus2[k] = iCactus2 [k] -1;
if(iCactus2[k] <= 15){
lcd.setCursor(iCactus2[k]+1 , 1);
lcd.write(byte(1));
if(iCactus2[k] < 0) {
iCactus2[k] = 103;
}
}
}
}
else{
charLocation = 0;
lcd.setCursor(0, charLocation);
lcd.write(byte(0));
for(int k = 0; k < MAX_CACTII; k++)
{
iCactus2[k] = iCactus2 [k] -1;
iCactus2[k] + iCactus2 [k] -1;
if(iCactus2[k] <= 15){
lcd.setCursor(iCactus2[k] , 1);
lcd.write(byte(1));
if(iCactus2[k] < 0) {
iCactus2[k] = 103;
}
}
if (iCactus2[k] == 0 && charLocation == 0){
//this code says that if a cactus and a lizard are in the same space it will cancel out, therefore "killing" the lizard
lcd.clear();
lcd.setCursor(0,1);
lcd.write(byte(2));
delay(25);
lcd.clear();
lcd.setCursor(3,0);
lcd.print(" YOU ARE DIE ");
delay(2000);
lcd.clear();
lcd.print("Time Survived:");
lcd.setCursor(0,8);
lcd.print( millis() /1000);
delay(3000);
lcd.clear();
lcd.print(" Press Reset for");
lcd.setCursor(3,1);
lcd.print( "Another Game ");
delay(100000);
lcd.clear();
}
if (iCactus2[k] == 0 && charLocation == 1){
//this code says that if a cactus and a lizard are in the same space it will cancel out, therefore "killing" the lizard
lcd.clear();
lcd.setCursor(0,1);
lcd.write(byte(2));
delay(25);
lcd.clear();
lcd.setCursor(3,0);
lcd.print("YOU ARE DIE ");
delay(2000);
lcd.clear();
lcd.print("Time Survived:");
lcd.setCursor(0,8);
lcd.print( millis() /1000);
delay(3000);
lcd.clear();
lcd.print("Press Reset For");
lcd.setCursor(3,1);
lcd.print( "Another Game ");
delay(100000);
lcd.clear();
// the code for the end once the lizard dies. this code enables the lcd to display the words with a sligh delay between each one.
iCactus2[k] =103;
}
}
}
}
}
Reflection
This project was one of the most successful and fun we have had all year. Justin and I worked together well, which allowed for a great end goal. Our time was well spent, and we took until the very last day to complete our project. Some bad things happened as well. For example, we did not know how to program very well, so we frequently asked for help. We ended up learning a lot, but it was interrupting other groups. Also, when my partner wasn't working with me on code, he felt he had nothing to do. In the future, I would want to have a project designed to be easier to cooperate on. Many good things happened over this project as well. For example, we worked together well and didn't argue which helped work ethic. Also, we learned a lot about coding and breadboards, so in the future we will have experience. The next good thing is our work ethic generally. I never left the computer, and was always trying to improve our product. Overall, this project was very fun and I hope the robots will spare us when they take over the world.