Guys, need a little help with my bargraph.
The u8lib require to run draw(); for what ever need to be displayed on the screen
so i have my pressure displayed as i want it responds nice and smooth for the potentiometer but the bargraof want even move, i`m trying to fiddle it out but i need some advice on how to:
//Front panel control
#include "U8glib.h"
#include <EEPROM.h>
//▼Sensor Inputs
int sensor1 = A0;
//▼RGB
int redPin = 12;
int greenPin = 11;
int bluePin = 10;
const byte RGBbut = 52;
byte ButtonState;
byte lastState = LOW;
byte count = 0;
//▼Other
char Val[5];
char buffer[5];
int raw;
float voltage;
int pressureFL; //Pressure PSI
U8GLIB_LM6059 u8g(8, 9, 5, 7, 6);
void draw(void) /// YOU CALL DISPLAY HERE
{
u8g.setFont(u8g_font_timB12);
u8g.drawStr(-5, 21, buffer);
u8g.drawFrame(30, 5, 6, 20);
}
void BarFL(int value = sensor1, int low = 0, int high = 120, int x = 31, int y = 24, int w = 33, int h = 20, int F_color = 1, int B_color = 0); //Bargraph 1 FL
void setup()
{
Serial.begin(9600);
//▼RGB
setColor(0, 0, 0);
count = EEPROM.read(10);
pinMode(RGBbut, INPUT_PULLUP);
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
//▼Pressure Sensors
pinMode(sensor1, INPUT);
}
void loop()
{ // picture loop
u8g.firstPage();
do {
draw();
} while( u8g.nextPage() );
///////////////////////////////////////////////////////////////////////////////////////////// RGB LED
ButtonState = digitalRead(RGBbut); //RGB BUTTON
if(ButtonState && (ButtonState != lastState))
{
if(count < 6) // This will check to see if the count is within a range of 0 - 6
count += 1; // same as count = count + 1;
else
count = 1;
}
lastState = ButtonState;
if(count==1)setColor(255, 255, 255); // White
if(count==2)setColor(255, 255, 0); // Yellow
if(count==3)setColor(100, 255, 0); // Green
if(count==4)setColor(0, 255, 255); // Aqua
if(count==5)setColor(255, 0, 255); // Purple
if(count==6)setColor(0, 255, 50); // Blue
//storing color to eeprom
if(ButtonState == LOW )
{
EEPROM.write(10,count);
}
////////////////////////////////////////////////////////////////////////////////////////////////// sensor #1
//Sensor #1 FL
raw = analogRead(sensor1);
raw -= 102;
pressureFL = (raw * 2) / 11;
dtostrf(pressureFL, 4, 0, buffer); // display pressure on glcd
BarFL(pressureFL); //Call BarGraph
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////// setColor
void setColor(int red, int green, int blue)//RGB Color
{
red = 255 - red;
green = 255 - green;
blue = 255 - blue;
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////// GRAPH
void BarFL(int value, int low, int high, int x, int y, int w, int h, int F_color, int B_color) ///////////////////////////////////// ▼ PROBLEM (is working fine with adafruit lib)
{
static int lastV = -1, move = 0;
int Val = map(value, low, high, 0, h-1);
if (Val != lastV) // prevents it from constantly being redrawn on the screen
{
if ( Val > lastV)
{
for (move; move <= Val; move++)
{
u8g.drawLine(x, y - move, w + 1, y - move);
}
lastV = Val;
}
else
{
for (move; move >= lastV; move--)
{
u8g.drawLine(x, y - (move-1), w + 1, y - (move-1));
}
}
lastV = Val;
}
}
thanks