#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <ssd1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for SSD1306 OLED display connected using I2C (SDA, SCL pins)
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
void setup() {
// Initialize serial communication for debugging
Serial.begin(9600);
// Initialize the OLED display
if(!display.begin(SSD1306_PAGEADDR, 0x3c)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
// Clear the buffer
display.clearDisplay();
// Display a welcome message
display.setTextSize(1); // Normal 1:1 pixel scale
display.setTextColor(SSD1306_WHITE); // Draw white text
display.setCursor(30, 30); // Start at top-left corner
display.println(F("Hello, world!"));
display.display(); // Display the buffer
delay(2000); // Pause for 2 seconds
// Clear display and draw shapes
display.clearDisplay();
display.drawLine(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, SSD1306_WHITE);
display.drawLine(SCREEN_WIDTH, 0, 0, SCREEN_HEIGHT, SSD1306_WHITE);
display.display(); // Show the buffer on the screen
delay(2000);
}
void loop() {
// You can add more code here to update the display or show animations
display.clearDisplay();
// Display a welcome message
display.setTextSize(1); // Normal 1:1 pixel scale
display.setTextColor(SSD1306_WHITE); // Draw white text
display.setCursor(30, 30); // Start at top-left corner
display.println(F("Hello, world!"));
display.display(); // Display the buffer
delay(2000);
}