This morning, I put the finishing touches on my project: The Crazy Countdown Timer.
This project emulates the cheesy "time bomb" that is often seen in movies. The hero finds the bomb, and then is faced with the decision of which wire to cut.
The clock counts down the time until the timer hits 0, at which point an action happens (a green LED goes on), and it flashes 00:00 in a panicky way.
For our timer, we have 3 wires to choose from. Cutting (disconnecting) the blue wire stops the timer; cutting the red wire starts "panic mode" where the timer flashes and counts down faster; and cutting the yellow wire immediately drops the time to 0 (in other words, bad news!).
To make things trickier, the board senses motion. The first time the board is bumped, the timer goes into "panic mode". If it is bumped again, it drops to 0 (bad news again!).
What the hero of our bad movie didn't know is that there are 3 buttons that allow time to be incremented by seconds (SW1), minutes (SW2), and hours (SW3).
This timer has many other potential uses. For example, it could run a sprinkler at a preset intervals.
Attached are the complete project source code, two pictures of the resulting project, and an image showing the connections that need to be made.
edit: video is in my next blog post: http://www.element14.com/community/people/ntewinkel/blog/2011/08/30/video-for-crazy-countdown-timer
Parts list:
1 XL_Star board from Element14
1 Liteon LTC-617D1G clock display (or similar)
18 F-F jumper wires
3 male headers
1 jumper (the type that connects 2 pins)
Procedure:
1. Solder headers onto the XL_Star board and onto the clock display, so that connections can be made with jumper wires.
2. Create a pin expander to allow multiple connections to be made to 1 GND pin:
- Solder the jumper onto the small end pin of a small segment of header - I used a 5 pin segment.
- Then solder a wire across the small ends to connect all the pins.
- Now place the jumper onto the GND pin, and viola - you can connect multiple wires to GND!
3. Make connections to the clock display as shown in the file LTC-617 connections, using the jumper wires.
- I used the GND that is on the same side of the board as all the other connections. This leaves one GND pin available on the other side for the "crazy wires".
4. Connect the 3 "crazy wires", from PTE2 (blue), PTE3 (yellow), and PTE4 (red) to the pin expander on GND.
5. Import the attached project into CodeWarrior and run it on the XL_Star board.
Running the Crazy Countdown Timer:
* When you apply power, the timer starts counting down from 30 seconds.
* Increase seconds with SW1; increase minutes with SW2, increase hours with SW3
* When counting down, the clock display will show:
- If more than an hour is left on the timer it will display hours:minutes with the alarm dot (lower right for display) flashing every second
- If less than an hour is left, the display will show minutes:seconds
* When the timer reaches zero, it will do an action and then start flashing 00:00. The action in this case is just to light the green LED marked "8 bit"
* The 3 LEDs "Freefall", "Transient", and "Orientation" are lit up when the crazy wires are hooked up properly.
* Crazy Wire actions:
- Cutting (disconnecting) the blue wire stops the timer
- Cutting the red wire starts "panic mode" where the timer flashes and counts down faster
- Cutting the yellow wire immediately drops the time to 0 and does the action.
* Motion:
- Bumping the board once starts "panic mode"
- Bumping the board again drops the time to 0 and does the action.
The source code illustrates the following features:
* Lighting a single green LED - see do_action()
* Lighting an array of LEDs - similar to the XL_Star demo, but shows more detail in lighting specific LEDs within the array
* Detecting motion using the accelerometer:
- a simple yes/no detection of motion
- easy adjustment of sensitivity (adjust the #define'd SENSITIVITY - lower number = more sensitive)
* Controlling a clock display using multiplexing, notably:
- There are not enough connections to light all digits at once, so each digit is lit for a set amount of time. This is done so quickly that to the naked eye it looks like all are on.
- Digits are all lit evenly - the more segments are lit in a digit, the dimmer it gets. To compensate, digits with more segments are shown a little longer.
* Timing: semi-accurately times seconds - it loses a tiny bit of time running code that is outside of the timed loop, and the code in the timed loop is likely to run into a bit of overtime.
* Use of inputs (for the crazy wires)
* Use of buttons