Home Creators Posts Import Register Favorites Logout

Content

This is a short extension to my previous video on LED displays to show how, instead of displaying an arbitrary countdown from 5000-0, you can create a timer to display a time in mm:ss format. 

The timing loop has also been adjusted - instead of relying on delay(), the loop now tests the interrupt-driven millis() function, which should be able to time accurately to well within 1 second over a 1-hour period.

The Arduino code is available at https://drive.google.com/open?id=16ZBwdX-ZHmuyB9QBRQUsWCQ3RoKBgID2

Files

4-Digit Countdown Timer (in minutes and seconds)

In this video, I'll demonstrate a slight modification to my previous Arduino TM1637 4-digit LED display code (from this video: https://www.youtube.com/watch?v=aBUnAhrSVu0) so that, instead of just counting down integer values from 5000 - 0, it shows a timer counting down from one hour, displaying the value in mm:ss format. I'm using an Arduino Nano and a TM1637 4-digit 7-segment display. The Arduino code is available on my Patreon page here: https://www.patreon.com/playfultech

Comments

Matt

I installed the library and tried to compile the program and got this:Arduino: 1.8.5 (Windows Store 1.8.10.0) (Windows 10), Board: "Arduino/Genuino Uno" In file included from C:\Users\Alison\Downloads\CountdownTimer\CountdownTimer.ino:9:0: C:\Users\Alison\Documents\Arduino\libraries\TM1637-master/TM1637Display.h:30:1: error: expected unqualified-id before 'class' class TM1637Display { ^ C:\Users\Alison\Documents\Arduino\libraries\TM1637-master/TM1637Display.h:30:1: error: expected constructor, destructor, or type conversion before 'class' CountdownTimer:18: error: 'TM1637Display' does not name a type TM1637Display display(2,3); ^ C:\Users\Alison\Downloads\CountdownTimer\CountdownTimer.ino: In function 'void setup()': CountdownTimer:26: error: 'display' was not declared in this scope display.setBrightness(0x0c); ^ C:\Users\Alison\Downloads\CountdownTimer\CountdownTimer.ino: In function 'void countdown()': CountdownTimer:42: error: 'display' was not declared in this scope display.showNumberDecEx(seconds, 0, true, 2, 2); ^ C:\Users\Alison\Downloads\CountdownTimer\CountdownTimer.ino: In function 'void displayText()': CountdownTimer:51: error: 'display' was not declared in this scope display.setSegments(PLAY); ^ exit status 1 'TM1637Display' does not name a type This report would have more information with "Show verbose output during compilation" option enabled in File -> Preferences.

Matt

The other sketch works

Matt

Installed the library properly as the sketch from the earlier led display post works and compiles perfectly. Confusing.

Alastair Aitchison

Hmm, odd. Just a thought - are you placing this .ino file in the same directory as the first one, or in a directory all of its own (with a matching name)?

Matt

They're all in my downloads folder

Matt

Just checked it's in a different folder.

Matt

Sorry I should say I love your videos etc, don't mean to be a pain just would really love to be able to get a timer to work.

Matt

Sorry about all that mate, tried it on a different computer and it worked. Feel like a wally now

Jeff Danevich

Alastair, Hi can you check these out these LED from Spark Fun <a href="https://www.sparkfun.com/products/13667" rel="nofollow noopener" target="_blank">https://www.sparkfun.com/products/13667</a> and see if they will work in place of the ones you suggest. I can't get those in the US from your link and tried some other ones on EBay and they are not lighting up. I am able to get the relay to work by changing the code to 0,9,9 so I could figure out which way to turn since I had no lights as a guide. Thanks for posting these projects. Jeff

Jake

Hi Alastair. I got the countdown to work with no problems, thanks. What should I write in the void loop section if I want to write a pin high when the count reaches 0? Jakob

Jake

Also, the count starts over and over again, never stopping at 0. Is it suppose to do that?

Jake

Thank you so much Alastair - got it to work!

Joff Bullock

Hi Alastair! I've got your countdown working but when it reaches 0 it then counts down from 2:47 and once that reaches 0 it then counts down from 60 mins (no matter what the 'unsigned long' value is). i've tried your above recommendations but they don't seem to work, can you help?

Joff Bullock

Hi Alastair, just re-downloaded your code and tried again with the above, still resetting countdown to 2:47 once the countdown ends though, very strange! I don't suppose it would have anything to do with the library installation?

Griffin Trenbeath

I must be an idiot. Nothing is working at all. I tried all the above.]\

Griffin Trenbeath

Thanks sir, but all is good and working great now. This part of the instructions put a random IDE TM1637 in the library that took priority over the avishorp. b.) Then, in the Arudino IDE go Sketch -> Include Library -> Manage Libraries to refresh the list of installed libraries

SSI

Have you ever do Timing Display using Panel 16x32 P3 connected to Arduino Shield & RTC? if you have done before. Would you share me your coding. I have task from university make Timing Display Panel (h:m:s PM/AM)

Nathan Bekker

What would i need to change in order to countdown in seconds and ms increments?

Giorgio Filardi

Dear Alastair I did all the above still restarts at 2:47 the first time and then at 59:59

rutvik g

HI Alastair! Firstly, thanks for your program. I edited your program such that the countdown begins from 5 mins but it loops again from 2:47 then 1 hour( the same as @Joff Bullock) . Could you plss help?

rutvik g

Thank you so much, it worked!

Frei Eva-maria

i have a question. How can i insert in the code a action after the countdown is running out? can you give me a example.

mark dennis

I have a code similar to this one, but I am having trouble with getting out of it. I want the timer to run and once the gamers have solved the problem, how can they stop the timer early so that they can continue the game? Any help would be greatly appreciated!!!

PierreG

How can i have the timer start after a button press, and not as soon as the arduino boot?

alexandra Mora

Hi Alastair I'm learning Arduino, I'm not programming person, but I study electronic 20 year ago, my questions is I want to Add a 4x4 keypad to choose how many time I want to, and pressing # to start the timer and * to stop it, any advise ?

Michel Bouchard

Hi, your tutorials are juste amazing! I have a question for you: i would like to start the timer by using a rfid tag. is it easy to do ? thanks.

Anthony Claughan

Hi, quick one.... I've wired the Arduino and downloaded the code, all works but I've got no colon in between the mm & ss

R

Hi Alastair, what would I need to include in the code for the timer to stop upon a button press? Many Thanks

Greg Pare

How would I add a normally open button to simply stop the timer?

Greg Pare

Timer is working great! Just need to stop

Phil Ritter

Hi, I got a restart after 4 seconds by only changing the the data pin to 4 (using a Wemos D1 mini)

Jochem Beumer

Hi, I was trying this code with an ESP8266MOD, the countdown stops at 5956 and starts over. Also the colon between mm & ss is not working. Are these issues related to the board or can I solve this in code?

Ryan Vervack

Alastair, your channel is fantastic! One note -- in the countdown code, I would recommend changing the timeRemaining to a signed long; as written it's very likely that you will never actually hit 0 and therefore the while loop will continue after the timer should have ended.

Manuel Garcia

hi Alastair one question in the video, the gray cable that joins RFID module with Arduino. what is?