store different values into two variables from rotary encoder [SOLVED]

Hi All,
I am trying to store two variables within a while loop after reading a rotary encoder but stores same value for both variables w1Value and w2Value

#include <PinChangeInterrupt.h>
#include <Wire.h>
#include <hd44780.h>
#include <hd44780ioClass/hd44780_I2Cexp.h>
hd44780_I2Cexp lcd;
// Const Variables and pin assinged
const byte ENC_SW = 3;    // Encoder Switch
const byte ENC_PinA = 6;  // PIN A of Encoder
const byte ENC_PinB = 8;  // PIN B of Encoder
const byte buttonPin = 9; // Weld button
// Variables
byte prevENC_SWstate = HIGH;
byte ENC_SWstate = HIGH;
byte Inconfig; // Display config
int ENC_PinAState = LOW;
int ENC_PinALastState = LOW;
int Counter1;
int select;
unsigned long TimeStamp;
unsigned long ENC_SWpressDuration;
unsigned long delayTime = 50;
void setup()
{
  lcd.begin(16, 2);
  lcd.clear();
  pinMode(ENC_PinA, INPUT_PULLUP);
  pinMode(ENC_PinB, INPUT_PULLUP);
  pinMode(ENC_SW, INPUT_PULLUP);
  attachPCINT(digitalPinToPCINT(ENC_PinA), rotaryEncoder, CHANGE);
  lcd.setCursor(5, 0);
  lcd.print("Start");
  delay(1000);
  lcd.clear();
  Serial.begin(115200);
}

void loop()
{
  lcd.setCursor(1, 0);
  lcd.print("W1:10");
  lcd.setCursor(1, 1);
  lcd.print("W2:20");
  lcd.setCursor(9, 0);
  lcd.print("T:29");
  lcd.setCursor(9, 1);
  lcd.print("P:20");
  lcd.print("%");
  int w1Value;
  int w2Value;

  ENC_SWstate = digitalRead(ENC_SW);
  if (ENC_SWstate != prevENC_SWstate)
  {
    if (ENC_SWstate == LOW)
    {
      Inconfig = 1;
    }
  }
  prevENC_SWstate = ENC_SWstate;

  while (Inconfig == 1)
  {
    ENC_SWstate = digitalRead(ENC_SW);
    if (ENC_SWstate != prevENC_SWstate)
    {
      if (ENC_SWstate == LOW)
      {
        select += 1;
        select = select % 4;
      }
      Serial.print(ENC_SWstate);
      Serial.println(select);
    }
    prevENC_SWstate = ENC_SWstate;

    switch (select)
    {

    case 0: //W1
      clearSelectPointer(1);
      lcd.setCursor(0, 0);
      lcd.print(">");
      w1Value = readEncoder() % 6 * 10;
      lcd.setCursor(1, 0);
      lcd.print("W1:");
      lcd.print(w1Value);
      lcd.print(" ");
      break;
    case 1: //W2
      clearSelectPointer(2);
      lcd.setCursor(0, 1);
      lcd.print(">");
      w2Value = readEncoder() % 6 * 10;
      lcd.setCursor(1, 1);
      lcd.print("W2:");
      lcd.print(w2Value);
      lcd.print(" ");
      break;
    case 2: //P
      clearSelectPointer(3);
      lcd.setCursor(8, 1);
      lcd.print(">");
      break;
    case 3:
      lcd.setCursor(0, 0); // 1
      lcd.print(" ");
      lcd.setCursor(0, 1); // 2
      lcd.print(" ");
      lcd.setCursor(8, 1);
      lcd.print(" ");
      break;
    }
  }
}

void rotaryEncoder()
{
  ENC_PinAState = digitalRead(ENC_PinA);
  if (digitalRead(ENC_PinB) != ENC_PinAState)
  {
    Counter1--;
  }
  else
  {
    Counter1++;
  }
}


int readEncoder()
{
  noInterrupts();
  int copyCounter = Counter1;
  interrupts();
  return (copyCounter) >> 1;
}

