I've been trying to get my arduino to iterate across an array while blinking the text on an lcd at the same time but it doesn't seem to work well. Is there a way to get my lcd to blink the specific row while allowing my encoder to toggle between the values within the array?
LCD___Rotary_Encoder.ino (2.0 KB)
#include <Bounce2.h>
#include <LiquidCrystal_I2C.h>
int pinA = 19;
int pinB = 18;
int pinC = 5;
int aState;
int aLastState;
int digits[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
int digit;
int sizeofdigits;
int a;
Bounce debouncerA=Bounce();
Bounce debouncerB=Bounce();
Bounce debouncerC=Bounce();
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x3F for a 16 chars and 2 line display
void setup() {
digit=0;
pinMode (pinA,INPUT);
pinMode (pinB,INPUT);
pinMode (pinC,INPUT);
debouncerA.attach(pinA);
debouncerA.interval(5);
debouncerB.attach(pinB);
debouncerB.interval(5);
debouncerC.attach(pinC);
debouncerC.interval(5);
Serial.begin (115200);
lcd.init();
lcd.clear();
lcd.backlight();
// Make sure backlight is on
aLastState = digitalRead(pinA);
int size = sizeof(digits) / sizeof(int);
sizeofdigits=size;
Serial.print(sizeofdigits);
}
void loop() {
MainMenu();
aState = debouncerA.read();
//delayMicroseconds(5000);
if (aState != aLastState){
// outputB != outputA state, encoder is rotating clockwise
if (debouncerB.read() != aState) {
movedClockwise();
//counter ++;
}
else if (debouncerB.read() == aState){
//counter --;
movedCounterClockwise();
}
}
aLastState = aState;
}
void movedClockwise() {
digit=digit+1;
if (digit==sizeofdigits){
digit=0;
}
}
void movedCounterClockwise() {
digit=digit-1;
if(digit==-1){
digit=9;
}
}
void MainMenu(){
// Print a message on both lines of the LCD.
lcd.setCursor(0,0); //Set cursor to character 2 on line 0
lcd.print("Hello world!");
lcd.setCursor(0,1); //Move cursor to character 2 on line 1
lcd.print(digits[digit]);
/*lcd.blink();
delay(3000);
lcd.noBlink();
delay(3000);*/
debouncerA.update();
debouncerB.update();
}