NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.
Project Help and Ideas » Christmas Countdown Clock
December 04, 2015 by edSky |
Here is my Christmas Countdown Clock version 1.0 I use interrupts to process the button click that sets the current date/time. I modelled the setting of the time after a current LED watch called the Blink Time Watch. Hold the button for a few seconds and it enters "Set Year" mode. Then short presses increment the year. Hold long again and we go to "Set Month". Short clicks set the month. Repeat with Day, Hour, Minute and Seconds. The last long hold goes back to Run mode. I initially wanted to store the date/time as Year|DDD|Seconds where Seconds was Hours36+Minutes60+Seconds. I figured I could get the difference between current time and target time (i.e. Now and Christmas) by subtracting the two and using MODulus arithmetic to convert back to hh:mm:ss for display. This was to me the most intuitive from a mainframe or modern PC CPU point of view. It would simplify the code and I wouldn't have to "borrow" from minutes and hours and so on when subtracting. Turns out the code needed to do the "simple" math was over 4x as large as the long-hand accounting for time differences. I have been busy at my store (a toy store and this is prime time) so I haven't posted this until now. And I have a few to-do items. One is to automatically increment the year of the target (Christmas) when we actually count down to 0. Two is to do something fancy for the 24 hours of Christmas (or just display Merry Christmas). Three is to code in changes to and from Daylight Savings Time. I wanted to do this up front but figured I need to reset the time every other day or so because of drift. Five is to capture the moment of button-press and determine time-down so when you release the final mode change back to seconds it will negate the delay (i.e. it is 17:24:00 and I push the button now and hold for two seconds - when I release it is 17:24:03 not 17:24:00, but if I can add that time in...) (Four is something I can't remember or haven't even thought of yet.)
|
---|---|
December 04, 2015 by sask55 |
That is a very good looking display. Nice neat work on the code and the layout as well. |
December 04, 2015 by JKITSON |
Very neat. The code is easy to follow, thanks to notes. Good work & idea Jim |
December 04, 2015 by edSky |
Thanks. I can explain what I did if anyone has any questions. The 74LS14 is used to debounce the switch. I tried the various software debounce code folks were nice enough to share but I had such a hard time with reliability. It would work 90% of the time but 1 outta ten times when something jumped ahead it drove me nuts. Not knowing a lot about EE I had a hard time with this but I wrote another project to time bounces. The inverter is also used as an ancillary tool to alternate the Christmas lights. It's wasn't really important (but yeah, it is) to have lights, but what the heck. It's Christmas and even us old Jews have the spirit! So I had a second timer firing interrupts every quarter second and using it to control two bulbs - one every 1/4 second toggling on/off and and one every second. To be more festive I took advantage of the extra inverters and had one alternate bulb. The logic in the main() loop is primarily display logic. What I noticed early on in the earliest (years ago) examples was that values were displayed over and over even when they didn't change in successive passes. I try to check what happened last pass, and if nothing changed then no need to steal cycles and call an expensive routine to display something that is already being displayed (or any other action besides "displayed"). The problems I encountered, however, was that my logic didn't always work. Look, I've been coding since the 70's on and off at machine level so I have an inkling of an idea how to code. But this is the tiniest machine ever! Smaller than an 8080, 6502, etc! I'm not sure it was the compiler or the resources, but things didn't always work. It's a miracle this finally came together! Anyway, I tried to put as much logic and as little at the same time in the interrupt handler for the button. I think I was able to do that. It's all pretty much straightforward state-logic reacting to the button. Lastly, this is my first project I've contributed and I feel funny because while I bought my kit early I also changed careers from a life-long developer to a retail store owner. I had a lousy work experience with a big-name defense contractor in the government sector and turned my back on the avocation I loved for 3 decades. So for 5 years my Nerdkit sat collecting dust and I am so thankful this site is still operational. You guys are awesome. |
December 04, 2015 by edSky |
Thanks. I can explain what I did if anyone has any questions. The 74LS14 is used to debounce the switch. I tried the various software debounce code folks were nice enough to share but I had such a hard time with reliability. It would work 90% of the time but 1 outta ten times when something jumped ahead it drove me nuts. Not knowing a lot about EE I had a hard time with this but I wrote another project to time bounces. The inverter is also used as an ancillary tool to alternate the Christmas lights. It's wasn't really important (but yeah, it is) to have lights, but what the heck. It's Christmas and even us old Jews have the spirit! So I had a second timer firing interrupts every quarter second and using it to control two bulbs - one every 1/4 second toggling on/off and and one every second. To be more festive I took advantage of the extra inverters and had one alternate bulb. The logic in the main() loop is primarily display logic. What I noticed early on in the earliest (years ago) examples was that values were displayed over and over even when they didn't change in successive passes. I try to check what happened last pass, and if nothing changed then no need to steal cycles and call an expensive routine to display something that is already being displayed (or any other action besides "displayed"). The problems I encountered, however, was that my logic didn't always work. Look, I've been coding since the 70's on and off at machine level so I have an inkling of an idea how to code. But this is the tiniest machine ever! Smaller than an 8080, 6502, etc! I'm not sure it was the compiler or the resources, but things didn't always work. It's a miracle this finally came together! Anyway, I tried to put as much logic and as little at the same time in the interrupt handler for the button. I think I was able to do that. It's all pretty much straightforward state-logic reacting to the button. Lastly, this is my first project I've contributed and I feel funny because while I bought my kit early I also changed careers from a life-long developer to a retail store owner. I had a lousy work experience with a big-name defense contractor in the government sector and turned my back on the avocation I loved for 3 decades. So for 5 years my Nerdkit sat collecting dust and I am so thankful this site is still operational. You guys are awesome. |
December 05, 2015 by Ralphxyz |
Nice to see new projects, thanks for posting!! Nice project!! |
December 06, 2015 by Rick_S |
Had you given any thought to using a real time clock module? Just curious on that note. Great looking display and project. Just for curiosity's sake, where are you/your store located? Rick |
December 07, 2015 by edSky |
Rick, I thought about the real-time clock and have looked at some of the projects that use them. I wanted to get this done by Thanksgiving and being a programmer in a previous life everything looks like a software solution to me. Throw in a little fear of the unknown (finding a good two-wire library or whatever other code I would need) and I went the brute force route. I did look at SparkFun and other sites to see how easily I could source a real-time clock and integrate it painlessly. I made the decision that since it wasn't mission critical I would settle for a periodic clock adjustment. I managed to get this all working on a 168 so I'm happy with that. Debugging is also another issue. Using printf and the original Serial-USB dongle works but I would love to find an easy-to-read schematic to use the AVR-USB approach. If I can crack that nut then my next version will have that and a real-time clock and be on a 328 for good measure. Ed |
December 08, 2015 by Rick_S |
I think before I'd try to mess with the AVR-USB (V-USB) I'd just go with a microcontroller with built in USB support like the ATMEGA32U4 found on the Teensy. That way the USB is handled by an on-board peripheral instead of having to emulate it in software. That would leave a lot more overhead available for your program instead of all the dedicated time for the USB. The teensy has pretty good C libraries available and can even be programmed with the Arduino environment if desired. Also, you didn't mention where your store was. ?? Rick |
December 08, 2015 by Ralphxyz |
Have you ever tried Atmel Studio? It has a debugger. I have only played around with Atmel Studio it has been on my list of things to learn for a long time now. |
December 08, 2015 by edSky |
Rick, The store. It is in Little Rock, AR. Getting back to the Teensy, are the C libraries suitable to drop-in to our existing Nerdkits code/libs? I need to look at it some more and see if it comes in a form factor or dev board that exposes all the pins. What development environment do you use for it? I'd hate to go the dumbed-down Arduino C++ route if I didn't have to. I'd prefer C on these small machines. Ed |
December 09, 2015 by Rick_S |
Most of the code you compile for the nerdkit can be easily ported to the ATMEGA32u4 on the the teensy using AVR-GCC just like with the nerdkit. The only changes you may have to make would be the ports used and timing. The Teensy is clocked at 16MHz so the delay library the NK uses would not work without modification. Also, since the LCD library uses the delay library for its timing, it would only work if the NK delay library was modified to suit the AVR-GCC standard delays. Paul Stoffregen has C libraries for the USB portion of the chip so you don't really have to delve too deeply into that, just link his library and it works. It's really a nice little platform if you want USB serial built in. I built an Industrial inductive joystick to PC mouse control with them for the place I work. We have them running on 4 CNC Milling machines and a CNC Vertical Turret Lathe. You can see the photo's of the prototype (Before I had commercial PCB's made for them) and the writeup I sent Paul on his website HERE. It was all coded in straight C no Arduino at all. I'd pop in and check out your store if I lived a bit closer, but I live about 80 Miles SE of Chicago, so Little Rock would be a bit of a drive :D. |
December 10, 2015 by lnino |
Really nice Project, edSky. Thanks a lot for sharing. Maybe I have the time to make it. I definately have to share some of my projects when I finsihed them. I started so many projects, but most of them are unfinished. But the project which is almost finished is my "Text Adventure". |
December 14, 2015 by Ralphxyz |
edSky, since you are in Little Rock would you send me your email address. I have some unfinished business in Little Rock but I live on Long Island, NY. I'll fill in the details with email. Thanks, Ralph |
December 29, 2015 by edSky |
Ralph, Sorry I didn't reply sooner, this is my busy time and now it's getting back to normal. My email address is efigarsky at gmail.com I hope you and everyone on board had a Merry Christmas and wish you all a Happy New Year! Ed |
Please log in to post a reply.
Did you know that inductors try to keep their current constant over short periods of time? Learn more...
|