int clearSelectPointer(int checkPointer)
{
  switch (checkPointer)
  {
  case 1:                // for select 1
    lcd.setCursor(0, 1); // 2
    lcd.print(" ");
    lcd.setCursor(8, 1); // 3
    lcd.print(" ");
    break;
  case 2:                // for select 2
    lcd.setCursor(0, 0); // 1
    lcd.print(" ");
    lcd.setCursor(8, 1); // 3
    lcd.print(" ");
    break;
  case 3:                // for select 3
    lcd.setCursor(0, 0); // 1
    lcd.print(" ");
    lcd.setCursor(0, 1); // 2
    lcd.print(" ");
    break;
  }
  return (checkPointer);
}

Would it possible to store unique values to variables w1Value and w2Value ? Q

a possible problem may be that w1Value and w2Value are local variables recreated on every execution of loop() try making them static so they retain existing values

 static int w1Value;
  static int w2Value;

also Counter1 is modified in the interrupt service routine so make it volatile

volatile int Counter1;

Not sure if i understand how to use them.

#include <PinChangeInterrupt.h>
#include <Wire.h>
#include <hd44780.h>
#include <hd44780ioClass/hd44780_I2Cexp.h>
hd44780_I2Cexp lcd;
// Const Variables and pin assinged
const byte ENC_SW = 3;    // Encoder Switch
const byte ENC_PinA = 6;  // PIN A of Encoder
const byte ENC_PinB = 8;  // PIN B of Encoder
const byte buttonPin = 9; // Weld button
// Variables
byte prevENC_SWstate = HIGH;
byte ENC_SWstate = HIGH;
byte Inconfig; // Display config
int ENC_PinAState = LOW;
int ENC_PinALastState = LOW;
volatile int Counter1;
int select;
static int w1Value;
static int w2Value;
unsigned long TimeStamp;
unsigned long ENC_SWpressDuration;
unsigned long delayTime = 50;
void setup()
{
  lcd.begin(16, 2);
  lcd.clear();
  pinMode(ENC_PinA, INPUT_PULLUP);
  pinMode(ENC_PinB, INPUT_PULLUP);
  pinMode(ENC_SW, INPUT_PULLUP);
  attachPCINT(digitalPinToPCINT(ENC_PinA), rotaryEncoder, CHANGE);
  lcd.setCursor(5, 0);
  lcd.print("Start");
  delay(1000);
  lcd.clear();
  Serial.begin(115200);
}

void loop()
{
  lcd.setCursor(1, 0);
  lcd.print("W1:10");
  lcd.setCursor(1, 1);
  lcd.print("W2:20");
  lcd.setCursor(9, 0);
  lcd.print("T:29");
  lcd.setCursor(9, 1);
  lcd.print("P:20");
  lcd.print("%");

  ENC_SWstate = digitalRead(ENC_SW);
  if (ENC_SWstate != prevENC_SWstate)
  {
    if (ENC_SWstate == LOW)
    {
      Inconfig = 1;
    }
  }
  prevENC_SWstate = ENC_SWstate;

  while (Inconfig == 1)
  {
    ENC_SWstate = digitalRead(ENC_SW);
    if (ENC_SWstate != prevENC_SWstate)
    {
      if (ENC_SWstate == LOW)
      {
        select += 1;
        select = select % 4;
      }
      Serial.print(ENC_SWstate);
      Serial.println(select);
    }
    prevENC_SWstate = ENC_SWstate;

    switch (select)
    {

    case 0: //W1
      clearSelectPointer(1);
      lcd.setCursor(0, 0);
      lcd.print(">");
      w1Value = readEncoder() % 6 * 10;
      lcd.setCursor(1, 0);
      lcd.print("W1:");
      lcd.print(w1Value);
      lcd.print(" ");
      break;
    case 1: //W2
      clearSelectPointer(2);
      lcd.setCursor(0, 1);
      lcd.print(">");
      w2Value = readEncoder() % 6 * 10;
      lcd.setCursor(1, 1);
      lcd.print("W2:");
      lcd.print(w2Value);
      lcd.print(" ");
      break;
    case 2: //P
      clearSelectPointer(3);
      lcd.setCursor(8, 1);
      lcd.print(">");
      break;
    case 3:
      lcd.setCursor(0, 0); // 1
      lcd.print(" ");
      lcd.setCursor(0, 1); // 2
      lcd.print(" ");
      lcd.setCursor(8, 1);
      lcd.print(" ");
      break;
    }
  }
}

void rotaryEncoder()
{
  ENC_PinAState = digitalRead(ENC_PinA);
  if (digitalRead(ENC_PinB) != ENC_PinAState)
  {
    Counter1--;
  }
  else
  {
    Counter1++;
  }
}

