#include <TM1637Display.h> // Include the TM1637 library
#include "Button.h"
#include "AlarmTone.h"
#include "Clock.h"
#include "config.h"
const int SPEAKER_PIN = A3;
Button hourButton(A0);
Button minuteButton(A1);
Button alarmButton(A2);
AlarmTone alarmTone;
Clock clock;
TM1637Display display(2, 3); // Change these pin numbers to your TM1637 module pins
enum DisplayState {
DisplayClock,
DisplayAlarmStatus,
DisplayAlarmTime,
DisplayAlarmActive,
DisplaySnooze,
};
DisplayState displayState = DisplayClock;
long lastStateChange = 0;
void changeDisplayState(DisplayState newValue) {
displayState = newValue;
lastStateChange = millis();
}
long millisSinceStateChange() {
return millis() - lastStateChange;
}
void displayTime() {
DateTime now = clock.now();
int hour = now.hour();
int minute = now.minute();
int displayValue = hour * 100 + minute;
display.showNumberDecEx(displayValue, 0b01000000, true); // Show colon in the middle
}
// Modify other display-related functions accordingly
void setup() {
Serial.begin(115200);
clock.begin();
hourButton.begin();
hourButton.set_repeat(500, 200);
minuteButton.begin();
minuteButton.set_repeat(500, 200);
alarmButton.begin();
alarmButton.set_repeat(1000, -1);
alarmTone.begin(SPEAKER_PIN);
display.setBrightness(7); // Adjust brightness level
// No need for pinMode(COLON_PIN, OUTPUT) for TM1637
// ... Rest of your setup code ...
}
void loop() {
display.setBrightness(7);
switch (displayState) {
case DisplayClock:
clockState();
break;
case DisplayAlarmStatus:
alarmStatusState();
break;
case DisplayAlarmTime:
alarmTimeState();
break;
case DisplayAlarmActive:
alarmState();
break;
case DisplaySnooze:
snoozeState();
break;
}
delay(100); // Add a short delay to prevent flickering
}