#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(OLED_RESET);
void setup() {
// Initialize SSD1306 display with the I2C address 0x3C
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
// Clear the display buffer.
display.clearDisplay();
// Display "STARTING" message
display.setTextSize(2); // Increase text size
display.setTextColor(SSD1306_WHITE);
display.setCursor(10, 10); // Move cursor
display.println("STARTING");
display.display(); // Display the message
delay(2000); // Pause for 2 seconds
display.clearDisplay(); // Clear the display buffer
}
void loop() {
static int previousS = -1;
int S = analogRead(A0);
// Check if the current analog reading is significantly different from the previous reading
if (abs(S - previousS) > 5) { // Decrease threshold for faster updates
// Clear the display buffer.
display.clearDisplay();
// Display analog reading
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.print("Analog reading: ");
display.println(S);
// Display bar graph decoration with thicker line
display.drawFastHLine(0, 20, S / 10, SSD1306_WHITE);
display.drawFastHLine(0, 21, S / 10, SSD1306_WHITE);
display.drawFastHLine(0, 22, S / 10, SSD1306_WHITE);
display.drawFastHLine(0, 23, S / 10, SSD1306_WHITE);
display.display(); // Update the display
previousS = S;
}
// Update LEDs based on the analog reading
for (int i = 0; i < 10; i++) {
if (S >= 102.3 * (i + 1)) {
digitalWrite(i, HIGH); // Turn on LED
} else {
digitalWrite(i, LOW); // Turn off LED
}
}
}
// MADE BY ME WITH HELP FROM CHATGTP