int readEncoder()
{
  noInterrupts();
  int copyCounter = Counter1;
  interrupts();
  return (copyCounter) >> 1;
}

int clearSelectPointer(int checkPointer)
{
  switch (checkPointer)
  {
  case 1:                // for select 1
    lcd.setCursor(0, 1); // 2
    lcd.print(" ");
    lcd.setCursor(8, 1); // 3
    lcd.print(" ");
    break;
  case 2:                // for select 2
    lcd.setCursor(0, 0); // 1
    lcd.print(" ");
    lcd.setCursor(8, 1); // 3
    lcd.print(" ");
    break;
  case 3:                // for select 3
    lcd.setCursor(0, 0); // 1
    lcd.print(" ");
    lcd.setCursor(0, 1); // 2
    lcd.print(" ");
    break;
  }
  return (checkPointer);
}

With the above code, the values does not seem to be changing.

can you give a printout of a run of the program?

byte prevENC_SWstate = HIGH;
byte ENC_SWstate = HIGH;

Byte holds 0-255, I suppose technically if the compiler sets it to anything other that zero it’s considered HIGH but would you want it set to 1?

static int w1Value;
static int w2Value;

As global variables, these do not need to be declared as static.The static designator was required when you had them declared in loop().

w1Value = readEncoder() % 6 * 10;
w2Value = readEncoder() % 6 * 10;

With the above code, the values does not seem to be changing.

This code should produce output of 0 and + or - 10,20,30,40,50 depending on the encoder count. Have you confirmed that the encoder values are actually changing?

declaring static int w1Value globally and

w1Value = readEncoder() % 6 * 10;
w2Value = readEncoder() % 6 * 10;

and function reads as

w1Value = readEncoder() % 6 * 10;
w2Value = readEncoder() % 6 * 10;

When

case 0: //W1
      clearSelectPointer(1);
      lcd.setCursor(0, 0);
      lcd.print(">");
      w1Value = readEncoder() % 6 * 10;
      lcd.setCursor(1, 0);
      lcd.print("W1:");
      lcd.print(w1Value);
      lcd.print(" ");
      break;

executes it takes a value of w1Value from encoder as expected but when

 case 1: //W2
      clearSelectPointer(2);
      lcd.setCursor(0, 1);
      lcd.print(">");
      w2Value = readEncoder() % 6 * 10;
      lcd.setCursor(1, 1);
      lcd.print("W2:");
      lcd.print(w2Value);
      lcd.print(" ");
      break;

it takes the vlaue w1Value, which is not what i expected and with a new value at w2Value when case1 excutes it takes the value of w2Value.

Full Code:

#include <PinChangeInterrupt.h>
#include <Wire.h>
#include <hd44780.h>
#include <hd44780ioClass/hd44780_I2Cexp.h>
hd44780_I2Cexp lcd;
// Const Variables and pin assinged
const byte ENC_SW = 3;    // Encoder Switch
const byte ENC_PinA = 6;  // PIN A of Encoder
const byte ENC_PinB = 8;  // PIN B of Encoder
const byte buttonPin = 9; // Weld button
// Variables
byte prevENC_SWstate;
byte ENC_SWstate;
byte Inconfig; // Display config
int ENC_PinAState;
int ENC_PinALastState;
int Counter1;
int select;
static int w1Value;
static int w2Value;
unsigned long TimeStamp;
unsigned long ENC_SWpressDuration;
unsigned long delayTime = 50;
void setup()
{
  lcd.begin(16, 2);
  lcd.clear();
  pinMode(ENC_PinA, INPUT_PULLUP);
  pinMode(ENC_PinB, INPUT_PULLUP);
  pinMode(ENC_SW, INPUT_PULLUP);
  attachPCINT(digitalPinToPCINT(ENC_PinA), rotaryEncoder, CHANGE);
  lcd.setCursor(5, 0);
  lcd.print("Start");
  delay(1000);
  lcd.clear();
  Serial.begin(115200);
}

