diff --git a/LcdBarGraph.cpp b/LcdBarGraph.cpp deleted file mode 100644 index c2d853c..0000000 --- a/LcdBarGraph.cpp +++ /dev/null @@ -1,164 +0,0 @@ -/** - * File: LcdBarGraph.cpp - * Description: - * LcdBarGraph is an Arduino library for displaying analog values in LCD display, - * which is previously initialized. This library uses LiquedCrystal library for displaying. - * - * Author: Balazs Kelemen - * Contact: prampec+arduino@gmail.com - * Copyright: 2010 Balazs Kelemen - * Credits: Hans van Neck - * Copying permission statement: - This file is part of LcdBarGraph. - - LcdBarGraph is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - -*/ - -#include "Arduino.h" -#include "LcdBarGraph.h" - -#include - - -// -- initializing bar segment characters -#ifndef USE_BUILDIN_FILLED_CHAR -// -- filled character -byte LcdBarGraph::_level0[8] = { - B11111, - B11111, - B11111, - B11111, - B11111, - B11111, - B11111, - B11111 -}; -#endif - -// -- character with one bar -byte LcdBarGraph::_level1[8] = { - B10000, - B10000, - B10000, - B10000, - B10000, - B10000, - B10000, - B10000 -}; -// -- character with two bars -byte LcdBarGraph::_level2[8] = { - B11000, - B11000, - B11000, - B11000, - B11000, - B11000, - B11000, - B11000 -}; -// -- character with three bars -byte LcdBarGraph::_level3[8] = { - B11100, - B11100, - B11100, - B11100, - B11100, - B11100, - B11100, - B11100 -}; -// -- character with four bars -byte LcdBarGraph::_level4[8] = { - B11110, - B11110, - B11110, - B11110, - B11110, - B11110, - B11110, - B11110 -}; - -// -- constructor -LcdBarGraph::LcdBarGraph(LiquidCrystal* lcd, byte numCols, byte startX, byte startY) -{ - // -- setting fields - _lcd = lcd; - _numCols = numCols; - _startX = startX; - _startY = startY; - // -- creating characters -#ifndef USE_BUILDIN_FILLED_CHAR - _lcd->createChar(0, this->_level0); -#endif - _lcd->createChar(1, this->_level1); - _lcd->createChar(2, this->_level2); - _lcd->createChar(3, this->_level3); - _lcd->createChar(4, this->_level4); - // -- setting initial values - this->_prevValue = 0; // -- cached value - this->_lastFullChars = 0; // -- cached value -} - -// -- the draw function -void LcdBarGraph::drawValue(int value, int maxValue) { - // -- calculate full (filled) character count - byte fullChars = (long)value * _numCols / maxValue; - // -- calculate partial character bar count - byte mod = ((long)value * _numCols * 5 / maxValue) % 5; - - // -- if value does not change, do not draw anything - int normalizedValue = (int)fullChars * 5 + mod; - if(this->_prevValue != normalizedValue) { - // -- do not clear the display to eliminate flickers - _lcd->setCursor(_startX, _startY); - - // -- write filled characters - for(byte i=0; iwrite((byte)USE_BUILDIN_FILLED_CHAR); // -- use build in filled char -#else - _lcd->write((byte)0); -#endif - } - - // -- write the partial character - if(mod > 0) { - _lcd->write(mod); // -- index the right partial character - ++fullChars; - } - - // -- clear characters left over the previous draw - for(byte i=fullChars;i_lastFullChars;i++) { - _lcd->write(' '); - } - - // -- save cache - this->_lastFullChars = fullChars; - this->_prevValue = normalizedValue; - } - /* - // debug info - _lcd->setCursor(0,1); - _lcd->write('['); - _lcd->print((int)value); - _lcd->write(' '); - _lcd->print(normalizedValue); - _lcd->write(' '); - _lcd->print((int)mod); - _lcd->write(']'); - */ -} diff --git a/LcdBarGraph.h b/LcdBarGraph.h deleted file mode 100644 index 0cc0c33..0000000 --- a/LcdBarGraph.h +++ /dev/null @@ -1,72 +0,0 @@ -/** - * File: LcdBarGraph.h - * Description: - * LcdBarGraph is an Arduino library for displaying analog values in LCD display, - * which is previously initialized. This library uses LiquedCrystal library for displaying. - * - * Author: Balazs Kelemen - * Contact: prampec+arduino@gmail.com - * Copyright: 2010 Balazs Kelemen - * Credits: Hans van Neck - * Copying permission statement: - This file is part of LcdBarGraph. - - LcdBarGraph is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - -*/ - -#ifndef LCDBARGRAPH_H -#define LCDBARGRAPH_H - -#include - -#include "Arduino.h" - -#define USE_BUILDIN_FILLED_CHAR 0xFF // -- Char 0xFF is usualy a filled character. Uncomment if you want the library to create the filled char at the expense of 26 bytes. - -class LcdBarGraph -{ -public: - /** - * Create an instance of the class. The bar will be drawn in the startY row - * of the LCD, from the startX column positon (inclusive) to to the startX+numCols column position - * (inclusive). - * lcd - A LiquidCristal instance should be passed. - * numCols - Width of the bar. - * startX - Horzontal starting position (column) of the bar. Zero based value. - * startY - Vertical starting position (row) of the bar. Zero based value. - */ - LcdBarGraph(LiquidCrystal* lcd, byte numCols, byte startX = 0, byte startY = 0); - /** - * Draw a bargraph with a value between 0 and maxValue. - */ - void drawValue(int value, int maxvalue); -private: - LiquidCrystal* _lcd; - byte _numCols; - byte _startX; - byte _startY; - int _prevValue; - byte _lastFullChars; - -#ifndef USE_BUILDIN_FILLED_CHAR - static byte _level0[8]; -#endif - static byte _level1[8]; - static byte _level2[8]; - static byte _level3[8]; - static byte _level4[8]; -}; - -#endif diff --git a/examples/AnalogVisualization/AnalogVisualization.pde b/examples/AnalogVisualization/AnalogVisualization.pde old mode 100644 new mode 100755 index 42cd251..1cb1d22 --- a/examples/AnalogVisualization/AnalogVisualization.pde +++ b/examples/AnalogVisualization/AnalogVisualization.pde @@ -1,11 +1,11 @@ #include -#include +#include byte lcdNumCols = 16; // -- number of columns in the LCD byte sensorPin = 0; // -- value for this example LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // -- creating LCD instance -LcdBarGraph lbg(&lcd, lcdNumCols); // -- creating +LcdBarGraphX lbg(&lcd, lcdNumCols); // -- creating void setup(){ // -- initializing the LCD diff --git a/examples/MoreGraphs/MoreGraphs.ino b/examples/MoreGraphs/MoreGraphs.ino old mode 100644 new mode 100755 index c2d3e42..d3aa7c2 --- a/examples/MoreGraphs/MoreGraphs.ino +++ b/examples/MoreGraphs/MoreGraphs.ino @@ -1,16 +1,16 @@ #include -#include +#include byte lcdNumCols = 16; // -- number of columns in the LCD LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // -- creating LCD instance // -- creating a 4 chars wide bars -LcdBarGraph lbg0(&lcd, 4, 0, 0); // -- First line at column 0 -LcdBarGraph lbg1(&lcd, 4, 5, 0); // -- First line at column 5 -LcdBarGraph lbg2(&lcd, 4, 10, 0); // -- First line at column 10 -LcdBarGraph lbg3(&lcd, 4, 0, 1); // -- Second line at column 0 -LcdBarGraph lbg4(&lcd, 4, 5, 1); // -- Second line at column 5 -LcdBarGraph lbg5(&lcd, 4, 10, 1); // -- Second line at column 0 +LcdBarGraphX lbg0(&lcd, 4, 0, 0); // -- First line at column 0 +LcdBarGraphX lbg1(&lcd, 4, 5, 0); // -- First line at column 5 +LcdBarGraphX lbg2(&lcd, 4, 10, 0); // -- First line at column 10 +LcdBarGraphX lbg3(&lcd, 4, 0, 1); // -- Second line at column 0 +LcdBarGraphX lbg4(&lcd, 4, 5, 1); // -- Second line at column 5 +LcdBarGraphX lbg5(&lcd, 4, 10, 1); // -- Second line at column 0 byte i0 = 0; byte i1 = 0; diff --git a/examples/PositionVisualization/PositionVisualization.pde b/examples/PositionVisualization/PositionVisualization.pde old mode 100644 new mode 100755 index 9ae1e70..8738683 --- a/examples/PositionVisualization/PositionVisualization.pde +++ b/examples/PositionVisualization/PositionVisualization.pde @@ -1,11 +1,11 @@ #include -#include +#include byte lcdNumCols = 16; // -- number of columns in the LCD byte sensorPin = 0; // -- value for this example LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // -- creating LCD instance -LcdBarGraph lbg(&lcd, 4, 12, 1); // -- creating a 4 char wide baraph in the end of second column (column 1) +LcdBarGraphX lbg(&lcd, 4, 12, 1); // -- creating a 4 char wide baraph in the end of second column (column 1) void setup(){ // -- initializing the LCD diff --git a/keywords.txt b/keywords.txt old mode 100644 new mode 100755 index 4e8f019..0cd0757 --- a/keywords.txt +++ b/keywords.txt @@ -6,13 +6,14 @@ # Datatypes (KEYWORD1) ####################################### -LcdBarGraph KEYWORD1 +LcdBarGraphX KEYWORD1 ####################################### # Methods and Functions (KEYWORD2) ####################################### drawValue KEYWORD2 +begin KEYWORD2 ####################################### # Constants (LITERAL1)