#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 gauge_value = 0; // Current value of the gauge (0 to 100)
int potentiometer_value = 0; // Current potentiometer reading (0 to 1023)
void setup() {
pinMode(A0, INPUT); // Set pin A0 as input to read potentiometer value
}
void loop() {
potentiometer_value = analogRead(A0); // Read potentiometer value (0 to 1023)
gauge_value = map(potentiometer_value, 0, 1023, 0, 100); // Map potentiometer value to gauge range (0 to 100)
// OLED display drawing logic - Modify this part based on your OLED library (u8glib or others)
u8g.firstPage();
do {
drawGauge();
} while (u8g.nextPage());
}
// Function to draw the gauge on the OLED display
void drawGauge() {
// Draw the gauge outline
u8g.setColorIndex(1);
u8g.drawCircle(64, 32, 30); // Center at (64, 32) with radius 30
// Calculate the end point of the needle based on the gauge value
int needle_angle_deg = map(gauge_value, 0, 100, 135, 405); // Map gauge value to needle angle (135° to 405°)
int needle_length = 20;
int needle_x = 64 + needle_length * cos(radians(needle_angle_deg));
int needle_y = 32 + needle_length * sin(radians(needle_angle_deg));
// Draw the needle
u8g.setColorIndex(1);
u8g.drawLine(64, 32, needle_x, needle_y);
// Draw the center of the gauge
u8g.setColorIndex(1);
u8g.drawCircle(64, 32, 3);
// Draw the gauge value text
u8g.setColorIndex(1);
u8g.setFont(u8g_font_profont10);
u8g.setPrintPos(54, 60);
u8g.print(gauge_value);
u8g.print("%");
}