EEPROM and Button Selections?

Hello! First, I want to thank you for taking the time to read my post. I’m a novice to the world of Arduino, so my programming skills are fresh from the starter books/guides that I can find.

What I have: I have my main Arduino board set up as ISP to program the Arduino on a breadboard. To that breadboard Arduino, I have my LCD and two buttons connected.

What I’m trying to achieve: I’m trying to create a sort of “Choose your own adventure” type of game.

In my mind, this is how the code should be working:

Arduino boots and sets up to use the LCD and buttons along with two variables ‘zz’ and ‘yz’. The user presses button a, it checks if there is a zero in the zero position and displays two options. It then changes the EEPROM zero and one positions to 1 and 1. If button a is a 1, two options are then displayed. If button b is pressed and is a 1, two different options are displayed. The cycle continues with more options and more writes in the same format.

Again, I’m super new to this. This sounds good in my head, but in practice, it doesn’t seem to be working for the second button. The button does nothing. Button a will show options of 1a and 2a, but button b does nothing.

If you have a second, would you take a look at this code for me and let me know where I’m going wrong? I’m pretty stumped.

#include <LiquidCrystal.h>
#include <EEPROM.h>

int zz;
int yz;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

const int switchPin = 6;
int switchState = 0;
int prevSwitchState = 0;

const int switchPin2 = 7;
int switchState2 = 0;
int prevSwitchState2 = 0;

void setup() {
  pinMode(switchPin,INPUT);
  pinMode(switchPin2,INPUT);
  EEPROM.write(0, 0);  
  EEPROM.write(1, 0);
  lcd.begin(16, 2);  ;
  lcd.print("Testing");
}

void loop() {
  switchState = digitalRead(switchPin);
  switchState2 = digitalRead(switchPin2);
  zz = EEPROM.read(0);
  yz - EEPROM.read(1);
  
  if (switchState != prevSwitchState) {
  	if (switchState == LOW){
  	  	if (zz == 0){
  		lcd.clear();
  		delay(1000);
  		lcd.print(F("Option 1"));
		lcd.setCursor(0, 1);
		lcd.print(F("option 2"));
		EEPROM.write(0, 1);
		EEPROM.write(1, 1);
  	  }  		
  	}
  }

 if (switchState != prevSwitchState) {
 	if (switchState == LOW){
 		if(zz == 1){
 			lcd.clear();
 			lcd.print(F("Option 1a"));
 			lcd.setCursor(0, 1);
 			lcd.print(F("Option 2a"));
 			EEPROM.write(0, 2);
 			EEPROM.write(1, 2);
 		}
 	}
 }
if (switchState2 != prevSwitchState2) {
	if (switchState2 == LOW){
		if(yz == 1){
			lcd.clear();
			lcd.print(F("Option 1b"));
			lcd.setCursor(0, 1);
			lcd.print(F("option 2b"));
			EEPROM.write(0, 3);
			EEPROM.write(0, 4);
		}
	}
}  

 prevSwitchState2 = switchState2;
 prevSwitchState = switchState;
}
  if (switchState2 != prevSwitchState2) {
    if (switchState2 == LOW) {
      if (yz == 1) {

What do you see if you print the value of the variables tested in these lines ?

How are the switches wired ? Any pullup resistors ?

Buttons are wired to dPins 6 and 7 respectively. Each are connected to ground with a 10k resistor and the 5v power rail.

I modified part of the code like this and it prints out a 0.

 if (switchState != prevSwitchState) {
    if (switchState == LOW){
        if(zz == 1){
            lcd.clear();
            lcd.print(F("Option 1a"));
            lcd.setCursor(0, 1);
            lcd.print(yz);
            EEPROM.write(0, 2);
            EEPROM.write(1, 2);
        }
    }
 }

Wow, I found it. There’s a small typo that uses a - sign instead of = under void loop. Sheesh. I was staring at this for hours. Thank you!

I modified part of the code like this and it prints out a 0.

If switch 2 is not doing what you want then it is the variables associated with it.

Serial.print("switchState2 : ");
Serial.println(switchState2);
Serial.print("prevSwitchState2 : ");
Serial.println(prevSwitchState2);
Serial.print("yz : ");
Serial.println(yz);

  if (switchState2 != prevSwitchState2) {
    if (switchState2 == LOW) {
      if (yz == 1) {

Would have highlighted the problem. When if tests do not behave as expected it is always worth seeing the values of the variables associated with them.

This one's being programmed on a breadboard and the Arduino is the ISP. I haven't found a way to get the serial feedback from the breadboard to the serial monitor without using an FTDI. Do you happen to know if it's possible with the way I have it set up?