#include <PCM.h>
#include <Wire.h>
#include <DS3231.h>
#include <BasicTimer.h>
DS3231 clock;
BasicTimer timer;
PCM audio;
const int speakerPin = 9; // Use any digital pin you like for the speaker
const unsigned long playInterval = 300000; // Play time every 5 minutes (300,000 milliseconds)
void setup() {
pinMode(speakerPin, OUTPUT);
Serial.begin(9600);
clock.begin();
timer.every(playInterval, playCurrentTime);
}
void loop() {
timer.update();
}
void playCurrentTime() {
int currentHour = clock.getHour();
int currentMinute = clock.getMinute();
// Convert the current time to a string
char timeString[6];
sprintf(timeString, "%02d:%02d", currentHour, currentMinute);
Serial.print("Playing time: ");
Serial.println(timeString);
// Play the time using the PCM library
playTime(timeString);
}
void playTime(const char *timeString) {
for (int i = 0; timeString[i] != '\0'; i++) {
if (timeString[i] == ':') {
// Play a colon sound
audio.play("colon.wav");
} else if (timeString[i] >= '0' && timeString[i] <= '9') {
// Play the corresponding digit sound
char fileName[8];
sprintf(fileName, "%c.wav", timeString[i]);
audio.play(fileName);
}
// Delay to separate the sounds
delay(1000);
}
}