void loop()
{
  lcd.setCursor(1, 0);
  lcd.print("W1:10");
  lcd.setCursor(1, 1);
  lcd.print("W2:20");
  lcd.setCursor(9, 0);
  lcd.print("T:29");
  lcd.setCursor(9, 1);
  lcd.print("P:20");
  lcd.print("%");

  ENC_SWstate = digitalRead(ENC_SW);
  if (ENC_SWstate != prevENC_SWstate)
  {
    if (ENC_SWstate == LOW)
    {
      Inconfig = 1;
    }
  }
  prevENC_SWstate = ENC_SWstate;

  while (Inconfig == 1)
  {
    ENC_SWstate = digitalRead(ENC_SW);
    if (ENC_SWstate != prevENC_SWstate)
    {
      if (ENC_SWstate == LOW)
      {
        select += 1;
        select = select % 4;
      }
      Serial.print(ENC_SWstate);
      Serial.println(select);
    }
    prevENC_SWstate = ENC_SWstate;

    switch (select)
    {

    case 0: //W1
      clearSelectPointer(1);
      lcd.setCursor(0, 0);
      lcd.print(">");
      w1Value = readEncoder() % 6 * 10;
      lcd.setCursor(1, 0);
      lcd.print("W1:");
      lcd.print(w1Value);
      lcd.print(" ");
      break;
    case 1: //W2
      clearSelectPointer(2);
      lcd.setCursor(0, 1);
      lcd.print(">");
      w2Value = readEncoder() % 6 * 10;
      lcd.setCursor(1, 1);
      lcd.print("W2:");
      lcd.print(w2Value);
      lcd.print(" ");
      break;
    case 2: //P
      clearSelectPointer(3);
      lcd.setCursor(8, 1);
      lcd.print(">");
      break;
    case 3:
      lcd.setCursor(0, 0); // 1
      lcd.print(" ");
      lcd.setCursor(0, 1); // 2
      lcd.print(" ");
      lcd.setCursor(8, 1);
      lcd.print(" ");
      break;
    }
  }
}

void rotaryEncoder()
{
  ENC_PinAState = digitalRead(ENC_PinA);
  if (digitalRead(ENC_PinB) != ENC_PinAState)
  {
    Counter1--;
  }
  else
  {
    Counter1++;
  }
}

int readEncoder()
{
  noInterrupts();
  int copyCounter = Counter1;
  interrupts();
  return (copyCounter) >> 1;
}

int clearSelectPointer(int checkPointer)
{
  switch (checkPointer)
  {
  case 1:                // for select 1
    lcd.setCursor(0, 1); // 2
    lcd.print(" ");
    lcd.setCursor(8, 1); // 3
    lcd.print(" ");
    break;
  case 2:                // for select 2
    lcd.setCursor(0, 0); // 1
    lcd.print(" ");
    lcd.setCursor(8, 1); // 3
    lcd.print(" ");
    break;
  case 3:                // for select 3
    lcd.setCursor(0, 0); // 1
    lcd.print(" ");
    lcd.setCursor(0, 1); // 2
    lcd.print(" ");
    break;
  }
  return (checkPointer);
}

it takes the vlaue w1Value, which is not what i expected and with a new value at w2Value when case1 excutes it takes the value of w2Value.

Please explain the problem statement. Are you saying that after the first error where case1 shows the w1Value instead of w2Value it correctly shows the proper w2Value the next time you enter case 1?

Or, did you mean to say that the first time for case 0 it shows w1Value. Then case 1 shows the w1Value and case 0 shows the w2Value the next time you are in that case, and the values stay out of sync?

switch (select)

Are you absolutely certain you are in the correct case?

w1Value and w2Value shows the values as the rotary encoder is turned. problem is once w1Value(case 0) is set and when it moves to the next case (case 1), the value of w2 shows the value of w1.

Here is the output

Case:0 W1:0 W1:10 W1:20 W1:30 W1:40 Case:1 W2:40 W2:50

Hope i've cleared the confusion.

problem is once w1Value(case 0) is set and when it moves to the next case (case 1), the value of w2 shows the value of w1.

No, I think it is showing the value of the encoder counter as it is. If you want each case to start at 0, then you need to do something to reset the raw counts.

You could reset the encoder when you change cases

if (ENC_SWstate == LOW)
      {
        select += 1;
        select = select % 4;
        noInterrupts();
        Counter1 =  0;
        interrupts();
      }

Or you could limit the reset only to when select is ==0 or == 1

No, I think it is showing the value of the encoder counter as it is.

Actually yest it sure picking from the encoder. i meant the final value of w1Value and w2Value. when it case 1 is executed initially w2Value = w1Value. That changes as i turn the encoder.

