Two button control for a DC motor and LCD

Hi!
I have an LCD and two buttons. I want one of the buttons to cycle between 3 modes with each of them displaying something. After a mode is selected the second button is used to start that respective mode and do some actions such as running a motor for a certain amount and changing the color of an RGB LED. When the button is pressed a second time it should display a warning message and a third push would, ideally pause the process. Is there a way to make the program remember where it was paused and continue from there with an additional press of a button? Also how make the process completely stop when holding both buttons for a few seconds.

#include <LiquidCrystal.h>
#include <Wire.h>

#define Q1_Q3 12
#define Q2_Q4 13

#define RSPin 31
#define EnablePin 33
#define DS4 29
#define DS5 37
#define DS6 45
#define DS7 35

#define PIN_R 39
#define PIN_G 40
#define PIN_B 43

#define START_BTN 49
#define MODE_BTN 47

int modeCounter = 0;
int processStatus = 0;
int currentMode = 0;

LiquidCrystal lcd(RSPin, EnablePin, DS4, DS5, DS6, DS7);

void setup()
{
  Serial.begin(9600);
  Wire.begin();
  lcd.begin(16, 2); //Configure the LCD
  lcd.setCursor(0, 0);
  lcd.print("    WELCOME!    ");
  delay(2000);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.write("     Please     ");
  lcd.setCursor(0, 1);
  lcd.write(" select a MODE ");
  pinMode(START_BTN, INPUT_PULLUP);
  pinMode(MODE_BTN, INPUT_PULLUP);
  pinMode(PIN_R, OUTPUT);
  pinMode(PIN_G, OUTPUT);
  pinMode(PIN_B, OUTPUT);
  pinMode(Q1_Q3, OUTPUT);
  pinMode(Q2_Q4, OUTPUT);
  digitalWrite(PIN_R, HIGH);
  digitalWrite(PIN_G, HIGH);
  digitalWrite(PIN_B, HIGH);
}

void loop()
{
  byte _status;
  unsigned int H_dat, T_dat;
  float RH, T_C;
  byte mode = digitalRead(MODE_BTN);
  byte sap = digitalRead(START_BTN);
  if (mode == LOW) {
    modeCounter++;
    switch (modeCounter) {
      case 1:
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.write("Current Mode: ");
        lcd.setCursor(0, 1);
        lcd.write("MODE 1");
        delay(500);
        currentMode = 1;
        break;
      case 2:
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.write("Current Mode: ");
        lcd.setCursor(0, 1);
        lcd.write("MODE 2");
        delay(500);
        currentMode = 2;
        break;
      case 3:
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.write("Current Mode: ");
        lcd.setCursor(0, 1);
        lcd.write("MODE 3");
        delay(500);
        currentMode = 3;
        break;
      default:
        modeCounter = 0;
        break;
    }
  }
}


void motorFWD() {
  digitalWrite(Q1_Q3, HIGH);
  for (int dc; dc <= 255; dc++)
  {
    analogWrite(Q2_Q4, dc);
    delay(20);
  }
  analogWrite(Q2_Q4, 255);
}

void motorBWK() {
  digitalWrite(Q2_Q4, HIGH);
  for (int dc; dc <= 255; dc++)
  {
    analogWrite(Q1_Q3, dc);
    delay(20);
  }
  analogWrite(Q1_Q3, 255);
}

void motorSTOP() {
  for (int i = 255; i >= 0; i--) {
    analogWrite(Q2_Q4, i);
    delay(20);
  }
  digitalWrite(Q1_Q3, LOW);
}

void modeS1()
{
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.write("Cycle in progress...");
  lcd.setCursor(0, 1);
  lcd.write("     MODE 1     ");
  motorFWD();
  delay(10000);
  motorSTOP();
  delay(1000);
  motorBWK();
  delay(8000);
  motorSTOP();
  delay(1000);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.write("Cycle");
  lcd.setCursor(0, 1);
  lcd.write("FINISHED!");
}

void modeS2()
{
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.write("Cycle in progress...");
  lcd.setCursor(0, 1);
  lcd.write("     MODE 2     ");
  motorFWD();
  delay(10000);
  motorSTOP();
  delay(1000);
  motorBWK();
  delay(8000);
  motorSTOP();
  delay(1000);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.write("Cycle");
  lcd.setCursor(0, 1);
  lcd.write("FINISHED!");
}

void modeS3()
{
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.write("Cycle in progress...");
  lcd.setCursor(0, 1);
  lcd.write("     MODE 3     ");
  motorFWD();
  delay(10000);
  motorSTOP();
  delay(1000);
  motorBWK();
  delay(8000);
  motorSTOP();
  delay(1000);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.write("Cycle");
  lcd.setCursor(0, 1);
  lcd.write("FINISHED!");
}

This is the code I have so far. The functions for the motor are used to control a DC motor through a H-Bridge. And the control scheme from above is used to control the duration for which the motor is running. I already tested those functions and they seem to work well enough for my application, I know that they could be better. And then there are the 3 mode of operation I want to cycle through, for now they are the same but will end up being different. Also I observed that when the motor is running or changing direction the LCD tends to display just blocks or random characters, is this behavior from the code and if yes how could I solve it, or some electrical/electronic problem on my PCB?

Thanks!

There is the possibility that the power drawn from the source through the motor gets to high and the LCD doesn't get enough power to function properly .

For your mode button, you should actually use a state-change detection. That is, you take action when the button becomes pressed, not when it is pressed (as you do now); there is an example in the IDE.

For your start button, you can consider a finite state machine. Your 'process' can be in one of certain states; based on a quick glance at your description

  1. Not running
  2. Running
  3. Warning

You can implement it using a switch/case.

I suggest that you do a little bit of studying on the above subjects and try some things. If you're stuck, we can help.

Hardware is not my strong point. I suspect a power issue. Can you provide a schematic/wiring diagram; a photo of a hand drawn one is fine.

What kind of motors are you using? What exact H-bridge is driving them.

A photo of the setup might also help. Having 'power' wires parallel with signal wires (as an example) might cause the symptoms that you describe.