#define B1_PIN 13
#define B2_PIN 12
//Defined buttons as B1_PIN and B2_PIN
#include <LiquidCrystal_I2C.h>
//Set so we don't have to included a lot of code
LiquidCrystal_I2C lcd(0x27, 20, 4);
//Sets the rows into collums
void setup()
{
// put your setup code here, to run once:
pinMode(B1_PIN, INPUT_PULLUP);
pinMode(B2_PIN, INPUT_PULLUP);
//INPUT_PULLUP insures the code works
lcd.init();
lcd.backlight();
//Lighting up the screen
lcd.setCursor(0,0);
//Determains the position of the cursor
lcd.print("Your feet hit the");
lcd.setCursor(0,1);
lcd.print("soft, shiny sand");
lcd.setCursor(0,2);
lcd.print("although You start to relise");
lcd.setCursor(0,3);
lcd.print("Something is amiss");
//shows text for 5 seconds before making it disapear
delay(5000);
lcd.init();
lcd.setCursor(0,0);
lcd.print("Do you:");
lcd.setCursor(0,1);
lcd.print("1. go back home");
lcd.setCursor(0,2);
lcd.print("2. Call for help");
lcd.setCursor(0,3);
lcd.print("Press button 1 or 2");
int waitingForInput = true;
int userInput = 0; //Will store the user input
while (waitingForInput)
{
int b1State = digitalRead(B1_PIN);
int b2State = digitalRead(B2_PIN);
if (b1State == LOW)
{
waitingForInput = false;
userInput = 1;
}
if (b2State == LOW)
{
waitingForInput = false;
userInput = 2;
}
}
lcd.init(); //clear the screen
//provide new game text and choice based on userInput
if (userInput == 2)
{
lcd.print("You Ignored and");
lcd.setCursor(0,1);
lcd.print("went on with your day");
lcd.setCursor(0,2);
lcd.print("passed out and died");
lcd.setCursor(0,3);
lcd.print("GAME OVER!!");
}
else
{
lcd.print("You hope back in");
lcd.setCursor(0,1);
lcd.print("your car and");
lcd.setCursor(0,2);
lcd.print("leave the beach");
lcd.setCursor(0,3);
lcd.print("only to get");
lcd.setCursor(0,4);
lcd.print("hit by a heat wave");
delay(2000);
lcd.setCursor(0,0);
lcd.print("Do you:");
lcd.setCursor(0,1);
lcd.print("1.Investigate what happened");
lcd.setCursor(0,2);
lcd.print("2. Call for assistance");
lcd.setCursor(0,3);
lcd.print("Press button 1 or 2");
int waitingForInput = true;
int userInput = 0; //Will store the user input
while (waitingForInput)
{
int b1State = digitalRead(B1_PIN);
int b2State = digitalRead(B2_PIN);
if (b1State == LOW)
{
waitingForInput = false;
userInput = 1;
}
if (b2State == LOW)
{
waitingForInput = false;
userInput = 2;
}
lcd.init(); //clear the screen
//provide new game text and choice based on userInput
if (userInput == 1)
{
lcd.print("You turn corner");
lcd.setCursor(0,1);
lcd.print("by coner ");
lcd.setCursor(0,2);
lcd.print("");
lcd.setCursor(0,3);
lcd.print("");
}
else
{
lcd.print("");
lcd.setCursor(0,1);
lcd.print("");
lcd.setCursor(0,2);
lcd.print("");
lcd.setCursor(0,3);
lcd.print("");
lcd.setCursor(0,4);
lcd.print("");
delay(2000);
lcd.setCursor(0,0);
lcd.print("Do you:");
lcd.setCursor(0,1);
lcd.print("1.");
lcd.setCursor(0,2);
lcd.print("2.");
lcd.setCursor(0,3);
lcd.print("Press button 1 or 2");
int waitingForInput = true;
int userInput = 0; //Will store the user input
while (waitingForInput)
{
int b1State = digitalRead(B1_PIN);
int b2State = digitalRead(B2_PIN);
if (b1State == LOW)
{
waitingForInput = false;
userInput = 1;
}
if (b2State == LOW)
{
waitingForInput = false;
userInput = 2;
}
lcd.init(); //clear the screen
//provide new game text and choice based on userInput
if (userInput == 2)
{
lcd.print("");
lcd.setCursor(0,1);
lcd.print("");
lcd.setCursor(0,2);
lcd.print("");
lcd.setCursor(0,3);
lcd.print("");
}
else
{
lcd.print("");
lcd.setCursor(0,1);
lcd.print("");
lcd.setCursor(0,2);
lcd.print("");
lcd.setCursor(0,3);
lcd.print("");
lcd.setCursor(0,4);
lcd.print("");
delay(2000);
lcd.setCursor(0,0);
lcd.print("Do you:");
lcd.setCursor(0,1);
lcd.print("1.");
lcd.setCursor(0,2);
lcd.print("2.");
lcd.setCursor(0,3);
lcd.print("Press button 1 or 2");
}