#include <Wire.h> // Include the I2C library
#include <Adafruit_GFX.h> // Include the GFX library
#include <Adafruit_SSD1306.h> // Include the SSD1306 OLED library
#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
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); // Create an OLED object
void setup()
{
// Initialize the OLED display
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C))
{ // Initialize with I2C address 0x3C
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Infinite loop if the display isn't found
}
display.clearDisplay(); // Clear the display buffer
display.setTextSize(1); // Set text size to normal (1)
display.setTextColor(SSD1306_WHITE); // Set text color to white
display.setCursor(0, 0); // Set the cursor to top-left corner
display.print(F("Hello World!")); // Print the string on the display
display.display(); // Update the OLED to show the message
}
void loop()
{
// Nothing to do in the loop for this example
}