#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
//LiquidCrystal_I2C lcd(0x27, 20, 4);
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() {
  // initialize the LCD and allocate the 5 arrays to a number.
  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);
}
//This simple loop code prints a number from 0 to 100 on the top line and displays the progress bar on the bottom line.
// The loop counts up, pauses for 1 second, then counts down again.
void loop() {
 for(int i=0; i <= 100; i++)
 {
  //lcd.setCursor(8,0);
   // lcd.print(i);
   // lcd.print("   ");
    updateProgressBar(i, 100, 1);   //This line calls the subroutine that displays the progress bar.  The 3 arguments are the current count, the total count and the line you want to print on.
    delay(10);
  }
  delay(500);
  lcd.clear();
  lcd.setCursor(2,0);
  lcd.print("kones");
  delay(500);
  lcd.clear();
}
/*
 * This is the method that does all the work on the progress bar.
 * Please feel free to use this in your own code.
 * @param count = the current number in the count progress
 * @param totalCount = the total number to count to
 * @param lineToPrintOn = the line of the LCD to print on.
 * 
 * Because I am using a 16 x 2 display, I have 16 characters.  Each character has 5 sections.  Therefore, I need to declare the number 80.0.
 * If you had a 20 x 4 display, you would have 25 x 5 = 100 columns.  Therefore you would change the 80.0 t
 */
 void updateProgressBar(unsigned long count, unsigned long totalCount, int lineToPrintOn)
 {
    double factor = totalCount/80.0;          //See note above!
    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);  
 }