OLED Pot Bar

Hi, so I'm trying, just for a "first project", to make a bar with a line in the middle, like a paddle, that can be moved left or right, through a potentiometer, on my new 96" 128x64 I2C OLED. I have gotten that working, but I also want a text line saying "...%" (the no. before the "%" is just the pot's 0-1023 mapped to 0-100, to basically say how much of the way is the potentiometer turned), but when I try to run, there is no text, only the "progress" bar.
Any help?
Code:

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <SPI.h>
#include <Adafruit_SSD1306.h>
Adafruit_SSD1306 display(4);
void setup() {

  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initiate the display
  display.clearDisplay();
  
}

void loop() {

  int var = analogRead(0);
  int var1 = analogRead(0);
  var = map(var, 1023, 0, 20, 109);
  var1 = map(var1, 1023, 0, 0, 100);
  display.setCursor(0, 0);
  display.setTextSize(3);
  display.print(var1);
  display.print("%");
  display.clearDisplay();
  display.drawRect(20, 50, 90, 10, 1);
  display.drawLine(var, 50, var, 59, 1);
  ;

  display.display();

}

Thanks.

A cleared value can not be displayed :wink:

Oliver

Sorry, I'm kind of new to this. What do you mean?

Domnulvlad:
Sorry, I'm kind of new to this. What do you mean?

That you cleared your printed value before writing it to the display.

Oliver

Thanks, but how should I fix the problem?

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <SPI.h>
#include <Adafruit_SSD1306.h>
Adafruit_SSD1306 display(4);
void setup() {

  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initiate the display
  display.clearDisplay();
 
}

void loop() {

  int var = analogRead(0);
  int var1 = analogRead(0);
  var = map(var, 1023, 0, 20, 109);
  var1 = map(var1, 1023, 0, 0, 100);
  display.setCursor(0, 0);
  display.setTextSize(3);
  display.print(var1);
  display.print("%");
  display.clearDisplay();    /* move this line up */
  display.drawRect(20, 50, 90, 10, 1);
  display.drawLine(var, 50, var, 59, 1);
  ;

  display.display();

}

Still doesn't wok after doing this

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <SPI.h>
#include <Adafruit_SSD1306.h>
Adafruit_SSD1306 display(4);
void setup() {

  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initiate the display
  display.clearDisplay();
 
}

void loop() {

  int var = analogRead(0);
  int var1 = analogRead(0);
  var = map(var, 1023, 0, 20, 109);
  var1 = map(var1, 1023, 0, 0, 100);
  display.clearDisplay();
  display.setCursor(0, 0);
  display.setTextSize(3);
  display.print(var1);
  display.print("%"); 
  display.drawRect(20, 50, 90, 10, 1);
  display.drawLine(var, 50, var, 59, 1);
  ;

  display.display();

}

The reason that your text is not showing up is because you did not set the text color.

display.setTextColor(WHITE,BLACK);

If your text color will be the same throughout your sketch (white text on a black background), you can add that code to your void setup(), otherwise you can add it your void loop() before you print the text.