/*
ESP32-C3_Mini Mothers Day Trinket
5/6/26
*/
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <MD_MAX72xx.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)
// GPIO pin numbers
const int BTN_PIN = 10;
const int CS_PIN = 2;
const int CLK_PIN = 3;
const int DATA_PIN = 4;
// button debounce
const uint32_t DEBOUNCE_TIME = 20;
// heart gfx
const byte SM_HEART[8] = {
0x0, 0x0, 0x24, 0x5A, 0x24, 0x18, 0x0, 0x0
};
const byte LG_HEART[8] = {
0x24, 0x5A, 0x81, 0x81, 0x42, 0x24, 0x18, 0x00
};
Adafruit_SSD1306 oled(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
MD_MAX72XX mx = MD_MAX72XX(MD_MAX72XX::PAROLA_HW, DATA_PIN, CLK_PIN, CS_PIN, 1);
void checkButton() {
static uint32_t lastTime = 0;
static bool lastState = HIGH;
bool currentState = digitalRead(BTN_PIN);
uint32_t now = millis();
if (currentState != lastState && now - lastTime >= DEBOUNCE_TIME) {
if (!currentState) {
Serial.println("Button pressed!");
drawLargeHeart();
oled.setCursor(20, 10);
oled.print("Love you");
oled.setCursor(30, 40);
oled.print("Mom !!!");
oled.display();
} else {
Serial.println("Button released!");
drawSmallHeart();
oled.clearDisplay();
oled.display();
}
lastTime = now;
lastState = currentState;
}
}
void drawSmallHeart() {
mx.clear();
for (int i = 0; i < 8; i++) {
mx.setRow(i, SM_HEART[i]);
}
mx.update();
}
void drawLargeHeart() {
mx.clear();
for (int i = 0; i < 8; i++) {
mx.setRow(i, LG_HEART[i]);
}
mx.update();
}
void setup() {
Serial.begin(115200);
if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;); // Don't proceed, loop forever
}
oled.setTextSize(2);
oled.setTextColor(SSD1306_WHITE, SSD1306_BLACK);
mx.begin();
mx.control(MD_MAX72XX::INTENSITY, MAX_INTENSITY / 2);
pinMode(BTN_PIN, INPUT_PULLUP);
oled.clearDisplay();
oled.display();
Serial.println("\nWelcome :-)\n");
drawSmallHeart();
}
void loop() {
checkButton();
}