I wish to keep all values constant even when it reaches the specific case. The only time it should change is when it reaches the case AND when the encoder is turned.

As you’ve suggested setting the counter1 = 0 will always set the encoder value to zero when the function is called. e.g: w1, initially is set 100 to set it to 110 the counter would reset to zero and we would need to turn the encoder again all the way from 0 t0 110. Where as if the values of the w1Value are retained then w1Value of 100 would be 110 just by a single turn of the rotary encoder.

I think I understand what you want.

When you exit a case after adjustment, you will need to save the final wValue1 or wValue2. Then when you reenter the case you will need to restore the encoder counter to an appropriate Counter1 value.

I'm not clear on how exactly to do this.

Rather than trying to do one time actions when you enter and leave the case(which is always looping) I would try and do it in the select block. For example, when select goes from 0 to 1, or 0 to 4, you save w1Value. When the case goes 1 to 0 or 4 to 0 you reset the Counter1 value to make the previous w1Value.

just realized that i had not set anything to exit the while loop. How do i exit the While Loop after setting exit value in Case 3 ? I am able to enter the the while loop at boot but cannot after exiting it.

#include <PinChangeInterrupt.h>
#include <Wire.h>
#include <hd44780.h>
#include <hd44780ioClass/hd44780_I2Cexp.h>
hd44780_I2Cexp lcd;
// Const Variables and pin assinged
const byte ENC_SW = 3;    // Encoder Switch
const byte ENC_PinA = 6;  // PIN A of Encoder
const byte ENC_PinB = 8;  // PIN B of Encoder
const byte buttonPin = 9; // Weld button
// Variables
byte prevENC_SWstate;
byte prevENC_SWstate1;
byte ENC_SWstate;
byte Inconfig; // Display config
int ENC_PinAState;
int ENC_PinALastState;
int Counter1;
int select;
int w1Value;
int w2Value;
int prevW1Value;
int w1ValSet;
unsigned long TimeStamp;
unsigned long ENC_SWpressDuration;
unsigned long delayTime = 50;
void setup()
{
  lcd.begin(16, 2);
  lcd.clear();
  pinMode(ENC_PinA, INPUT_PULLUP);
  pinMode(ENC_PinB, INPUT_PULLUP);
  pinMode(ENC_SW, INPUT_PULLUP);
  attachPCINT(digitalPinToPCINT(ENC_PinA), rotaryEncoder, CHANGE);
  lcd.setCursor(5, 0);
  lcd.print("Start");
  delay(1000);
  lcd.clear();
  Serial.begin(115200);
}

void loop()
{
  lcd.setCursor(1, 0);
  lcd.print("W1:");
  lcd.setCursor(1, 1);
  lcd.print("W2:");
  lcd.setCursor(9, 0);
  lcd.print("T:29");
  lcd.setCursor(9, 1);
  lcd.print("P:20");
  lcd.print("%");

  ENC_SWstate = digitalRead(ENC_SW);
  if (ENC_SWstate != prevENC_SWstate)
  {
    if (ENC_SWstate == LOW) //&& prevENC_SWstate == LOW)
    {
      Inconfig = 1;
    }
    prevENC_SWstate = ENC_SWstate;
  }

  while (Inconfig == 1)
  {
    ENC_SWstate = digitalRead(ENC_SW);
    if (ENC_SWstate != prevENC_SWstate1)
    {
      if (ENC_SWstate == LOW)
      {
        prevENC_SWstate = ENC_SWstate;
        select += 1;
        select = select % 4;
      }
      prevENC_SWstate1 = ENC_SWstate;
    }

    switch (select)
    {

    case 0: //W1
      clearSelectPointer(1);
      //int w1ValSet;
      lcd.setCursor(0, 0);
      lcd.print(">");
      lcd.setCursor(1, 0);
      lcd.print("W1:");
      w1Value = readEncoder() % 6 * 10;
      if (w1Value <= 0)
      {
        w1Value = 0;
      }
      else
      {
        w1Value = w1Value;
      }
      w1ValSet = w1Value;
      lcd.print(w1ValSet);
      lcd.print(" ");
      break;
    case 1: //W2
      clearSelectPointer(2);
      lcd.setCursor(0, 1);
      lcd.print(">");
      w2Value = readEncoder() % 10 * 10;
      lcd.setCursor(1, 1);
      lcd.print("W2:");
      lcd.print(w2Value);
      lcd.print(" ");
      break;
    case 2: //P
      clearSelectPointer(3);
      lcd.setCursor(8, 1);
      lcd.print(">");
      break;
    case 3:
      lcd.setCursor(0, 0); // 1
      lcd.print(" ");
      lcd.setCursor(0, 1); // 2
      lcd.print(" ");
      lcd.setCursor(8, 1);  //3
      lcd.print(" ");
      Inconfig = 0;
      break;
    }
  }
  Serial.print("W1:");
  Serial.println(w1ValSet);
  Serial.println(" ");
  Serial.print("ENC State:");
  Serial.println(ENC_SWstate);
  Serial.print("Prev State:");
  Serial.println(prevENC_SWstate);
  Serial.println(" ");
}

