#include "U8glib.h"
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_DEV_0 | U8G_I2C_OPT_NO_ACK | U8G_I2C_OPT_FAST); // Fast I2C / TWI
int progress = 0;
int potPin = A0; // Analog pin for the potentiometer
void setup() {
u8g.setFont(u8g_font_tpssb);
u8g.setColorIndex(1);
}
void loop() {
// Read potentiometer value
int potValue = analogRead(potPin);
// Map potentiometer value to the range of the progress bar (0 to 128)
progress = map(potValue, 0, 1023, 0, 128);
u8g.firstPage();
do {
u8g.drawStr(25, 50, "Progress Bar");
u8g.drawFrame(0, 10, 128, 20);
u8g.drawBox(10, 15, progress, 10);
} while ( u8g.nextPage() );
delay(50); // Optional delay to smooth the potentiometer input
}
Loading
ssd1306
ssd1306