#include <LiquidCrystal_I2C.h>
#define B1_PIN 13
#define B2_PIN 12
#define I2C_ADDR 0x27
#define LCD_COLUMNS 20
#define LCD_LINES 4
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
void setup() {
// Init
pinMode(B1_PIN, INPUT_PULLUP);
pinMode(B2_PIN, INPUT_PULLUP);
lcd.init();
lcd.backlight();
// Print something
lcd.setCursor(0, 0);
lcd.print("you arrive home");
lcd.setCursor(0, 1);
lcd.print("see the door ajar");
lcd.setCursor(0, 3);
lcd.print("somthing is weierd");
// Show test for 5 seconds
delay(2000);
lcd.init();
// Print something
lcd.setCursor(0, 0);
lcd.print("Do you:");
lcd.setCursor(0, 1);
lcd.print("1, Enter the house?");
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 reply to users 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
if(userInput == 1)
{
lcd.setCursor(0, 0);
lcd.print("you went inside");
lcd.setCursor(0, 1);
lcd.print("and got eaten by");
lcd.setCursor(0, 2);
lcd.print("a monster");
lcd.setCursor(0, 3);
lcd.print("GAME OVER");
}
else
{
// Print something
lcd.setCursor(0, 0);
lcd.print("you call for help");
lcd.setCursor(0, 1);
lcd.print("a man with a knife");
lcd.setCursor(0, 2);
lcd.print("coming to you");
// Show test for 5 seconds
delay(2000);
lcd.init();
// Print something
lcd.setCursor(0, 0);
lcd.print("SCREAM!! Do you:");
lcd.setCursor(0, 1);
lcd.print("1, run to the forest");
lcd.setCursor(0, 2);
lcd.print("2, go to the beach");
lcd.setCursor(0, 3);
lcd.print("Press button 1 or 2");
waitingForInput = true;
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 in userInput
if (userInput == 1)
{
// Print something
lcd.setCursor(0, 0);
lcd.print("You waited for police");
lcd.setCursor(0, 1);
lcd.print("You are safe, but a");
lcd.setCursor(0, 2);
lcd.print("lion ate your hamster");
lcd.setCursor(0, 3);
lcd.print("Game Over !!!!");
}
else
{
// Print something
lcd.setCursor(0, 0);
lcd.print("You investigated and");
lcd.setCursor(0, 1);
lcd.print("everything is ok");
lcd.setCursor(0, 3);
lcd.print("Game Over");
}
}
void loop() {
// put your main code here, to run repeatedly:
}