void rotaryEncoder()
{
  ENC_PinAState = digitalRead(ENC_PinA);
  if (digitalRead(ENC_PinB) != ENC_PinAState)
  {
    Counter1--;
  }
  else
  {
    Counter1++;
  }
}

int readEncoder()
{
  noInterrupts();
  int copyCounter = Counter1;
  interrupts();
  return (copyCounter) >> 1;
}

int clearSelectPointer(int checkPointer)
{
  switch (checkPointer)
  {
  case 1:                // for select 1
    lcd.setCursor(0, 1); // 2
    lcd.print(" ");
    lcd.setCursor(8, 1); // 3
    lcd.print(" ");
    break;
  case 2:                // for select 2
    lcd.setCursor(0, 0); // 1
    lcd.print(" ");
    lcd.setCursor(8, 1); // 3
    lcd.print(" ");
    break;
  case 3:                // for select 3
    lcd.setCursor(0, 0); // 1
    lcd.print(" ");
    lcd.setCursor(0, 1); // 2
    lcd.print(" ");
    break;
  }
  return (checkPointer);
}

I am able to enter the the while loop at boot but cannot after exiting it.

I think the logic of your switch reading is wrong and leaves prevENC_SWstate ==LOW and it will not be entered again.

  ENC_SWstate = digitalRead(ENC_SW);
  if (ENC_SWstate != prevENC_SWstate)
  {
    if (ENC_SWstate == LOW) //&& prevENC_SWstate == LOW)
    {
      Inconfig = 1;
    }
    prevENC_SWstate = ENC_SWstate;
  }

Try replacing it with this debounced code.

ENC_SWstate = digitalRead(ENC_SW);
  if (ENC_SWstate == LOW && prevENC_SWstate == HIGH)
  {
    delay(50); //debounce period
    ENC_SWstate = digitalRead(ENC_SW);
    if (ENC_SWstate == LOW)//stable LOW
    {
      Inconfig = 1;
    }
  }
  prevENC_SWstate = ENC_SWstate;

did not seem to have made any difference. Still works once.

Can you get any serial debugging into the sketch to see the value of variables, entry into conditionals, etc? Does the button press change the switch state reading?

What is the value of Inconfig? Can you see it change to 1 when there is a button press? My testing shows the button press detection code is pretty solid.

Full code

#include <PinChangeInterrupt.h>
#include <Wire.h>
#include <hd44780.h>
#include <hd44780ioClass/hd44780_I2Cexp.h>
hd44780_I2Cexp lcd;
// Const Variables and pin assinged
const byte ENC_SW = 3;    // Encoder Switch
const byte ENC_PinA = 6;  // PIN A of Encoder
const byte ENC_PinB = 8;  // PIN B of Encoder
const byte buttonPin = 9; // Weld button
// Variables
byte prevENC_SWstate;
byte prevENC_SWstate1;
byte ENC_SWstate;
byte Inconfig; // Display config
int ENC_PinAState;
int ENC_PinALastState;
int Counter1;
int select;
int w1Value;
int w2Value;
int prevW1Value;
int w1ValSet;
unsigned long TimeStamp;
unsigned long ENC_SWpressDuration;
unsigned long delayTime = 50;
void setup()
{
  lcd.begin(16, 2);
  lcd.clear();
  pinMode(ENC_PinA, INPUT_PULLUP);
  pinMode(ENC_PinB, INPUT_PULLUP);
  pinMode(ENC_SW, INPUT_PULLUP);
  attachPCINT(digitalPinToPCINT(ENC_PinA), rotaryEncoder, CHANGE);
  lcd.setCursor(5, 0);
  lcd.print("Start");
  delay(1000);
  lcd.clear();
  Serial.begin(115200);
}

