Choose your own adventure

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

LCD.begin() only needs to be issued once. I don’t see how you ever exit the while loop in setup(), choice is never changed (from 1).

Ok, thanks for the help with the lcd code. The code shown is incomplete; I haven't got around to closing the while loop yet, but thanks for pointing it out. The code still isn't working, do you have any more suggestions?

isn't working

The dreaded "isn't working" tells me nothing. If the code worked, would you be here? If you describe what happens when you run the code and what you expect to happen we have a better chance at helping you.

Can you print to the LCD?

const int yesPin = 7;
const int noPin = 6;

What is connected to those pins? Switches? If so, do the switches have pulldown resistors?

Can you provide a schematic of your project? Drawn on paper, photographed and posted is fine.

Ok, so I realized my problem, but thanks for your efforts in helping me.

Hi,
Okay, what was the solution?

Tom.... :slight_smile: