#include <Wire.h>
#include <RTClib.h>
#include <LedControl.h>
RTC_DS1307 rtc;
LedControl lc(D2, D3, D4, 1); // DIN, CLK, CS, numDevices
const int button1Pin = D9;
const int button2Pin = D10;
const int greenLedPin = D5;
const int redLedPin = D6;
// Custom characters (8x8 bitmaps)
byte A[8] = {
B00111100,
B01100110,
B11000011,
B11000011,
B11111111,
B11000011,
B11000011,
B11000011
};
byte B[8] = {
B11111110,
B11000011,
B11000011,
B11111110,
B11000011,
B11000011,
B11000011,
B11111110
};
byte C[8] = {
B00111110,
B01100011,
B11000000,
B11000000,
B11000000,
B11000000,
B01100011,
B00111110
};
void displayChar(byte letter[]) {
for (int i = 0; i < 8; i++) {
lc.setRow(0, i, letter[i]);
}
}
void setup() {
Wire.begin();
lc.shutdown(0, false);
lc.setIntensity(0, 8); // Brightness level (0–15)
lc.clearDisplay(0);
pinMode(button1Pin, INPUT_PULLUP);
pinMode(button2Pin, INPUT_PULLUP);
pinMode(greenLedPin, OUTPUT);
pinMode(redLedPin, OUTPUT);
Serial.begin(9600);
if (!rtc.begin()) {
Serial.println("RTC not found!");
while (1);
}
if (!rtc.isrunning()) {
Serial.println("RTC is not running, setting time...");
rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); // Set time from computer clock
}
}
void loop() {
DateTime now = rtc.now();
// Scheduled time: 12:00:00
if (now.hour() == 12 && now.minute() == 0 && now.second() == 0) {
displayChar(A);
digitalWrite(greenLedPin, HIGH);
delay(300);
digitalWrite(greenLedPin, LOW);
}
// Button 1 pressed: Display 'B'
if (digitalRead(button1Pin) == LOW) {
displayChar(B);
digitalWrite(redLedPin, HIGH);
delay(300);
digitalWrite(redLedPin, LOW);
}
// Button 2 pressed: Display 'C'
if (digitalRead(button2Pin) == LOW) {
displayChar(C);
}
delay(200);
}