#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 BTN_PIN 5 // Assuming the push button is connected to GPIO pin 5
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
const char* messages[] = {
"Assalamualaikum",
"Apa Kabar Niih?",
"Semoga Baik yaaaa",
" Tidak Banyak yang Ingin",
"disampaikan Perihal rasa yang pernah ada",
" yang belum tersampaikan",
"I Love You"
};
int currentMessageIndex = 0;
void setup() {
Serial.begin(115200);
pinMode(BTN_PIN, INPUT_PULLUP); // Set the push button pin as input with internal pull-up resistor
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
Serial.println(F("SSD1306 allocation failed"));
for (;;);
}
delay(300);
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0, 0);
display.println(messages[currentMessageIndex]);
display.display();
}
void loop() {
if (digitalRead(BTN_PIN) == LOW) { // Check if the button is pressed
delay(1000); // Debounce delay
currentMessageIndex = (currentMessageIndex + 1) % (sizeof(messages) / sizeof(messages[0]));
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0, 0);
display.println(messages[currentMessageIndex]);
display.display();
}
}