#include <Wire.h>
#include <RTClib.h>
#include <TM1637Display.h>
#include <Keypad.h>
RTC_DS3231 rtc;
const int CLK = 13; // Pin CLK TM1637
const int DIO = 12; // Pin DIO TM1637
TM1637Display display(CLK, DIO);
const byte ROW_NUM = 4; // four rows
const byte COLUMN_NUM = 4; // four columns
char keys[ROW_NUM][COLUMN_NUM] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte pin_rows[ROW_NUM] = {9, 8, 7, 6}; // connect to the row pinouts of the keypad
byte pin_column[COLUMN_NUM] = {5, 4, 3, 2}; // connect to the column pinouts of the keypad
Keypad keypad = Keypad(makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM);
void setup() {
Serial.begin(9600);
if (!rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
if (rtc.lostPower()) {
Serial.println("RTC lost power, let's set the time!");
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
display.setBrightness(0x0f);
}
void loop() {
char key = keypad.getKey();
DateTime now = rtc.now();
int hours = now.hour();
int minutes = now.minute();
if (key) {
// Jika tombol ditekan, tampilkan di TM1637
display.showNumberDec(key - '1');
int formattedTime = (hours *100) + minutes;
display.showNumberDecEx(formattedTime, 0b11100000, true);
delay(10000); // Tampilkan selama 1 detik (sesuaikan sesuai kebutuhan)
display.clear();
}
// Format the time as HH:MM
// Display the time on TM1637
// Update every second
}