#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
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define BUTTON_PIN 2 // Change this to the pin connected to your button
void setup() {
Serial.begin(9600);
// SSD1306 display initialization
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;);
}
// Clear the buffer
display.clearDisplay();
// Button pin setup
pinMode(BUTTON_PIN, INPUT_PULLUP); // Using internal pull-up resistor
}
void loop() {
// Check if the button is pressed
if (digitalRead(BUTTON_PIN) == LOW) {
display.clearDisplay(); // Clear the display
display.setTextSize(1); // Set text size
display.setTextColor(SSD1306_WHITE); // Set text color
display.setCursor(0, 0); // Set cursor position
display.setCursor(0, 0); // Set cursor position
display.println("Button pressed!"); // Print first line
display.println(); // Print one line space
display.println("Welcome Nyruthi "); // Print second lin
display.display(); // Display the message
delay(1000); // Delay to debounce the button
}
}