#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
byte patterns[6][8] = {
{ 0b00000, 0b00000, 0b00000, 0b00000, 0b00000, 0b00000, 0b00000, 0b00000 },
{ 0b10000, 0b10000, 0b10000, 0b10000, 0b10000, 0b10000, 0b10000, 0b10000 },
{ 0b11000, 0b11000, 0b11000, 0b11000, 0b11000, 0b11000, 0b11000, 0b11000 },
{ 0b11100, 0b11100, 0b11100, 0b11100, 0b11100, 0b11100, 0b11100, 0b11100 },
{ 0b11110, 0b11110, 0b11110, 0b11110, 0b11110, 0b11110, 0b11110, 0b11110 },
{ 0b11111, 0b11111, 0b11111, 0b11111, 0b11111, 0b11111, 0b11111, 0b11111 }
};
void setup() {
lcd.init();
lcd.backlight();
for (int i = 0; i < 6; i++) {
lcd.createChar(i, patterns[i]);
}
}
void loop() {
for (int i = 0; i < 80; i++) {
lcd.setCursor(0, 0);
lcd.print(i);
lcd.print(" ");
updateProgressBar(i, 80, 1);
delay(12);
}
}
void updateProgressBar(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) {
for (int j = 0; j < number; j++) {
lcd.setCursor(j, lineToPrintOn);
lcd.write(5);
}
}
lcd.setCursor(number, lineToPrintOn);
lcd.write(remainder);
if (number < 16) {
for (int j = number + 1; j <= 16; j++) {
lcd.setCursor(j, lineToPrintOn);
lcd.write(0);
}
}
}