#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
int sensor=A0;
int progress=0;
byte zero[] = {
B00000,
B00000,
B00000,
B00000,
B00000,
B00000,
B00000,
B00000
};
byte one[] = {
B10000,
B10000,
B10000,
B10000,
B10000,
B10000,
B10000,
B10000
};
byte two[] = {
B11000,
B11000,
B11000,
B11000,
B11000,
B11000,
B11000,
B11000
};
byte three[] = {
B11100,
B11100,
B11100,
B11100,
B11100,
B11100,
B11100,
B11100
};
byte four[] = {
B11110,
B11110,
B11110,
B11110,
B11110,
B11110,
B11110,
B11110
};
byte five[] = {
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111
};
void setup() {
pinMode(A0,INPUT);
lcd.init();
lcd.backlight();
lcd.createChar(0, zero);
lcd.createChar(1, one);
lcd.createChar(2, two);
lcd.createChar(3, three);
lcd.createChar(4, four);
lcd.createChar(5, five);
}
void loop() {
{ progress=analogRead(sensor);
progress = map(progress,620,0,0,600);
progress = progress > 100 ? 100 : progress;
progress = progress < 0 ? 0 :progress;
lcd.clear();
lcd.setCursor(0,0);
lcd.print(progress);
lcd.print(" ");
updateprogress(progress, 100, 1);
delay(200);
}
delay(1000);
{
lcd.setCursor(0,0);
lcd.print(progress);
lcd.print(" ");
updateprogress(progress, 100, 1);
delay(50);
}
delay(1000);
}
void updateprogress(unsigned long count, unsigned long totalCount, int lineToPrintOn)
{
double factor = totalCount/80.0;
int percent = (count+1)/factor;
int number = percent/5;
int remainder = percent%5;
if(number > 0)
{
lcd.setCursor(number-1,lineToPrintOn);
lcd.write(5);
}
lcd.setCursor(number,lineToPrintOn);
lcd.write(remainder);