Hey,
I’m programming a choose your own adventure game with an LCD screen, and I have a few questions.
#1: I have two buttons that I want to toggle yes and no respectively, what code can I use to achieve this?
#2: Have I wired up the board correctly? (refer to the picture)
I’m using the Arduino Uno and the LCD screen that came in the starter kit, which you can view here
Here’s my code so far:
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int yesPin = 7;
const int noPin = 6;
int yesState = 0;
int noState = 0;
int yes = 0;
int no = 0;
int choice = 0;
void setup() {
pinMode(yesPin, INPUT);
pinMode(noPin, INPUT);
lcd.begin(16, 2);
lcd.print("The Trail");
delay(1000);
lcd.setCursor(0, 1);
lcd.print("Loading...");
delay(2000);
lcd.clear();
lcd.begin(16, 2);
lcd.print("You are on");
delay(100);
lcd.setCursor(0, 1);
lcd.print("a Trail");
delay(3000);
lcd.clear();
lcd.begin(16, 2);
lcd.print("Left or Right?");
delay(100);
lcd.setCursor(0, 1);
lcd.print("L/R");
choice = 1;
while(choice == 1){
yesState = digitalRead(yesPin);
noState = digitalRead(noPin);
if(yesState = HIGH){
yes = 1;
}else {
yes = 0;
}
if(noState = HIGH){
no = 1;
}else {
no = 0;
}
}
if (yes == 1) {
lcd.clear();
lcd.begin(16, 2);
lcd.print("true");
choice = 0;
}
}
void loop() {
}
Note: the code pictured is incomplete