#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
// Define OLED display width and height
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
// Initialize the OLED display with the I2C address (0x3C for most 128x64 displays)
#define OLED_RESET -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
void setup() {
// Start serial communication
Serial.begin(115200);
// Initialize the OLED display
if (!display.begin(0x3C, OLED_RESET)) { // Use 0x3C directly
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
// Clear the buffer
display.clearDisplay();
// Display a message
display.setTextSize(1); // Normal 1:1 pixel scale
display.setTextColor(SSD1306_WHITE); // Draw white text
display.setCursor(0, 0); // Start at top-left corner
display.println(F("Hello, World!"));
display.display();
}
void loop() {
// You can add code here to update the display with new content
// Example: Display a counter
static int counter = 0;
display.clearDisplay();
display.setCursor(0, 0);
display.print("Counter: ");
display.println(counter++);
display.display();
delay(1000); // Update every second
}