I have been working a little on the clock recently. And while I don’t have access to components to extend the functionality of the clock on the hardware side, I have been busy on the software functionality.
I have updated the github repo to the latest version I have running.
The hardware setup has not changed at all. Maybe next week I will add a button or two, but for now, that’s it. I will need to purchase additional components on my own.
First things first :
unsigned int isn’t large enough to hold time.
long int is the better choice.
Running a melody in the main loop effectively blocks the timekeeping functionality of the arduino for the duration of the melody. After spending some time on this problem, I worked around it by not including the alarm in the main loop. Instead, the main loop keeps track of where in the melody I am, and invokes an alarm function to only play the next note in the melody and return to the main loop. While the alarm function is playing, the display isn’t updated. But since each note lasts for less than a second, I always have some time to update the display to the latest time (at a least count of seconds) before going to the next note. As of now, the alarm is set to trigger at 05:00:00 every day, and run for 10 minutes.
I have also started working on date keeping. As of now, its a simple thing. It keeps count of the day of the week, date, month, and year. It was a challenge to update date. Just incrementing date by 1 at 00:00:00 works in theory, but only if you forget that arduino counts milliseconds. So, in practice, it adds around a thousand values to date if that’s your only condition. I couldn’t really figure out how to update it only at the instant the time overflows from 23:59:59 to 00:00:00. Instead, I chose to start keeping a flag. The date is only incremented if its 00:00:00 AND a flag variable is 0. Whenever I increment the date, I set the flag variable to 1 so it doesn’t trigger increment again. I set the flag variable to 0 whenever the alarm fires, so its primed to trigger the date increment again at the next overflow of time.
Things still to do :
- Add an update button to override the 10 minute duration of the alarm
- Get a better melody for the alarm, and code it in
- Account for leap years in the calendar
- Upgrade time keeping with quartz or RTC
More long term goals include extending the number of pins on the board, hopefully with a home made shield; a battery; maybe more buttons so I can adjust time without hardcoding into the program; networking (maybe update time from the internet, and remotely push commands to the microcontroller); ability to command a motor (so I can open my apartment over the network); a thermometer sensor, and finally, an array of 7 segment displays.
Here’s it in action !
- I feel cold
- Your Friendly Neighborhood Kitchen Admin?