/**
* @file BasicProgress.ino
* @ingroup examples
* @brief Basic library usage example
*
* This example shows how to display a single horizontal smooth progress bar on a character LCD display.
*/
//First include the Liquid Crystal library <LiquidCrystal.h> or <LiquidCrystal_I2C.h>
//#include <LiquidCrystal_I2C.h>
#include <LiquidCrystal.h>
// than include the Smooth progress bars library
#include <SmoothProgress.h>
// SmoothProgress supports progress bars in different visual styles
// Each style is stored in separate .h file that should be included next (you have to use at leas one)
// Let's include the style for horizontal progress bar as a square frame with 1 pixel margin
#include <BarStyle1.h>
// Define the lcd object for the display as recommended for the used liquid crystal library
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
// The library supports multiple progress bars (up to 4 on a single display), different styles and multiple displays
// The hardware limitation of these displays implies that all progress bars on a single display have to share the same style
// Next create the association between the lcd display object and the progress bar style
// as a bar_display (LCD) object (dispA here) to be further used when creating
// the smooth progress bar object and/or changing the style of the displayed progress bars
LCD dispA(lcd, barStyle1);
// Create the object representing the smooth progress bar to be shown on dispA (lcd)
// defining its size and position on the display
SmoothProgressBar spb(dispA, 10, 5, 0); // progress bar 10 characters wide, at 5-th column, 0-th row
void setup()
{
// do the usual lcd initialization for the used liquid crystal library
lcd.begin(20, 2);
lcd.print("Smooth progress bar");
// also initialize the bar_display object (loads the style)
dispA.begin();
delay(2000);
}
void loop()
{
lcd.clear();
// you can show the progress bar calling showProgressPct and specifying the percentage [0-100] to be filled
for (int i = 0; i <= 100; i++)
{
lcd.setCursor(0, 0); // move cursor to top left
lcd.print(i); // print the string on the display
lcd.print('%'); // print the string on the display
spb.showProgressPct(i);
delay(25);
}
delay(1000);
lcd.clear();
// or you can use showProgress method and specifying the number of columns to be filled
// The length in pixel columns of the progress bar can be found by calling the size() method
for (int i = spb.size(); i >=0; i--)
{
lcd.setCursor(0, 0); // move cursor to top left
lcd.print(i); // print the number on the display
lcd.print(' '); // print a character on the display (to overwrite)
spb.showProgress(i);
delay(100);
}
delay(1000);
lcd.clear();
// you can move the progress bar on another position on the display
// and/or change its size
if (spb.row() == 0)
{
spb.setPosition(spb.col() - 5, 1);
spb.setLength(spb.getLength() + 5);
}
else
{
spb.setPosition(spb.col() + 5, 0);
spb.setLength(spb.getLength() - 5);
}
}