Good morning Dear Friends !
I am new in arduino coding. Need make on the LCD display bargraph like this : post 11
http://forum.arduino.cc/index.php?topic=8218.0
Lambda display view.
Original code in C++ is GitHub - designer2k2/multidisplay: The MultiDisplay Project, An opensource datalogger, boost controller and display for cars GitHub - designer2k2/multidisplay: The MultiDisplay Project, An opensource datalogger, boost controller and display for cars
As i am not programmer, i cannot make C++ working in the Arduino . Problem is in deleting redundant boxes before necessary black box.
Please help!
If you can print black boxes, then you can print a space for a blank box.
Paul
Thanks!
From internet possible code:
/*
Voltmeter with graph
Coded by Ollie Jeffcoate
*/
#include <LiquidCrystal.h>
LiquidCrystal lcd(2, 3, 4, 5, 6, 7); //initialize the library, numbers of the interface pins
int analogInput = 1; //analog pin A1
float VoltageOut = 0.0;
float VoltageIn = 0.0;
int refresh = 50; //refresh rate
int i = 0; //variable used for clearing our byte 'graph'
int value = 0; //variable to store value
byte graph[8] =
{
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
};
void setup()
{
pinMode(analogInput, INPUT); //setting analog pin mode to input
lcd.begin(16, 2); //setting up the LCD screens rows and colums
lcd.print("Voltage=");
}
void loop(){
value = analogRead(analogInput); //reading the value on A1
//VoltageOut = (value * 5.0) / 1024.0;
VoltageIn = (value * 5.0) / 1024.0;
//VoltageOut / (R2/(R1+R2));
lcd.setCursor(8, 0); //printing the result to the LCD display
lcd.print(VoltageIn);
lcd.print(" V");
delay(refresh); //refreshing the screen
voltmetergraph(); //calling my function voltmetergraph
}
void voltmetergraph()
{
if (VoltageIn >= 0.3125) //setting up the bar graph
{
lcd.createChar(0, graph);
lcd.setCursor(0, 2);
lcd.write(byte(0));}
else {LcdClearByte(0);}
if (VoltageIn >= 0.625)
{
lcd.createChar(0, graph);
lcd.setCursor(1, 2);
lcd.write(byte(0));}
else {LcdClearByte(1);}
if (VoltageIn >= .9375)
{
lcd.createChar(0, graph);
lcd.setCursor(2, 2);
lcd.write(byte(0));}
else {LcdClearByte(2);}
if (VoltageIn >= 1.25){
lcd.createChar(0, graph);
lcd.setCursor(3, 2);
lcd.write(byte(0));}
else {LcdClearByte(3);}
if (VoltageIn >= 1.5625)
{
lcd.createChar(0, graph);
lcd.setCursor(4, 2);
lcd.write(byte(0));}
else {LcdClearByte(4);}
if (VoltageIn >= 1.875)
{
lcd.createChar(0, graph);
lcd.setCursor(5, 2);
lcd.write(byte(0));}
else {LcdClearByte(5);}
if (VoltageIn >= 2.1875)
{
lcd.createChar(0, graph);
lcd.setCursor(6, 2);
lcd.write(byte(0));}
else {LcdClearByte(6);}
if (VoltageIn >= 2.5)
{
lcd.createChar(0, graph);
lcd.setCursor(7, 2);
lcd.write(byte(0));}
else {LcdClearByte(7);}
if (VoltageIn >= 2.8125)
{
lcd.createChar(0, graph);
lcd.setCursor(8, 2);
lcd.write(byte(0));}
else {LcdClearByte(8);}
if (VoltageIn >= 3.125)
{
lcd.createChar(0, graph);
lcd.setCursor(9, 2);
lcd.write(byte(0));}
else {LcdClearByte(9);}
if (VoltageIn >= 3.4375)
{
lcd.createChar(0, graph);
lcd.setCursor(10, 2);
lcd.write(byte(0));}
else {LcdClearByte(10);}
if (VoltageIn >= 3.75)
{
lcd.createChar(0, graph);
lcd.setCursor(11, 2);
lcd.write(byte(0));}
else {LcdClearByte(11);}
if (VoltageIn >= 4.0625)
{
lcd.createChar(0, graph);
lcd.setCursor(12, 2);
lcd.write(byte(0));}
else {LcdClearByte(12);}
if (VoltageIn >= 4.375)
{
lcd.createChar(0, graph);
lcd.setCursor(13, 2);
lcd.write(byte(0));}
else {LcdClearByte(13);}
if (VoltageIn >= 4.6875)
{
lcd.createChar(0, graph);
lcd.setCursor(14, 2);
lcd.write(byte(0));}
else {LcdClearByte(14);}
if (VoltageIn >= 4.99)
{
lcd.createChar(0, graph);
lcd.setCursor(15, 2);
lcd.write(byte(0));}
else {LcdClearByte(15);}
}
void LcdClearByte(int c) //clearbyte function
{
lcd.setCursor(c,1);
for (i = 0; i < 16; i = i + 1) {
lcd.print(" ");
}
}
But cannot delete left-handed unwanted black boxes. lcd.clear() wasting time? How to clear unwanted left-handed boxes?
What are "left-handed boxes"? If you want a bar, all the boxes from left to the current level have to be drawn...
You can simply write:
lcd.setCursor(0,2);
if (VoltageIn >= 0.3125) lcd.print('█'); else lcd.print(' ');
...
...
It should work... ![]()
Thank You Mr. Datman
#include <LiquidCrystal.h>
LiquidCrystal lcd(2, 3, 4, 5, 6, 7); //initialize the library, numbers of the interface pins
int analogInput = 1; //analog pin A1
float VoltageOut = 0.0;
float VoltageIn = 0.0;
int refresh = 50; //refresh rate
int i = 0; //variable used for clearing our byte 'graph'
int value = 0; //variable to store value
byte graph[8] =
{
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
};
void setup()
{
pinMode(analogInput, INPUT); //setting analog pin mode to input
lcd.begin(16, 2); //setting up the LCD screens rows and colums
lcd.print("Voltage=");
}
void loop(){
value = analogRead(analogInput); //reading the value on A1
//VoltageOut = (value * 5.0) / 1024.0;
VoltageIn = (value * 5.0) / 1024.0;
//VoltageOut / (R2/(R1+R2));
lcd.setCursor(8, 0); //printing the result to the LCD display
lcd.print(VoltageIn);
lcd.print(" V");
delay(refresh); //refreshing the screen
voltmetergraph(); //calling my function voltmetergraph
}
void voltmetergraph()
{
if (VoltageIn >= 0.3125) //setting up the bar graph
{
lcd.setCursor(0,2);
lcd.print('█'); }
else
{
lcd.print(' ');
}
if (VoltageIn >= 0.625)
{
lcd.setCursor(1, 2);
lcd.print('█'); }
else
{
lcd.print(' ');
}
if (VoltageIn >= .9375)
{
lcd.setCursor(2, 2);
lcd.print('█');}
else
{lcd.print(' ');
}
if (VoltageIn >= 1.25){
lcd.setCursor(3, 2);
lcd.print('█');}
else
{lcd.print(' ');
}
if (VoltageIn >= 1.5625)
{
lcd.setCursor(4, 2);
lcd.print('█');}
else
{
lcd.print(' ');
}
if (VoltageIn >= 1.875)
{
lcd.setCursor(5, 2);
lcd.print('█');
}
else
{
lcd.print(' ');
}
if (VoltageIn >= 2.1875)
{
lcd.setCursor(6, 2);
lcd.print('█');
}
else
{
lcd.print(' ');
}
if (VoltageIn >= 2.5)
{
lcd.setCursor(7, 2);
lcd.print('█');
}
else
{
lcd.print(' ');
}
if (VoltageIn >= 2.8125)
{
lcd.setCursor(8, 2);
lcd.print('█');
}
else
{
lcd.print(' ');
}
if (VoltageIn >= 3.125)
{
lcd.setCursor(9, 2);
lcd.print('█');
}
else
{
lcd.print(' ');
}
if (VoltageIn >= 3.4375)
{
lcd.setCursor(10, 2);
lcd.print('█');
}
else
{
lcd.print(' ');
}
if (VoltageIn >= 3.75)
{
lcd.setCursor(11, 2);
lcd.print('█');
}
else
{
lcd.print(' ');
}
if (VoltageIn >= 4.0625)
{
lcd.setCursor(12, 2);
lcd.print('█');
}
else
{
lcd.print(' ');
}
if (VoltageIn >= 4.375)
{
lcd.setCursor(13, 2);
lcd.print('█');
}
else
{
lcd.print(' ');
}
if (VoltageIn >= 4.6875)
{
lcd.setCursor(14, 2);
lcd.print('█');
}
else
{
lcd.print(' ');
}
if (VoltageIn >= 4.99)
{
lcd.setCursor(15, 2);
lcd.print('█');
}
else
{
lcd.print(' ');
}
}
Not working right for me. I dont know how somewhere is unknown text 27000 on the lcd, like[ -----------27000]. Incomprehensible. My problem is :
I like to see ONLY ONE sign in the right place on the lcd like indicator pointer multimeter [ - ]
if (VoltageIn >= 2.5)
{
lcd.setCursor(7, 2);
lcd.print('█');
}
else
{
lcd.print(' ');
Cannot delete unwanted left-hand boxes [-------- ]
Need make on the LCD display bargraph like this : post 11
Multidisplay, a Open Source inCar Display, Logger - Exhibition - Arduino Forum
Lambda display view.
Original code in C++ is GitHub - designer2k2/multidisplay: The MultiDisplay Project, An opensource datalogger, boost controller and display for cars GitHub - designer2k2/multidisplay: The MultiDisplay Project, An opensource datalogger, boost controller and display for cars
As i am not programmer, i cannot make C++ working in the Arduino . Problem is in deleting redundant boxes before necessary black box.
lcd.setCursor(0,2);
if (VoltageIn >= 0.3125) lcd.write(255); else lcd.print(' ');
...
...
It works.
What you are asking is more complex, because you want a cursor.
Thank You Mr. Datman
#include <LiquidCrystal.h>
LiquidCrystal lcd(2, 3, 4, 5, 6, 7); //initialize the library, numbers of the interface pins
int analogInput = 1; //analog pin A1
float VoltageOut = 0.0;
float VoltageIn = 0.0;
int refresh = 50; //refresh rate
int i = 0; //variable used for clearing our byte 'graph'
int value = 0; //variable to store value
byte graph[8] =
{
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
};
void setup()
{
pinMode(analogInput, INPUT); //setting analog pin mode to input
lcd.begin(16, 2); //setting up the LCD screens rows and colums
lcd.print("Voltage=");
}
void loop(){
value = analogRead(analogInput); //reading the value on A1
//VoltageOut = (value * 5.0) / 1024.0;
VoltageIn = (value * 5.0) / 1024.0;
//VoltageOut / (R2/(R1+R2));
lcd.setCursor(8, 0); //printing the result to the LCD display
lcd.print(VoltageIn);
lcd.print(" V");
delay(refresh); //refreshing the screen
voltmetergraph(); //calling my function voltmetergraph
}
void voltmetergraph()
{
lcd.setCursor(0,2);
if (VoltageIn >= 0.3125) lcd.write(255); else lcd.print(' ');
lcd.setCursor(1, 2);
if (VoltageIn >= 0.625) lcd.write(255); else lcd.print(' ');
if (VoltageIn >= .9375)
lcd.setCursor(2, 2);
if (VoltageIn >= 1.25) lcd.write(255); else lcd.print(' ');
lcd.setCursor(3, 2);
if (VoltageIn >= 1.25) lcd.write(255); else lcd.print(' ');
lcd.setCursor(4, 2);
if (VoltageIn >= 1.5625) lcd.write(255); else lcd.print(' ');
lcd.setCursor(5, 2);
if (VoltageIn >= 1.875) lcd.write(255); else lcd.print(' ');
lcd.setCursor(5, 2);
if (VoltageIn >= 2.1875) lcd.write(255); else lcd.print(' ');
lcd.setCursor(6, 2);
if (VoltageIn >= 2.5) lcd.write(255); else lcd.print(' ');
lcd.setCursor(7, 2);
if (VoltageIn >= 2.8125) lcd.write(255); else lcd.print(' ');
lcd.setCursor(8, 2);
if (VoltageIn >= 3.125) lcd.write(255); else lcd.print(' ');
lcd.setCursor(9, 2);
if (VoltageIn >= 3.4375) lcd.write(255); else lcd.print(' ');
lcd.setCursor(10, 2);
if (VoltageIn >= 3.75) lcd.write(255); else lcd.print(' ');
lcd.setCursor(11, 2);
if (VoltageIn >= 4.0625) lcd.write(255); else lcd.print(' ');
lcd.setCursor(12, 2);
if (VoltageIn >= 4.375) lcd.write(255); else lcd.print(' ');
lcd.setCursor(13, 2);
if (VoltageIn >= 4.6875) lcd.write(255); else lcd.print(' ');
lcd.setCursor(14, 2);
if (VoltageIn >= 4.99) lcd.write(255); else lcd.print(' ');
lcd.setCursor(15, 2);
if (VoltageIn >= 5.00) lcd.write(255); else lcd.print(' ');
}
Not working right for me.
I like to see ONLY ONE sign in the right place on the lcd like indicator pointer multimeter [ - ] !!!!!!!!!
and not [------- ]
Cannot delete unwanted left-hand boxes [-------- ]
May be refresh or update display made scale slow and my idea is not real in HD44780 lcd
Why not print a complete row of blanks (spaces) then print your cursor at the desired position?
Hi
try replacing your voltmetergraph() function with the following:-
void voltmetergraph() {
for int i = 0; i < 16; i++) {
lcd.setCursor(i, 1);
if ((voltageIn >= (0.3125 * i)) and (voltageIn <= (0.3125 * (i+1))) lcd.write(255);
else lcd.write(32);
}
}
This loops round 16 times (i = 0 to i = 15) and prints a block if voltageIn is between the following values:-
if i = 0 then a block will be printed if voltageIn is between 0 and 0.3125 otherwise a space will be printed
if i = 1 then a block will be printed if voltageIn is between 0.3125 and 0.625 otherwise a space will be printed
...
...
if i = 15 then a block will be printed if voltageIn is between 4.6875 and 5 otherwise a space will be printed.
This should fix your problem an print a single block along the bottom line of the display.
N.B. The lines of the display have addresses 0 and 1 NOT 1 and 2 hence the lcd.setCursor(i, 1)
Ian
Try this:
#include <LiquidCrystal.h>
LiquidCrystal lcd(2, 3, 4, 5, 6, 7); //initialize the library, numbers of the interface pins
int analogInput = 1; //analog pin A1
float VoltageOut = 0.0;
float VoltageIn = 0.0;
int refresh = 50; //refresh rate
int value = 0; //variable to store value
void setup()
{
pinMode(analogInput, INPUT); //setting analog pin mode to input
lcd.begin(16, 2); //setting up the LCD screens rows and colums
lcd.print("Voltage=");
}
void loop()
{
value = analogRead(analogInput); //reading the value on A1
//VoltageOut = (value * 5.0) / 1024.0;
VoltageIn = (value * 5.0) / 1024.0;
//VoltageOut / (R2/(R1+R2));
lcd.setCursor(8, 0); //setting LCD cursor
lcd.print(VoltageIn);
lcd.print(" V");
delay(refresh); //screen refresh delay
voltmetergraph(); //calling my function voltmetergraph
}
void voltmetergraph()
{
lcd.setCursor(0, 1);
if (VoltageIn >= 0.28) lcd.write(255); else lcd.print('-');
lcd.setCursor(1, 1);
if (VoltageIn >= 0.56) lcd.write(255); else lcd.print('-');
lcd.setCursor(2, 1);
if (VoltageIn >= 0.83) lcd.write(255); else lcd.print('-');
lcd.setCursor(3, 1);
if (VoltageIn >= 1.11) lcd.write(255); else lcd.print('-');
lcd.setCursor(4, 1);
if (VoltageIn >= 1.38) lcd.write(255); else lcd.print('-');
lcd.setCursor(5, 1);
if (VoltageIn >= 1.67) lcd.write(255); else lcd.print('-');
lcd.setCursor(5, 1);
if (VoltageIn >= 1.94) lcd.write(255); else lcd.print('-');
lcd.setCursor(6, 1);
if (VoltageIn >= 2.22) lcd.write(255); else lcd.print('-');
lcd.setCursor(7, 1);
if (VoltageIn >= 2.50) lcd.write(255); else lcd.print('-');
lcd.setCursor(8, 1);
if (VoltageIn >= 2.78) lcd.write(255); else lcd.print('-');
lcd.setCursor(9, 1);
if (VoltageIn >= 3.06) lcd.write(255); else lcd.print('-');
lcd.setCursor(10, 1);
if (VoltageIn >= 3.33) lcd.write(255); else lcd.print('-');
lcd.setCursor(11, 1);
if (VoltageIn >= 3.61) lcd.write(255); else lcd.print('-');
lcd.setCursor(12, 1);
if (VoltageIn >= 3.89) lcd.write(255); else lcd.print('-');
lcd.setCursor(13, 1);
if (VoltageIn >= 4.17) lcd.write(255); else lcd.print('-');
lcd.setCursor(14, 1);
if (VoltageIn >= 4.44) lcd.write(255); else lcd.print('-');
lcd.setCursor(15, 1);
if (VoltageIn >= 4.72) lcd.write(255); else lcd.print('-');
}
Try this, instead of the previous:
#include <LiquidCrystal.h>
LiquidCrystal lcd(2, 3, 4, 5, 6, 7); //initialize the library, numbers of the interface pins
int analogInput = 1; //analog pin A1
unsigned long VoltageIn = 0; // [mV]
int refresh = 50; //refresh rate
void setup()
{
pinMode(analogInput, INPUT); //setting analog pin mode to input
lcd.begin(16, 2); //setting up the LCD screens rows and columns
lcd.print("Voltage=");
lcd.setCursor(13, 0); lcd.print('V');
}
void loop()
{
//value = analogRead(analogInput); //reading the value on A1
//VoltageOut = (value * 5.0) / 1024.0;
//VoltageOut / (R2/(R1+R2));
VoltageIn = analogRead(analogInput) * 5000 / 1024;
lcd.setCursor(8, 0); //setting LCD cursor
lcd.print(int(VoltageIn/1000)); lcd.print('.'); lcd.print(int(VoltageIn/10)%100);
delay(refresh); //screen refresh delay
voltmetergraph(); //calling my function voltmetergraph
}
void voltmetergraph()
{
int step=280; // mV
for(int i=0; i<16; i++)
{lcd.setCursor(i,0); if(VoltageIn>=step*(i+1) && VoltageIn<step*(i+2)) lcd.write(255); else lcd.print('-');}
}
Actually with a bit of thought we can simplify things even more. Try this:-
#include <LiquidCrystal.h>
LiquidCrystal lcd(2, 3, 4, 5, 6, 7); //initialize the library, numbers of the interface pins
int analogInput = 1; //analog pin A1
float VoltageIn = 0.0; // Used to calculate and display voltage
int refresh = 500; //refresh the display every half second
int i = 0; //variable used for clearing our byte 'graph'
int value = 0; //variable to store value from analogRead
void setup()
{
pinMode(analogInput, INPUT); //setting analog pin mode to input
lcd.begin(16, 2); //setting up the LCD screens rows and colums
lcd.print("Voltage=");
}
void loop(){
value = analogRead(analogInput); //reading the value on A1
VoltageIn = (value * 5.0) / 1024.0;
lcd.setCursor(8, 0); //printing the result to the LCD display
lcd.print(VoltageIn);
lcd.print(" V");
delay(refresh); //refreshing the screen
voltmetergraph(); //calling my function voltmetergraph
}
void voltmetergraph()
{
int position = map(value, 0, 1023, 0, 15);
lcd.setCursor(0,1); // move the cursor to the start of the second line
lcd.print(" "); // clear the second line by writing 15 spaces
lcd.setCursor(position, 1); // Move to the correct position on the line
lcd.write(255); // print a block
}
This works because value has a range of 0 to 1023 and the map converts this to the range 0 to 15 which can be used to position the block on the line.
If you want to draw a bar rather than a single block use this code for voltmetergraph():-
void voltmetergraph()
{
int position = map(value, 0, 1023, 0, 15);
lcd.setCursor(0,1); // move the cursor to the start of the second line
lcd.print(" "); // clear the second line by writing 15 spaces
for (int j = 0; j <= position; j++)
{
lcd.setCursor(j, 1);
lcd.write(255); // print a block
}
}
Ian
Thank You Datman and IanCrowe!
I like for my ad8307 voltmeter project IanCrowe code:
/*
Code from IanCrowe http://forum.arduino.cc/index.php?topic=541688.0
post 11 with one little supplement clearing last box too.
Thank You Iancrowe!
*/
#include <LiquidCrystal.h>
LiquidCrystal lcd(2, 3, 4, 5, 6, 7); //initialize the library, numbers of the interface pins
int analogInput = 1; //analog pin A1
float VoltageIn = 0.0; // Used to calculate and display voltage
int refresh = 500; //refresh the display every half second
int i = 0; //variable used for clearing our byte 'graph'
int value = 0; //variable to store value from analogRead
void setup()
{
pinMode(analogInput, INPUT); //setting analog pin mode to input
lcd.begin(16, 2); //setting up the LCD screens rows and colums
lcd.print("Voltage=");
}
void loop(){
value = analogRead(analogInput); //reading the value on A1
VoltageIn = (value * 5.0) / 1024.0;
lcd.setCursor(8, 0); //printing the result to the LCD display
lcd.print(VoltageIn);
lcd.print(" V");
delay(refresh); //refreshing the screen
voltmetergraph(); //calling my function voltmetergraph
}
void voltmetergraph()
{
int position = map(value, 0, 1023, 0, 15);
lcd.setCursor(0,1); // move the cursor to the start of the second line
lcd.print(" "); // clear the second line by writing 15 spaces(
//For clearing last box-5v too, needed 16 spaces if first is 1.
lcd.setCursor(position, 1); // Move to the correct position on the line
lcd.write(255); // print a block
}
Much thanks!
73!
Tiit
Hi Tilt
My bad it should have been 16 spaces to clear the whole line not 15.
Ian
Tiit:
Thank You Datman and IanCrowe!
I like for my ad8307 voltmeter project IanCrowe code:/*
Code from IanCrowe LCD Horizontal bargraph like one black rectangle - Programming Questions - Arduino Forum
post 11 with one little supplement clearing last box too.
Thank You Iancrowe!
*/
#include <LiquidCrystal.h>
LiquidCrystal lcd(2, 3, 4, 5, 6, 7); //initialize the library, numbers of the interface pins
int analogInput = 1; //analog pin A1
float VoltageIn = 0.0; // Used to calculate and display voltage
int refresh = 500; //refresh the display every half second
int i = 0; //variable used for clearing our byte 'graph'
int value = 0; //variable to store value from analogRead
void setup()
{
pinMode(analogInput, INPUT); //setting analog pin mode to input
lcd.begin(16, 2); //setting up the LCD screens rows and colums
lcd.print("Voltage=");
}
void loop(){
value = analogRead(analogInput); //reading the value on A1
VoltageIn = (value * 5.0) / 1024.0;
lcd.setCursor(8, 0); //printing the result to the LCD display
lcd.print(VoltageIn);
lcd.print(" V");
delay(refresh); //refreshing the screen
voltmetergraph(); //calling my function voltmetergraph
}
void voltmetergraph()
{
int position = map(value, 0, 1023, 0, 15);
lcd.setCursor(0,1); // move the cursor to the start of the second line
lcd.print(" "); // clear the second line by writing 15 spaces(
//For clearing last box-5v too, needed 16 spaces if first is 1.
lcd.setCursor(position, 1); // Move to the correct position on the line
lcd.write(255); // print a block
}
Much thanks! 73! Tiit