Wilfried Loche
Published © GPL3+

LcdProgressBarDouble

LcdProgressBarDouble is an Arduino library for displaying a 2 progress bars in a single row in LCD display.

BeginnerProtip6,928
LcdProgressBarDouble

Things used in this project

Story

Read more

Schematics

Breadboard (Timer)

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

Schema (Timer)

If you prefer, here is the electric schematic

Breadboard (trimmer potentiometers)

Schema (trimmer potentiometers)

Fritzing schemas (with trimmer potentiometers)

For timer example, simply remove the 2 potentiometers connected to A4 and A5 analog entries.

Code

DoubleTimer.ino

C/C++
Double progress bars demo
/*
  DoubleTimer.ino - v1.0.0 - 2016-08-01

  Showcase of LcdProgressBarDouble library: displays a 2 progress bars in a single row in LCD display,
  which is previously initialized. This library uses LiquidCrystal library for displaying.

  Copyright (c) 2016 Wilfried Loche.  All rights reserved.

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 3 of the License, or (at your option) any later version.

  See file LICENSE.txt for further informations on licensing terms.
*/
#include <LiquidCrystal.h>
#include <LcdProgressBarDouble.h>

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

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

unsigned long duration1 = 20000; // 8000 milliseconds, 8 seconds
unsigned long duration2 = 10000; // 2000 milliseconds, 2 seconds
unsigned long startedMillis1  = 0;
unsigned long startedMillis2  = 0;

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

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

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

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

//-- initializing the progress bars
void initLpg()
{
  //-- start time
  startedMillis1 = millis();
  startedMillis2 = startedMillis1;

  //-- Set min and max values
  lpg.setMinValues(startedMillis1);
  lpg.setMaxValues(startedMillis1 + duration1, startedMillis2 + duration2);

  //-- Draw it
  lpg.draw(startedMillis1);
}

void loop() {

  unsigned long currentMillis = millis();

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

  if ((unsigned long)(currentMillis - startedMillis1) > duration1) {
    //--- Bargraph 1 duration's over: delay and start again!
    startedMillis1 += duration1;
    //lpg.setMinValue1(startedMillis1);
    //lpg.setMaxValue1(startedMillis1 + duration1);

    //--- Shortcut of 2 previous methods
    lpg.setRangeValue1(startedMillis1, startedMillis1 + duration1);
  }

  if ((unsigned long)(currentMillis - startedMillis2) > duration2) {
    //--- Bargraph 2 duration's over: delay and start again!
    startedMillis2 += duration2;
    
    //lpg.setMinValue2(startedMillis2);
    //lpg.setMaxValue2(startedMillis2 + duration2);

    //--- Shortcut of 2 previous methods
    lpg.setRangeValue2(startedMillis2, startedMillis2 + duration2);
  }

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

DoubleBarPot.ino

C/C++
Showcase of LcdProgressBarDouble library: displays a 2 progress bars in a single row in LCD display (from 2 trimmer potentiometers)
/*
  DoubleBarPot.ino - v1.0.2 - 2016-08-01

  Showcase of LcdProgressBarDouble library: displays a 2 progress bars in a single row in LCD display (from 2 trimmer potentiometers),
  which is previously initialized. This library uses LiquidCrystal library for displaying.

  Copyright (c) 2016 Wilfried Loche.  All rights reserved.

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 3 of the License, or (at your option) any later version.

  See file LICENSE.txt for further informations on licensing terms.
*/
#include <LiquidCrystal.h>
#include <LcdProgressBarDouble.h>

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

const int pinR4 = A4;
const int pinR5 = A5;

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

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

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

  lcd.setCursor(0, 0);
  lcd.print("LcdProgressBar*2");

  //-- Set min and max values
  //*** (0 is default minimum value)
  //*** (1023 is maximum value for both bars)
  lpg.setMaxValues(1023);
      
  delay(50);
}

void loop()
{
  int r4 = analogRead(pinR4);
  int r5 = analogRead(pinR5);
  
  //-- draw progress bars
  lpg.draw(r4, r5);

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

GitHub

LcdProgressBarDouble Git repository on GitHub

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