Rotary Encoder LCD Blinking text

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

The easier you make it to read and copy the code the more likely it is that you will get help

Please follow the advice given in the link below when posting code , use code tags and post the code here

Please read the post linked by UKHeliBob again, pay special attention to the section about the use of code tags and fix your post.

So it will maintain indentations and we don't have to be looking at e.g.

Thank you.

Yes. Use a millis() based approach to update the specific row of the thisplay. Below as a guide

void loop()
{
  blinkDisplay();
}


void blinkDisplay()
{
  // keep track when we have to do something
  static uint32_t nextUpdateTime = 0;
  // state; row is currently displayed or not
  static bool rowOn = false;
  
  // check if i's time to update the row
  if(millis() - nextUpdateTime >= interval)
  {
    nextUpdateTime+= interval;
    // if row is currently not showing
    if (rowOn == false)
    {
      // indicate that it is now showing
      rowOn = true;
      // select the row
      lcd.setCursor(0,0);
      // print message
      lcd.print("Hello World");
    }
    // if row is currently showing
    else
    {
      // indicate that it is now showing
      rowOn = false;
      // select the row
      lcd.setCursor(0,0);
      // wipe message
      lcd.print("                ");
    }
  }
}

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.