u8lib bargraf conversion from adafruit library

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

BarFL is not called within the picture loop. Place the call to BarFL inside the "draw" function.

Oliver

i actually did this and i get this message

BarGraph_Tutorial.ino: In function 'void draw()':
BarGraph_Tutorial:12: error: too few arguments to function 'void BarFL(int, int, int, int, int, int, int, int, int)'
BarGraph_Tutorial:32: error: at this point in file

Then please post your complete code. I guess the prototype line for BarFL must be before draw().

Oliver

The complete code is in the first post.There is nothing else.

Ah, I see. Nevertheless, all draw operation must happen within the “picture loop”, which is in your code inside the “draw” function.

Oliver

Ok but that don`t solved the problem. i have no idea how to merge it. Is there any option in your library to draw bargraph?? if yes can you post example so i can redesign what i have?

See i cannot find any suitable like in your library where reference value could be attached. something like u8glib.drawLine(xstart, xfinish, ystart, yfinish, value) or similar. Im not so sure if im thinkig it right

I think it would require a more precise specification of what you mean by bar graph. Additionally it is like this: A graphics library should be able to draw single pixels. If this is possible, you can draw anything else. In fact it is up to the user to draw any "high level" elements. So my suggestion is to break down your "bargraph" to simple elements like lines and boxes. These elements can be drawn by u8glib (and any other library).

Oliver

i am simply want to draw line or box with potentiomer. 0-1023 where 0 is nothing on the screen and 1023 is say 15pixel tall and 5 pixel width.

#include "U8glib.h"
U8GLIB_LM6059 u8g(8, 9, 5, 7, 6);
void setup(void) {
}
void loop(void) {
  uint16_t adc;  
  // read ADC value from pin 0. Range is 0..1023
  adc = analogRead(0);
  // convert ADC value to 0..15
  adc = adc/64;
  // picture loop
  u8g.firstPage();  
  do {
    u8g.drawBox(0, 0, adc, 15);
  } while( u8g.nextPage() );
  // rebuild the picture after some delay
  delay(50);
}

Not tested!

Oliver

Works ok as horizontal bar from left to right. What should i need to make vertical? but it will have to work from bottom to top.

This is a programming question, not a library specific graphics questions. However, i think drawBox should be like this:

u8g.drawBox(0, adc, 15, 15-adc);

Oliver

I`m sorry, did not realize that. Can we ask someone to move this post to the programming section?? Any way, thanks a lot for your help.

https://www.youtube.com/watch?v=O8RnCyhhjyU just as quick reference this is what i`m trying to archieve.

Im wondering if its possible for you to add this to your library? with this code u8g.drawBox(0, adc, 15, 15-adc); You can only position in top line and value above 950 (analogRead) draw the entire line 64px tall

I think these bar graphs can be easily programmed with the existing elements in u8glib, so i will not add them to the library. I think it is more a code pattern.

The second part of your last post, i did not understand. Is there a question?

Oliver

The second part of your last post, i did not understand. Is there a question?

u8g.drawBox(0, adc, 15, 15-adc);

"y" positioning is lost in this cas im just trying to say that it behave the way i don`t want.

Any way, i`ll try to do it during the weekend when my mind is fresh.