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;
}