Simple interface using a rotary encoder

Hi Guys!
I am trying to create a simple interface using a rotary encoder.
I would like to have basically 2 rows:

Pulse: #values
Delay: #values

I would want to "point" (using arrow key) and "select" using encoder button one of the two rows.
Upon then, using encoder button to change the values.

Until now I could only change the first row. I don't know yet how to code the selection.

I would be happy if you guys can assist.

Thanks.

Z

#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3F,16,2);
int val;
int encoder0PinA = 2;
int encoder0PinB = 3;
int encoder0Pos = 0;
int encoder0PinALast = LOW;
int n = LOW;
const int swPin= 4 ;//the number of the button
int pulse_time = 0;
byte cursor[8] = {
  0b10000,
  0b10000,
  0b01000,
  0b00110,
  0b01000,
  0b10000,
  0b10000,
  0b00000
};


void setup() {
  lcd.init();  // initialize the lcd
  lcd.backlight();
  lcd.setCursor(1,0);
  lcd.print("Pulse:");
  lcd.setCursor(1,1);
  lcd.print("Delay:");
  pinMode (encoder0PinA, INPUT);
  pinMode (encoder0PinB, INPUT);
  pinMode(swPin, INPUT);
  digitalWrite(swPin, HIGH);
  Serial.begin (9600);
  lcd.createChar(0, cursor);
}

void loop() {
  getEncoderTurn();
  if(digitalRead(swPin) == LOW)
  {
    pulse_time = getEncoderTurn();
    lcd.setCursor(8,0);
    lcd.print(pulse_time);
    lcd.setCursor(13,0);
    lcd.print("SET");
  }
}

int getEncoderTurn(void) {
  n = digitalRead(encoder0PinA);
  if ((encoder0PinALast == LOW) && (n == HIGH)) {
    if (digitalRead(encoder0PinB) == LOW) {
      encoder0Pos--;
    } else {
      encoder0Pos++;
    }
    //Serial.print (encoder0Pos);
    lcd.setCursor(8,0);
    lcd.print(encoder0Pos);
    lcd.print("           ");
    

  }
  encoder0PinALast = n;
  return encoder0Pos;
}

Is there a reason why you are not using one of the encoder libraries?

econjack:
Is there a reason why you are not using one of the encoder libraries?

I can certainly use. Please recommend one which can help me reach my needs.

Thanks.

If the encoder code you already have works to your satisfaction (make sure that it does), I see no reason to use a library.

What is your code supposed to do, and what does it do instead?

jremington:
If the encoder code you already have works to your satisfaction, I see no reason to use a library.

Hi jremington
My code doesn't yet do the job. Please see my first post.
I want to be able to change pulse and delay values using one encoder.

You will need to write code for that. If you want someone to do it for you, post in the Gigs & Collaborations section, and be prepared to pay.

If you want to write it yourself, consider using a state machine, using a status variable to determine where encoder input should be directed.

I will give it a try.
I will appreciate if anyone shares an example showing such application.