Ok here is a gif Imgur: The magic of the Internet (the top 2 rows) of what I want to do. I have several more graphs that I'd like to do but I want to get one graph working.
My prototype setup is
Ardunio Uno with a 2x16 serial LCD
My production setup will be
Ardunio Nano with a 2x20 Serial VFD
I've got all of the custom characters (just blocks) in the ramp I want (see code below).
#include <SerialLCD.h>
#include <Wire.h>
// make some custom characters:
byte P8[8] = {
0b11111,
0b11111,
0b11111,
0b11111,
0b11111,
0b11111,
0b11111,
0b11111,
};
byte P7[8] = {
0b00000,
0b11111,
0b11111,
0b11111,
0b11111,
0b11111,
0b11111,
0b11111,
};
byte P6[8] = {
0b00000,
0b00000,
0b11111,
0b11111,
0b11111,
0b11111,
0b11111,
0b11111,
};
byte P5[8] = {
0b00000,
0b00000,
0b00000,
0b11111,
0b11111,
0b11111,
0b11111,
0b11111,
};
byte P4[8] = {
0b00000,
0b00000,
0b00000,
0b00000,
0b11111,
0b11111,
0b11111,
0b11111,
};
byte P3[8] = {
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b11111,
0b11111,
0b11111,
};
byte P2[8] = {
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b11111,
0b11111,
};
byte P1[8] = {
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b11111,
};
;
// Constructor. Parameters: rows, columns, baud/i2c_address, interface (RS232, I2C, SPI)
SerialLCD lcd(2,16,9600,RS232);
void setup() {
// Initialize LCD module
lcd.init();
// create a new character
lcd.createChar(0, P1);
lcd.createChar(1, P2);
lcd.createChar(2, P3);
lcd.createChar(3, P4);
lcd.createChar(4, P5);
lcd.createChar(5, P6);
lcd.createChar(6, P7);
lcd.createChar(7, P8);
// Set Contrast
lcd.setContrast(40);
// Set Backlight
lcd.setBacklightBrightness(2);
}
void loop() {
int i;
lcd.home();
// lcd.clear();
lcd.setCursor(1, 9); // location of the first row cursor
lcd.write((byte)0);
lcd.write((byte)1);
lcd.write((byte)2);
lcd.write((byte)3);
lcd.write((byte)4);
lcd.write((byte)5);
lcd.write((byte)6);
lcd.write((byte)7);
lcd.setCursor(2, 1); // location of the second row cursor
lcd.write((byte)0);
lcd.write((byte)1);
lcd.write((byte)2);
lcd.write((byte)3);
lcd.write((byte)4);
lcd.write((byte)5);
lcd.write((byte)6);
lcd.write((byte)7);
lcd.write((byte)7);
lcd.write((byte)7);
lcd.write((byte)7);
lcd.write((byte)7);
lcd.write((byte)7);
lcd.write((byte)7);
lcd.write((byte)7);
lcd.write((byte)7);
}
This is my stab at the analog pins. The math is about right but getting it to scale with the graph above hasn't worked well for me.
#define lenght 16.0
double percent=100.0;
unsigned char b;
unsigned int peace;
#include <SerialLCD.h>
#include <Wire.h>
// make some custom characters:
byte P8[8] = {
0b11111,
0b11111,
0b11111,
0b11111,
0b11111,
0b11111,
0b11111,
0b11111,
};
byte P7[8] = {
0b00000,
0b11111,
0b11111,
0b11111,
0b11111,
0b11111,
0b11111,
0b11111,
};
byte P6[8] = {
0b00000,
0b00000,
0b11111,
0b11111,
0b11111,
0b11111,
0b11111,
0b11111,
};
byte P5[8] = {
0b00000,
0b00000,
0b00000,
0b11111,
0b11111,
0b11111,
0b11111,
0b11111,
};
byte P4[8] = {
0b00000,
0b00000,
0b00000,
0b00000,
0b11111,
0b11111,
0b11111,
0b11111,
};
byte P3[8] = {
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b11111,
0b11111,
0b11111,
};
byte P2[8] = {
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b11111,
0b11111,
};
byte P1[8] = {
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b11111,
};
;
// Constructor. Parameters: rows, columns, baud/i2c_address, interface (RS232, I2C, SPI)
SerialLCD lcd(2,16,9600,RS232);
void setup() {
// Initialize LCD module
lcd.init();
delay(100);
// create a new character
lcd.createChar(0, P1);
lcd.createChar(1, P2);
lcd.createChar(2, P3);
lcd.createChar(3, P4);
lcd.createChar(4, P5);
lcd.createChar(5, P6);
lcd.createChar(6, P7);
lcd.createChar(7, P8);
lcd.setCursor(0, 0);
// Set Contrast
lcd.setContrast(40);
// Set Backlight
lcd.setBacklightBrightness(4);
}
void loop() {
int i;
lcd.setCursor(1,1);
// ADC Conversion
unsigned int value = analogRead(0);
percent = value/1024.0*100.0;
// lcd.print(value);
lcd.print("FUEL ");
// lcd.print(" - ");
lcd.print(value);
lcd.print(" ");
lcd.setCursor(2,5);
double a=lenght/100*percent;
// Drawing rectangles on LCD
// drawing black rectangles on LCD
if (a>=1) {
for (int i=1;i<a;i++) {
lcd.write(7);
b=i;
}
a=a-b;
}
peace=a*5;
// drawing charater's colums
switch (peace) {
case 0:
break;
case 1:
lcd.print((char)0);
break;
case 2:
lcd.print((char)1);
break;
case 3:
lcd.print((char)2);
break;
case 4:
lcd.print((char)3);
break;
}
//clearing line
for (int i =0;i<(lenght-b);i++) {
lcd.print(" ");
}
;
}
what am I missing (I know, alot) I just want it to bar graph like in the GIF. I'm close yet so far. Any help will be appreciated