Hi,
I'm trying to use the code from this blog post:
http://www.electronicsblog.net/arduino-lcd-horizontal-progress-bar-using-custom-characters/
...with an I2C LCD, using the LiquidCrystal_I2C library. I've updated the sketch to use the newer library, and have a 5K pot attached. The vertical bars display incorrectly - compare the image on the blog to mine, attached here.
What is different about the Liquid Crystal I2C library vs. the original Liquid Crystal library, that would cause this? And how do I fix it?
Jeff
//http://www.electronicsblog.net
//Arduino LCD horizontal progress bar using custom characters
//#include <LiquidCrystal.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address
#define length 16.0
double percent=100.0;
unsigned char b;
unsigned int peace;
// custom characters
// LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
byte p1[8] = {
B0001,
B0001,
B0001,
B0001,
B0001,
B0001,
B0001,
B0001};
byte p2[8] = {
B11000,
B11000,
B11000,
B11000,
B11000,
B11000,
B11000,
B11000};
byte p3[8] = {
B11100,
B11100,
B11100,
B11100,
B11100,
B11100,
B11100,
B11100};
byte p4[8] = {
B11110,
B11110,
B11110,
B11110,
B11110,
B11110,
B11110,
B11110};
byte p5[8] = {
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111};
void setup() {
delay(100);
lcd.createChar(0, p1);
lcd.createChar(1, p2);
lcd.createChar(2, p3);
lcd.createChar(3, p4);
lcd.createChar(4, p5);
lcd.begin(16, 2);
}
void loop()
{
lcd.setCursor(0,0);
//ADC conversion
unsigned int value = analogRead(0);
percent = value/1024.0*100.0;
lcd.print(value);
lcd.print(" - ");
lcd.print(percent);
lcd.print(" % ");
lcd.setCursor(0,1);
double a=length/100*percent;
// drawing black rectangles on LCD
if (a>=1) {
for (int i=1;i<a;i++) {
lcd.write(4);
b=i;
}
a=a-b;
}
peace=a*5;
// drawing character's colums
switch (peace) {
case 0:
break;
case 1:
lcd.print((char)0);
break;
case 2:
lcd.write(1);
break;
case 3:
lcd.write(2);
break;
case 4:
lcd.write(3);
break;
}
//clearing line
for (int i =0;i<(length-b);i++) {
lcd.print(" ");
}
;
}