Hi
I'm rather new to coding and new to this forum. After I tried some basic projects from the starting kit I tried something on my own.
I used an LCD and 2 buttons for the input. They are working if I use another, simpler project.
My idea is to have some flavour text on the LCD and then either press button A or button B. The decision should set the value for "level" new, so it shows new flavour text.
My problem is that it only goes until "A to open" and "B to run away" and no longer reacts to my buttons. without the level argument it worked so far.
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
// set up a constant for the tilt switch pin
const int B = 6;
const int A = 7;
int level = 1;
void setup() {
lcd.begin(16, 2);
pinMode(A, INPUT);
pinMode(B, INPUT);
lcd.print(" Welcome to the");
lcd.setCursor(0, 1);
lcd.print(" DUNGEON!");
delay (3000);
lcd.clear();
lcd.print("You see a large");
lcd.setCursor(0, 1);
lcd.print("wooden chest.");
delay (3000);
lcd.clear();
lcd.print("A to open");
lcd.setCursor(0, 1);
lcd.print("B to run away");
}
void loop() {
if ((B == HIGH) && (level == 1)) {
lcd.clear();
lcd.print("You go home and");
lcd.setCursor(0, 1);
lcd.print("live a good life");
delay (3000);
lcd.clear();
lcd.print(" THE");
lcd.setCursor(0, 1);
lcd.print(" END");
delay (45000);
}
if ((A == HIGH) && (level == 1)) {
lcd.clear();
lcd.print("You found a ");
lcd.setCursor(0, 1);
lcd.print("golden crown");
delay (3000);
lcd.clear();
lcd.print("do you wannt to");
lcd.setCursor(0, 1);
lcd.print("search for more?");
delay (3000);
level = 99;
}
if (level == 99) {
lcd.clear();
lcd.print("There was");
lcd.setCursor(0, 1);
lcd.print("nothing more.");
delay (3000);
lcd.clear();
lcd.print("");
lcd.setCursor(0, 1);
delay (3000);
lcd.print(" klack");
delay (3000);
lcd.clear();
lcd.print("");
lcd.setCursor(0, 1);
delay (3000);
lcd.print(" klack");
delay (3000);
lcd.clear();
lcd.print("KLACK");
lcd.setCursor(0, 1);
delay (3000);
lcd.print(" KLACK");
delay (3000);
level = 98;
}
if (level == 98) {
lcd.clear();
lcd.print("A to run away");
lcd.setCursor(0, 1);
lcd.print("B to face it");
delay (3000);
}
}
Thanks for your help and happy coding
Tom