Loading...

LcdBarGraph Library for Arduino
Author:  Balázs Kelemen
Contact: prampec+arduino@gmail.com


Navigation


History

 1.0 2010-02-21: Initial Release
 1.1 2011-12-11: Make it compatible with Arduino 1.0
 1.2 2012-04-27: Fix of Robert Klotz for values greater than 1650. (Thank you Rob!)


Description

LcdBarGraph is an Arduino library for displaying analog values in LCD display, which is previously initialized. This library uses LiquedCrystal library for displaying.

LcdBarGraph.gif

The inspiration was come from the video Arduino EMF detector . After watching was wondering what a big work is to build a led bar. Why not use a higher level implementation? And the LcdBarGraph was born.

Please fill free to port this idea to other LCD libraries like arduinoshiftreglcd .


Download, install

Download here:

Extract the zip in your library folder. Restart the Arduino Ide.


Setup

First you need to set up the LiquidCrystal library as usual. After this you can create LcdBarGraph instance with the just created LiquidCrystal instance. You should pass the reference of the LiquidCrystal to the constructor of the LcdBarGraph, as you can see in the exampe.

You also need to specify the number of character columns in the LCD which is unfortunately not available from the official LiquidCrystal library.


Methods

draw(int value, int maxValue)

Draw a bargraph with a value between 0 and maxValue.


Example

  1. #include <LiquidCrystal.h>
  2. #include <LcdBarGraph.h>
  3.  
  4. byte lcdNumCols = 16; // -- number of columns in the LCD
  5. byte sensorPin = 0; // -- value for this example
  6.  
  7. LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // -- creating LCD instance
  8. LcdBarGraph lbg(&lcd, lcdNumCols);  // -- creating
  9.  
  10. void setup(){
  11.   // -- initializing the LCD
  12.   lcd.begin(2, lcdNumCols);
  13.   lcd.clear();
  14.   // -- do some delay some time I've got broken visualization
  15.   delay(100);
  16. }
  17.  
  18. void loop()
  19. {
  20.   // -- draw bar graph from the analog value readed
  21.   lbg.drawValue( analogRead(sensorPin), 1024);
  22.   // -- do some delay: frequent draw may cause broken visualization
  23.   delay(100);
  24. }


Information about this page

Last Modified: April 27, 2012, at 04:02 PM
By: prmpec