LCD Screen-Cycling through menu without external input

Hello all,

I have been trying to create a menu using two buttons as the inputs to navigate. I have a button push counter set up, and depending on what the counter reads, the menu should respond accordingly…in theory. However it is just cycling through each option fort he designated delay time (3 seconds). Does anyone know why it is not going off of the button push counter?

Also there are a bunch of servo control commands in there which I have not tested, thought I would tackle one problem at a time.

Thank you so much for the help!!!

Ry

  #include <Servo.h>
  
  #include <LiquidCrystal.h>
  
  LiquidCrystal lcd (2, 3, 4, 5, 6, 7);
  
  Servo servoThumb;
  Servo servoPointer;
  Servo servoMid;
  Servo servoRingPink;
   
  const int buttonPin1 = 13;
  const int buttonPin2 = 12;
  int buttonPushCounter = 1;
  
  byte currentButtonState1 = LOW;
  byte previousButtonState1 = LOW;
  byte currentButtonState2 = LOW;
  byte previousButtonState2 = LOW;
  
  int fsrPinBigtoe = 0;
  int fsrPinPinktoe = 1;
  int fsrReadingBigtoe;
  int fsrReadingPinktoe;
  
  int servoThumbPosition = 0;
  int servoPointerPosition = 0;
  int servoMidPosition = 0;
  int servoRingPinkPosition = 0;
  
  void setup() {
    Serial.begin(9600);
    pinMode(buttonPin1, INPUT);
    pinMode(buttonPin2, INPUT);
  
    servoThumb.attach(11);
    servoThumb.write(0);
    servoPointer.attach(10);
    servoPointer.write(0);
    servoMid.attach(9);
    servoMid.write(0);
    servoRingPink.attach(8);
    servoRingPink.write(0);

    lcd.begin(16, 2);
    
  
    // put your setup code here, to run once:
  
  }
  
  void loop() {
    fsrReadingPinktoe = analogRead(fsrPinPinktoe);
    Serial.print("Analog Reading Pinky Toe = ");
    Serial.println(fsrReadingPinktoe);
  
    fsrReadingBigtoe = analogRead(fsrPinBigtoe);
    Serial.print("Analog Reading Big Toe = ");
    Serial.println(fsrReadingBigtoe);
  
  
  
    currentButtonState1 == digitalRead(buttonPin1);
    if (currentButtonState1 != previousButtonState1 && currentButtonState1 == HIGH)
    {
      buttonPushCounter += 1;
    }
    currentButtonState2 == digitalRead(buttonPin2);
    if (currentButtonState2 != previousButtonState2 && currentButtonState2 == HIGH)
    {
      buttonPushCounter -= 1;
    }
  
    if (buttonPushCounter <= 1)
    {
      buttonPushCounter == 1;
    }
    if (buttonPushCounter >= 5)
    {
      buttonPushCounter = 5;
    }
  
    if (buttonPushCounter = 1)
    {
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Relax Mode");
      delay(3000);
      
      servoThumb.write(30);
      delay(10);
      servoPointer.write(30);
      delay(10);
      servoMid.write(30);
      delay(10);
      servoRingPink.write(30);
      delay(10);
      
    }
  
  
    if (buttonPushCounter = 2)
    {
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Grasp Mode");
      delay(3000);
  
      if (fsrReadingBigtoe >= 300)
      {
        delay(500);
        if (fsrReadingBigtoe >= 300)
        {
          servoThumb.write(135);
          delay(10);
          servoPointer.write(135);
          delay(10);
          servoMid.write(135);
          delay(10);
          servoRingPink.write(135);
      delay(10);
        }
        delay(10);
      }
      if (fsrReadingPinktoe >= 300);
      {
        servoThumb.write(30);
        delay(10);
        servoPointer.write(30);
        delay(10);
        servoMid.write(30);
        delay(10);
        servoRingPink.write(30);
      delay(10);
      }
    }
  
    if (buttonPushCounter = 3)
    {
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Point Mode");
      delay(3000);
  
      if (fsrReadingBigtoe >= 300)
      {
        delay(500);
        if (fsrReadingBigtoe >= 300)
        {
          servoThumb.write(135);
          delay(10);
          servoPointer.write(0);
          delay(10);
          servoMid.write(135);
          delay(10);
          servoRingPink.write(135);
      delay(10);
        }
        delay(10);
      }
      delay(10);
      if (fsrReadingPinktoe >= 300);
      {
        servoThumb.write(30);
        delay(10);
        servoPointer.write(30);
        delay(10);
        servoMid.write(30);
        delay(10);
        servoRingPink.write(30);
      delay(10);
      }
    }
  
    if (buttonPushCounter = 4)
    {
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Thumbs Up Mode");
      delay(3000);
  
      if (fsrReadingBigtoe >= 300)
      {
        delay(500);
        if (fsrReadingBigtoe >= 300)
        {
          servoThumb.write(0);
          delay(10);
          servoPointer.write(135);
          delay(10);
          servoMid.write(135);
          delay(10);
          servoRingPink.write(135);
      delay(10);
        }
        delay(10);
      }
      delay(10);
      if (fsrReadingPinktoe >= 300);
      {
        servoThumb.write(30);
        delay(10);
        servoPointer.write(30);
        delay(10);
        servoMid.write(30);
        delay(10);
        servoRingPink.write(30);
      delay(10);
      }
    }
  
    if (buttonPushCounter = 5)
    {
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Wave Mode");
      delay(3000);
  
      if (fsrReadingBigtoe >= 300)
      {
        delay(500);
        if (fsrReadingBigtoe >= 300)
        {
          servoThumb.write(0);
          delay(10);
          servoPointer.write(0);
          delay(10);
          servoMid.write(0);
          delay(10);
          servoRingPink.write(0);
      delay(10);
        }
        delay(10);
      }
      delay(10);
      if (fsrReadingPinktoe >= 300);
      {
        servoThumb.write(30);
        delay(10);
        servoPointer.write(30);
        delay(10);
        servoMid.write(30);
        delay(10);
        servoRingPink.write(30);
      delay(10);
      }
    }
  
  }

Not sure if this is the pb but all your if do variable allocation instead of testing

    if (buttonPushCounter = 2)

should read

    if (buttonPushCounter == 2)

and when you want to do assignments, you do a test

    currentButtonState1 == digitalRead(buttonPin1);
    currentButtonState2 == digitalRead(buttonPin2);

that should just be "="

    currentButtonState1 = digitalRead(buttonPin1);
    currentButtonState2 = digitalRead(buttonPin2);

proof read all the code, fix that and test again.

I updated the code, and it stopped the cycling of the menu however now when I push the button it does not go through the menu. Thank you so much for the help!!

Ry

I have made a mistake, that did indeed solve the problem. I still had the 3 second delay, written as delay(3000); I changed it to delay(10); and now I do not have to hold the button down for 3 seconds. Thank you for the help,

Cheers,

Ry