void loop()
{
  lcd.setCursor(1, 0);
  lcd.print("W1:");
  lcd.setCursor(1, 1);
  lcd.print("W2:");
  lcd.setCursor(9, 0);
  lcd.print("T:29");
  lcd.setCursor(9, 1);
  lcd.print("P:20");
  lcd.print("%");

  ENC_SWstate = digitalRead(ENC_SW);
  if (ENC_SWstate == LOW && prevENC_SWstate == HIGH)
  {
    delay(50); //debounce period
    ENC_SWstate = digitalRead(ENC_SW);
    if (ENC_SWstate == LOW)//stable LOW
    {
      Inconfig = 1;
    }
  }
  prevENC_SWstate = ENC_SWstate;
  
  while (Inconfig == 1)
  {
    ENC_SWstate = digitalRead(ENC_SW);
    if (ENC_SWstate != prevENC_SWstate1)
    {
      if (ENC_SWstate == LOW)
      {
        select += 1;
        select = select % 4;
      }
      prevENC_SWstate1 = ENC_SWstate;
    }

    switch (select)
    {

    case 0: //W1
      clearSelectPointer(1);
      //int w1ValSet;
      lcd.setCursor(0, 0);
      lcd.print(">");
      lcd.setCursor(1, 0);
      lcd.print("W1:");
      w1Value = readEncoder() % 6 * 10;
      if (w1Value <= 0)
      {
        w1Value = 0;
      }
      else
      {
        w1Value = w1Value;
      }
      w1ValSet = w1Value;
      lcd.print(w1ValSet);
      lcd.print(" ");
      break;
    case 1: //W2
      clearSelectPointer(2);
      lcd.setCursor(0, 1);
      lcd.print(">");
      w2Value = readEncoder() % 10 * 10;
      lcd.setCursor(1, 1);
      lcd.print("W2:");
      lcd.print(w2Value);
      lcd.print(" ");
      break;
    case 2: //P
      clearSelectPointer(3);
      lcd.setCursor(8, 1);
      lcd.print(">");
      break;
    case 3:
      lcd.setCursor(0, 0); // 1
      lcd.print(" ");
      lcd.setCursor(0, 1); // 2
      lcd.print(" ");
      lcd.setCursor(8, 1); //3
      lcd.print(" ");
      Inconfig = 0;
      break;
    }
  }
  Serial.print("W1:");
  Serial.println(w1ValSet);
  Serial.println(" ");
  Serial.print("ENC State:");
  Serial.println(ENC_SWstate);
  Serial.print("Prev State:");
  Serial.println(prevENC_SWstate);
  Serial.println(" ");
}

void rotaryEncoder()
{
  ENC_PinAState = digitalRead(ENC_PinA);
  if (digitalRead(ENC_PinB) != ENC_PinAState)
  {
    Counter1--;
  }
  else
  {
    Counter1++;
  }
}

int readEncoder()
{
  noInterrupts();
  int copyCounter = Counter1;
  interrupts();
  return (copyCounter) >> 1;
}

int clearSelectPointer(int checkPointer)
{
  switch (checkPointer)
  {
  case 1:                // for select 1
    lcd.setCursor(0, 1); // 2
    lcd.print(" ");
    lcd.setCursor(8, 1); // 3
    lcd.print(" ");
    break;
  case 2:                // for select 2
    lcd.setCursor(0, 0); // 1
    lcd.print(" ");
    lcd.setCursor(8, 1); // 3
    lcd.print(" ");
    break;
  case 3:                // for select 3
    lcd.setCursor(0, 0); // 1
    lcd.print(" ");
    lcd.setCursor(0, 1); // 2
    lcd.print(" ");
    break;
  }
  return (checkPointer);
}

Before button press, in Main Loop

W1:0

ENC State:1
Prev State:1

Exit While loop, back in Main Loop

W1:50

ENC State:1
Prev State:1

fixed it. now need to figure out how to set the w1Value and w2Value from changing as they loop through.

fixed it.

What was the problem, and what was the fix?

Added a "default" case with

select = 0;