#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
/* ===== OLED CONFIG ===== */
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_ADDR 0x3C
#define OLED_SDA_PIN 7
#define OLED_SCL_PIN 6
#define BUTTON_PIN 5
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
void setup() {
pinMode(BUTTON_PIN, INPUT_PULLUP);
Wire.begin(OLED_SDA_PIN, OLED_SCL_PIN);
if (!display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR)) {
while (true);
}
display.setRotation(1);
display.clearDisplay();
display.display();
}
void loop() {
display.clearDisplay();
display.drawRoundRect(0, 0, 64, 128, 6, SSD1306_WHITE);
if (digitalRead(BUTTON_PIN) == LOW) {
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
const char* text = "PRESS";
int16_t x1, y1;
uint16_t w, h;
display.getTextBounds(text, 0, 0, &x1, &y1, &w, &h);
int padding = 6;
int boxX = (64 - w) / 2 - padding;
int boxY = (128 - h) / 2 - padding;
int boxW = w + padding * 2;
int boxH = h + padding * 2;
display.drawRoundRect(boxX, boxY, boxW, boxH, 5, SSD1306_WHITE);
display.setCursor(boxX + padding, boxY + padding);
display.println(text);
}
display.display();
delay(50);
}