#include <Wire.h> // Include the Wire library for I2C communication
#include <Adafruit_GFX.h> // Include the Adafruit GFX library for graphics support
#include <Adafruit_SSD1306.h> // Include the Adafruit SSD1306 library for OLED support
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1 // Reset pin (not used with I2C)
#define OLED_ADDR 0x3C // I2C address of the OLED display (default is 0x3C or 0x3D depending on your module)
// Create an instance of the OLED display
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
void setup() {
// Initialize serial communication for debugging (optional)
Serial.begin(9600);
// Initialize the OLED display using I2C
if (!display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR)) { // Corrected line
Serial.println(F("SSD1306 allocation failed"));
for (;;); // Infinite loop if OLED is not found
}
// Clear the buffer (clear the display)
display.clearDisplay();
// Set text size and color
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0); // Start at the top-left corner of the display
// Display a message
display.println(F("Hello, World!"));
// Draw a simple line
display.drawLine(0, 10, 128, 10, SSD1306_WHITE);
// Show everything on the screen
display.display();
}
void loop() {
// Nothing to do here
}