LCD Encoder Menu

Hi,

Something else I've noticed is from the serial print.

Can someone advise me a better way to read the reading's of the encoder, so the serial monitor will print the direction or the switch and then the reading "xxxx", for example;

CW xxxx
CCW xxxx
SW xx

What I've noticed with the current serial print "I know, not the best", it starts with "1111", on a CW rotation of 1 detent I get "0011", on a CCW rotation of 1 detent I get "0011" and on the push of the switch I get "01"
So I'm getting 4 reading's with each rotation, but only 2 reading's with a push of the switch. So I've tried the skatch by removing the divide by 4;

long newP = myEnc.read() / 4;

To;

long newP = myEnc.read();

This seem's to still work correctly for the rotation of the encoder and the switch to toggle the LED, allthough with rotating the encoder a speed still sometimes changes the LED state.

I think a better serial print would help.

I've also commented-out the button pin 53 and it's pin mode as this may also be causing conflicts;

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
#include <Encoder.h>
Encoder myEnc(20, 21);

//Input & Button Logic
const int numOfInputs = 3;
const int inputPins[numOfInputs] = {20, 21, 53};
int inputState[numOfInputs];
int lastInputState[numOfInputs] = {LOW, LOW, LOW};
bool inputFlags[numOfInputs] = {LOW, LOW, LOW};
long lastDebounceTime[numOfInputs] = {0, 0, 0};
long debounceDelay = 10;
int backlight_pin10 = 10;

//LCD Menu Logic
const int numOfScreens = 10;
int currentScreen = 0;
const char* screens[numOfScreens][2] = {{"1Motor Voltage", "Volts"}, {"2Motor Current", "Amps"},
  {"3Motor Rated HP", "HP"}, {"4Overload Temp.", "degC"}, {"5Accel Time", "Secs"}, {"6Restart Time", "Mins"},
  {"7Analog Out. Curr.", "mA"}, {"8Input Temp.", "degC"}, {"9Run Time", "Hours"}, {"10Start Times", "times"}
};
//int button = 53;
int led = 13;
int dizzwold = false;
int parameters[numOfScreens];

void setup() {
  pinMode(backlight_pin10, OUTPUT);
  analogWrite(10, 200);
  for (int i = 0; i < numOfInputs; i++) {
    pinMode(inputPins[i], INPUT);
    digitalWrite(inputPins[i], HIGH); // pull-up 20k
  }
  pinMode(led, OUTPUT);
  //pinMode(button, INPUT_PULLUP); // set the internal pull up resistor, unpressed button is HIGH
  Serial.begin(9600);
  lcd.begin(20, 4);
}

long old = 0;

void loop() {
  setInputFlags();
  resolveInputFlags();

}

void setInputFlags() {
  for (int i = 0; i < numOfInputs; i++) {
    int reading = digitalRead(inputPins[i]);
    if (reading != lastInputState[i]) {
      lastDebounceTime[i] = millis();
      Serial.println(reading);
    }
    if ((millis() - lastDebounceTime[i]) > debounceDelay) {
      if (reading != inputState[i]) {
        inputState[i] = reading;
        if (inputState[i] == HIGH) {
          inputFlags[i] = HIGH;
        }
      }
    }
    lastInputState[i] = reading;
  }
}

void resolveInputFlags() {
  for (int i = 0; i < numOfInputs; i++) {
    if (inputFlags[i] == HIGH) {
      inputAction(i);
      inputFlags[i] = LOW;
      printScreen();
    }
  }
}

void inputAction(int input)
{
  long newP = myEnc.read();
  {
    if (input == 0)
    {
      if (newP < old)
      {
        old = newP;
        if (currentScreen == 0 && 1)
        {
          currentScreen = numOfScreens - 1;
        }
        else
        {
          currentScreen--;
        }
      }
    }
    else if (input == 1)
    {
      if (newP > old)
      {
        old = newP;
        if (currentScreen == numOfScreens - 1)
        {
          currentScreen = 0;
        }
        else
        {
          currentScreen++;
        }
      }
    }

    else if (input == 2);
    {
      dizzwold = ! dizzwold;
      digitalWrite(led, dizzwold);
      if (newP < old)
        old = newP;
      {
        parameterChange(1);
      }
      if (newP > old)
        old = newP;
      {
        parameterChange(0);
      }
    }
  }
}




void parameterChange(int key) {
  if (key == 0) {
    parameters[currentScreen]++;
  } else if (key == 1) {
    parameters[currentScreen]--;
  }
}

void printScreen() {
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(screens[currentScreen][0]);
  lcd.setCursor(0, 1);
  lcd.print(parameters[currentScreen]);
  lcd.print(" ");
  lcd.print(screens[currentScreen][1]);
}

Also once I'm in the input 2, I think I may need another "if or while statement for input 0 then check and input 1 then check?

Dizzwold.