Wilfried Loche
Published © GPL3+

LcdProgressBar

LcdProgressBar displays a progress bar in LCD display.

BeginnerProtip8,228
LcdProgressBar

Things used in this project

Story

Read more

Schematics

Breadboard

Follow the wires and you'll get the the demo working like a charm :)

Schema

If you prefer, here is the electric schematic

Code

Timer.ino

C/C++
Demo of LcdProgressBar library: progress bar for 2s, looping.
#include <LiquidCrystal.h>
#include <LcdProgressBar.h>

byte lcdNumCols = 16; // -- number of columns in the LCD

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
LcdProgressBar lpg(&lcd, 1, lcdNumCols);

unsigned long duration = 2000; // 2000 milliseconds, 2 seconds
unsigned long startedMillis  = 0;

void setup() {
  //-- Only useful for debugging purpose
  Serial.begin(9600);

  //-- initializing the LCD
  lcd.begin(2, lcdNumCols);
  lcd.clear();

  lcd.setCursor(0, 0);
  lcd.print("LcdProgressBar");
      
  delay(100);

  //-- initializing the progress bar
  initLpg();
}

//-- initializing the progress bar
void initLpg()
{
  //-- start time
  startedMillis = millis();

  //-- Set min and max values
  lpg.setMinValue(startedMillis);
  lpg.setMaxValue(startedMillis + duration);

  //-- Draw it: the frame
  lpg.draw(startedMillis);
}

void loop() {

  unsigned long currentMillis = millis();

  //-- draw progress bar
  lpg.draw(currentMillis);

  if ((unsigned long)(currentMillis - startedMillis) > duration) {
    //--- Duration's over: delay and start again!
    delay(900);
    initLpg();
  }

  // -- do some delay: frequent draw may cause broken visualization
  delay(100);
}

Github

https://github.com/wloche/LcdProgressBar

Credits

Wilfried Loche

Wilfried Loche

3 projects • 9 followers
Computer science lover for a while, I'm a project/program manager. My father transmitted me his DIY love: creating useful and helpful stuffs is so rewarding.

Comments