#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for SSD1306 display connected using I2C
#define OLED_RESET -1 // Reset pin
#define SCREEN_ADDRESS 0x3C
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
void setup()
{
Serial.begin(115200);
// Initialize the OLED object
if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS))
{
Serial.println(F("SSD1306 allocation failed"));
for (;;)
{
// Don't proceed, loop forever
}
}
// Clear the buffer.
display.clearDisplay(); // Clear the display
}
void loop()
{
// Display Text
display.setTextSize(1); // Set font size to 1
display.setTextColor(WHITE); // Set text color to white
display.setCursor(0, 28); // Set cursor position (x, y)
display.println("Hello world!"); // Print "Hello world!"
display.setTextSize(2); // Set font size to 2
display.setCursor(0, 42); // Set cursor position (x, y)
display.println("ESPUA OLED"); // Print "ESPUA OLED" with increased font size
display.display(); // Update the display
delay(2000); // Delay for 2 seconds
display.clearDisplay(); // Clear the display
// Display Text
display.setTextSize(1); // Set font size to 1
display.setTextColor(WHITE); // Set text color to white
display.setTextWrap(true); // Enable text wrapping
display.setCursor((SCREEN_WIDTH - 12 * 6) / 2, (SCREEN_HEIGHT - 8) / 2); // Center the cursor both horizontally and vertically
display.println("Hello world!"); // Print "Hello world!"
display.setCursor((SCREEN_WIDTH - 11 * 6) / 2, (SCREEN_HEIGHT + 8) / 2); // Center the cursor both horizontally and vertically
display.println("ESPUA OLED"); // Print "ESPUA OLED" with increased font size
display.display(); // Update the display
delay(2000); // Delay for 2 seconds
display.clearDisplay(); // Clear the display
}