Search code examples
carduinodelaylcd

How blink single character without delay() method on LCD using Arduino?


So, I want to write method than can provide blinking on LCD in special possition a specail value without using delay() method. I wrote the next method:

void blink(int cursorIndex, int val) {
   lcd.setCursor(cursorIndex, 0);

   if (millis() - blinkTime > 1000) {
      blinkTime = millis();
      printValOnLCD(val);
   } else {
      lcd.print(" ");
      lcd.print(" ");
   }
}

But it work not in that case that I exectly need. It blink only one time when millis() - blinkTime > 1000 in other cases it show __ .

How can I provide one blinking per one second??


Solution

  • This following code should let the LCD blink once per second. The blinking speed can be changed by changing the blinkSpeed_ms variable.

    void blink(int cursorIndex, int val) {
       lcd.setCursor(cursorIndex, 0);
       blinkSpeed_ms = 1000; //This variable defines the blinking speed
    
       if ((millis() - blinkTime > blinkSpeed_ms) && (millis() - blinkTime < blinkSpeed_ms * 2)) {
          printValOnLCD(val);
       } else if(millis() - blinkTime > (blinkSpeed_ms * 2)) {
          blinkTime = millis()
       }else {
          lcd.print(" ");
          lcd.print(" ");
       }
    }