LCD-I2C- Bargraph does not display correctly

Hello everyone,

I am trying to control two LEDs through PWM. In parallel I trying to read the analog input values of two potentiometer and display them as bar graph. The brightness control and bar graph for LED1 works. But the line which displays LED2 and bar graph blinks. And the bar graph display only after 50%. Can some one help me to identify where is the mistake?

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <LcdBarGraphRobojax.h>

byte lcdNumCols = 16; // -- number of columns in the LCD
byte lcdLine = 2; // -- number of line in the LCD
byte sensorPin0 = A0; // -- value for this example
byte sensorPin1 = A1;
float inpuValue0;//all sorts of variables I tried to use to decompose what was going on
float inpuValue1;
int LEDR = 10;
int LEDG = 11;

LiquidCrystal_I2C lcd(0x27, lcdNumCols, lcdLine); // -- creating LCD instance
LcdBarGraphRobojax lbg1(&lcd, 11, 5, 0);  // -- creating 16 character long bargraph starting at char 0 of line 0 (see video)
LcdBarGraphRobojax lbg2(&lcd, 11, 5, 1);

void setup() {
  // -- initializing the LCD
  lcd.backlight();      // Make sure backlight is on
  // -- do some delay: some time I've got broken visualization, says the guy from whom I took the LCD part

void loop()

  lbg1.clearLine(1);// clear line 1 to display fresh voltage value
  int inpuValue0 = analogRead(sensorPin0);
  lbg1.drawValue( inpuValue0, 1024); // -- draw bar graph from the analog value read
  analogWrite(LEDR, inpuValue0/4);
  lcd.setCursor (0,0); //
  int inpuValue1 = analogRead(sensorPin1);
  lbg2.drawValue( inpuValue1, 1024);
  analogWrite(LEDG, inpuValue1/4);
  lcd.setCursor (0,1); //
    // -- do some delay: frequent draw may cause broken visualization
//  float voltage = inpuValue * (16 /1023.0);
//  lcd.setCursor (0,1); //
//  lcd.print("Voltage:"); 
//  lcd.setCursor (8,1); //
//  lcd.print(voltage); // print
//  lcd.setCursor (12,1); //  
//  lcd.print("V");   

In what way is this a tutorial?

When refreshing an LCD, I always avoid clear line or clearing the whole display unless necessary

Try to only rebuild the changing parts of the display
I would hope the bar graph library will automatically manage that.

Did not realize. Sorry!

Your post was MOVED to its current location as it is more suitable

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