My LCD is controlled by an I2C display. However, the end of the text is always flickering. I as well connected a 4 x 4 keypad, though the input is also not appearing (well it is very dim), it is supposed to show on the second row. How do I fix this? I already tried to adjust the potentiometer that is built to the I2C, still dim and flickering
the error is the program line; LCD.clear (); which is in Loop () {.
Because the display is completely erased with every loop run (which takes time) and the entire text is rewritten, it flickers. You may only delete and rewrite the part of the display that has really changed, not the complete one every time rewrite content.
In addition to what @sterretje, @Deltaflyer and @J-M-L said, do not use the clear function in loop(). It is slow and will contribute to flickering. Use spaces to overwrite old data before sending new data. Do not update the display every time though loop(). Only when data changes or no more than 2 or 3 times a second. Only change the data that needs to change.
The following code illustrates the above suggestions. The hd44780 library is superior to the other LCD libraries and is available through the library manager.
// hd44780 library see https://github.com/duinoWitchery/hd44780
// thehd44780 library is available through the IDE library manager
#include <Wire.h>
#include <hd44780.h> // main hd44780 header
#include <hd44780ioClass/hd44780_I2Cexp.h> // i2c expander i/o class header
hd44780_I2Cexp lcd; // declare lcd object: auto locate & auto config expander chip
// LCD geometry
const int LCD_COLS = 16;
const int LCD_ROWS = 2;
void setup()
{
lcd.begin(LCD_COLS, LCD_ROWS);
lcd.clear();
lcd.print("Hello World");
lcd.setCursor(0, 1);
lcd.print("Millis ");
}
void loop()
{
updateLCD();
}
void updateLCD()
{
static unsigned long lcdTimer = 0;
unsigned long lcdInterval = 500; // update 2 times per second
if (millis() - lcdTimer >= lcdInterval)
{
lcdTimer = millis();
lcd.setCursor(8, 1);
lcd.print(" "); // overwrite old data
lcd.setCursor(8, 1); // reset the cursor
lcd.print(millis());
}
}
yes, sorry, I had started with my answer (english is not my language) and was stopped in another chat by my wife, who is currently 800km away from me, so my message came very late.