Draw box with pot

Guys, i`m trying to figure out how to construct this sketch to have progress bar related to pot.
My problem at the moment is that the code work only in left top corner and "0" draw full box, around "950"erase it to one line and everything above draw 15 pixel 64 pixel block.
Any ideas??

#include "U8glib.h"
U8GLIB_LM6059 u8g(8, 9, 5, 7, 6);


//▼Sensor Inputs
int sensor1 = A0;
//▼RGB
int redPin = 12;
int greenPin = 11;
int bluePin = 10;

void setup(void) {
   Serial.begin(9600);
   

  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);     
  //▼Pressure Sensors
  pinMode(sensor1, INPUT);
}
void loop(void) {
  uint16_t adc;  
  // read ADC value from pin 0. Range is 0..1023
  adc = analogRead(sensor1);
  Serial.println(adc);
  // convert ADC value to 0..15
  adc = adc/64;
  // picture loop
  u8g.firstPage();  
  do {
    
    u8g.drawBox(0, adc, 15, 15-adc);
  } while( u8g.nextPage() );

  
}

Thanks

why not use 2 pots one for x and one for y

read two potmeters and draw a line

something like

forever
{
x = analogRead(A0)/64;
y = analogRead(A1)/64;

u8g.drawLine(x,y, prevX, prevY);
prevX = x;
prevY = y;
}

This is example.
I have analog sensor that i want display pressure in form of vertical bar.

Any one?? Any suggestions?

You need to draw two boxes.

  1. from your base up to a height determined by the sensor, draw this solid in the foreground colour.
  2. from the height determined by the sensor to the height given by the full range of the sensor. Draw this solid in the background colour.

Keep a record of the last sensor value you drew and only redraw the two boxes when it has changed by a certain small ammount. This prevents flickering on the display.

Grumpy_Mike karma 1+

#include "U8glib.h"
U8GLIB_LM6059 u8g(8, 9, 5, 7, 6);


//▼Sensor Inputs
int sensor1 = A0;
//▼RGB
int redPin = 12;
int greenPin = 11;
int bluePin = 10;

void setup(void) {
   Serial.begin(9600);
   

  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);     
  //▼Pressure Sensors
  pinMode(sensor1, INPUT);
}
void loop(void) {
  uint16_t adc;  
  // read ADC value from pin 0. Range is 0..1023
  adc = analogRead(sensor1);
  Serial.println(adc);
  // convert ADC value to 0..15
  adc = adc/31;
  // picture loop
  u8g.firstPage();  
  do {
    u8g.setColorIndex(1);
    u8g.drawBox(20, 20, 33, 33);
    u8g.setColorIndex(0);
    u8g.drawBox(20, 20, 33, 33-adc);
  } while( u8g.nextPage() );

  
}

Can you make sample of how to store last value??

The last line in the loop function should read:-

 lastadc = adc;

Then after reading the adc at the start of the loop use:-

if( abs(lastadc - adc) > 4 ) {  // do the drawing of the box.

note the function abs() takes the absolute value so that it works if the reading goes up or down by more than four.

Mike, can you please have a look

include "U8glib.h"
U8GLIB_LM6059 u8g(8, 9, 5, 7, 6);


//▼Sensor Inputs
int sensor1 = A0;
//▼RGB
int redPin = 12;
int greenPin = 11;
int bluePin = 10;
int lastadc;
void setup(void) {
   Serial.begin(9600);
   

  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);     
  //▼Pressure Sensors
  pinMode(sensor1, INPUT);
}
void loop(void) {
  uint16_t adc;  
  // read ADC value from pin 0. Range is 0..1023
  adc = analogRead(sensor1);
  Serial.println(adc);
  // convert ADC value to 0..15
  adc = adc/31;
  // picture loop
  u8g.firstPage();  
  do {
    if( abs(lastadc - adc) > 4 )   // do the drawing of the box.
    u8g.setColorIndex(1);
    u8g.drawRBox(20, 20, 33, 33,4 );
    
    u8g.setColorIndex(0);
    u8g.drawBox(20, 20, 33, 33-adc );


    u8g.setColorIndex(1);
    u8g.drawRFrame(20, 19, 33, 35, 4);
    
    
  } while( u8g.nextPage() );
 
lastadc = adc;
  }

Does work, but i`m not so sure if i placed abs() in the right place

The abs is in the right place but the 'if' only works on the first instruction after it. You need to put all the conditional code inside braces { your conditional code }