This is a timer that can be used as a countdown timer for any purpose but was created to use when playing games. Once you set the turn duration, using the up and down buttons, simply press go when the turn starts and the timer will beep, the display will show "go" and the countdown will start. The countdown will display after 3 seconds. When the time is up, "End" will be displayed and a longer beep sounded. After 5 seconds the set duration will be redisplayed for the start of the next players turn.
The duration can be from a few seconds to 99 minutes and clearly it can be used as a timer for any purpose.
The up and down buttons can be held down to repeatedly change the time, above 60 seconds the increment is increased to 10 seconds.
CircuitThe circuit is straightforward.
The 3 momentary switches connect pins D2, D3 and D4 to ground when pressed. The pins are set to INPUT_PULLUP, hence are normally HIGH and go LOW when a button is pushed.
The buzzer is connected to pin 9.
The 4 digit LED display has 4 connections.
- VCC to +5v
- GND to GND
- CLK to pin 6
- DIO to pin 7
I am using a 4 digit 7 segment LCD display with a TM1637 driver. The one I used was a Youmile DR-YM-174, but any make should work.
The programThe program uses a library to drive the 4 digit display. I am using the library TM1637 v.1.2.0 by Avishay Orpaz.
The constants seg_go and seg_end define the segments that light to display the words "go" and "end".
The duration of the timer is held in a variable called "duration" and is set to 30 seconds by default in setup.
ShowTime() takes a single parameter of the time in seconds to display. If more than a second has elapsed since the last call, the time is displayed using the call display.showNumberDecEx(number, 0b01000000, true, 4, 0). The second parameter turns on the dividing colon and the third displays leading zeros.
WaitForStart() contains a while loop that repeats until the start button is pressed. In the repeat the up and down buttons are checked and, if pressed, the duration changed. When the start button is pressed, "go" is displayed by the call to display.setSegments(seg_go) and the busser sounded.
TimeDuration() is then called which calls the time display in a loop until the time is up, after which it displays "End" and sounds the buzzer.
After a 5 second pause, the process repeats.
Comments