简体   繁体   中英

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??

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM