Stopwatch Timer For 30 Minutes

0 views
Skip to first unread message

Gualberto Estrada

unread,
Aug 5, 2024, 12:37:06 AM8/5/24
to cuepelsiti
Setthe hour, minute, and second for the online countdown timer, and start it. Alternatively, you can set the date and time to count days, hours, minutes, and seconds till (or from) the event. The timer triggered alert will appear, and the pre-selected sound will be played at the set time.

This equation calculates the time the button was pressed plus some integer amount of time (in minutes). Then it takes the difference between that calculated time and now() in minutes. This is a negative value equal to setup_TimeAllotted untiil we run out of time. To make the timer appear as a countdown timer I take the absolute value of this result.


I am trying to implement on my prototype a stopwatch in a format 00(hr):00(min):00(sec).

When start button clicked it is supposed to start counting seconds and minutes and stop counting when stop button clicked.

Stopwatch should display how much time passed between start and stop e.g. 00:10:00 if stop button clicked in 10 min. Any help will be appreciated.

Thanks!


[ul]

[li]v_startTime: the time captured by Now.getValue() upon pressing start[/li][li]v_timeSpan: milliseconds elapsed since pressing start, i.e., Now.getValue() minus v_startTime[/li][/ul]

Since v_timeSpan is a straight-up number rather than a time format, it will be easy to perform math on. That math will be converting v_timespan into the various units of you clock: seconds, minutes, hours.


[ul]

[li]Seconds: Math.floor(v_timeSpan/1000) % 60[/li][li]Minutes: Math.floor(v_timeSpan/1000/60) % 60[/li][li]Hours: Math.floor(v_timeSpan/1000/60/60)[/li][/ul]

Math.floor() rounds whatever is in the parentheses down to the nearest integer.


The modulus operator (%) is similar to the division operator, except it returns only the remainder of the division (here by 60) and leaves out the quotient. This insures that both minutes and seconds will start over at zero when the number would have otherwise resulted in 60+ value.


I know there are a lot of answers, but I just want to post something very close to OP's question, that personally I would accept as indeed "oneliner countdown in terminal". My goals were:


If one wants a signal when it hits zero, one could e.g. build it with a command that returned a non-zero exit status at zero and combine it with watch -b, or something, but if one wants to build a more elaborate script, this is probably not the way to go; it is more of a "quick and dirty one-liner" type solution.


I have combined terdon's very good answer, into a function which at the same time displays the time since the start, and the time till the end. There are also three variants, so it's easier to call (you don't have to do Bash math), and it's also abstracted.


I'm surprised that nobody used the sleepenh tool in their scripts. Instead, the proposed solutions either use a sleep 1 between subsequent timer outputs or a busy loop that outputs as fast as possible. The former is inadequate because due to the small time spent doing the printing, the output will not actually happen once per second but a bit less than that which is suboptimal. After enough time passed, the counter will skip a second. The latter is inadequate because it keeps the CPU busy for no good reason.


The script can either be used as a stop watch (counting up until interrupted) or as a timer that runs for the specified amount of time. Since the sleep command is used, this script allows to specify the duration for which to count in the same precision as your sleep allows. On Debian and derivatives, this includes sub-second sleeps and a nice human-readable way to specify the time. So for example you can say:


The advantage of sleepenh is, that it is able to take into account the small delay that accumulates over time from the processing of other things than the sleep during a loop. Even if one would just sleep 1 in a loop 10 times, the overall execution would take a bit more than 10 seconds because of the small overhead that comes from executing sleep and iterating the loop. This error slowly accumulates and would over time make our stopwatch timer more and more imprecise. To fix this problem, one must each loop iteration compute the precise time to sleep which is usually slightly less than a second (for one second interval timers). The sleepenh tool does this for you.


cat /dev/zero produces an infinite amount of ASCII zero (\0) characters. pv displays progress, rate limits the data flowing through it and terminates after 60 characters (details below). Finally, the redirection to /dev/null makes sure that the \0 characters are not sent to the terminal.


Found this question earlier today, when looking for a term application to display a large countdown timer for a workshop. None of the suggestions was exactly what I needed, so I quickly put another one together in Go:


The timer is working as it should according to the instructions, but the only problem is it counts down in seconds, not minutes and seconds (e.g."110" instead of "1:50"), which is the norm for the bomb timers on film/tv.


I am totally new to both Arduino and electronics in general and I feel like I have jumped in at the deep end. If anyone could have a look at the code and make any suggestions as to how I might change the output on the display to minutes & seconds instead of just seconds that would be a massive help.


"This is an example of how to drive a 7 segment LED display from an ATmega

without the use of current limiting resistors. This technique is very common

but requires some knowledge of electronics - you do run the risk of dumping

too much current through the segments and burning out parts of the display.

If you use the stock code you should be ok, but be careful editing the

brightness values."


I'll paste in the code I've written for counting down. Basically decrement the ones_seconds by 1, when it hits 0 decrement the tens seconds, when that hits zero decrement the one_minutes, when that hits 0 decrement the tens_minutes.

Add some if statements to rollover the digits back up to 5 or 9 as needed.


Here's my time checking & digit update code.

It also flashes some Colon LEDs on/off at 1/4 second intervals so have immediate visual feedback that it's running. Watching 1 second pass with nothing happening is really boring...


Then I have another section that checks if updated == 1 and updates the display.

I use a MAX7221 to control my digits, the sparkfun code does it segment by segment.

This board here uses 4 high current shift registers to drive the segments with no multiplexing. I can sell you a bareboard for $4.50 and you can build it up without the SD card and RS232 parts.

960720 188 KB


No, you certainly can.

The design you started with I believe works by lighting up one segment of each digit one at a time, cycling thru the 4 digits.

My code gives you the means to count down the time as you requested.


The reason I ask is that I have been tasked with creating a countdown timer for my FIL's train club. They essentially want a 30 min countdown timer for some efficiency runs with a large (>2") digit display. I have been putting things together and came across this post. If it does use the TPIC6B595 it would be an ideal carrier as I will be using 4 of them to run the digits, as they need 9-12v, and it would save me a lot of time with breadboards etc.


Filmie, is this the sort of thing you're after? If so, you can have my code under the Beerware licence Although I think Crossroads is probably doing things in a similar way to me, regarding timekeeping variables etc.


CrossRoads:

Yes, uses TCIP6B595, nice chip for driving higher voltage digits.

I have to check to see if I have any left.

You need a bare board that you populate yourself? Or a fully populated board?


Oh, you may be in luck! I've ordered more boards, and at the same time tracked down some previously delivered boards that hadn't been built up yet.

Hopefully will have one mailed back to me on Saturday, can send to you Tuesday/Wednesday after it arrives.

You can get parts for it here inexpensively:

16 MHz xtal, two 22pf caps

7805

two 10uf caps for power filter

eight 0.1uF caps for decoupling

'328P if you need one

5mm screw terminals

10k reset resistor

current limit resistors for LEDs

Header pins for programming -

ICSP if needed,

FTDI if needed,

Header pins & 2 jumpers to select FTDI interface if needed

None needed if you program off board and put the 328 in a socket.

Pain in the ass for debugging - preferable to at least put a bootloaded part in a socket, then use FTDI Basic, or FTDI cable, or CP2102 module with adapter cale for downloading sketches on to the board.


There are 6 pins labelled Remote - you have +5, Gnd, and 4 input pins there. Can use internal pullups, and NO switches to Gnd for buttons to start your timer, etc. Will send a schematic with the board.


Once you confirm I'll get a list of parts ordered ready for when it arrives (the shift registers should be here today or tomorrow). Admittedly, a populated board would be simpler but happy to have a proper board (as was going to use breadboard for final solution).


I made up a little pcb that I use for 7 seg displays, it is stand alone ( program the 328 on your arduino, then plug it in the board)

I have put some 10 pin idc headers on it, 4 for the first 4 digits ( as in a clock ), and one on the right of the board to carry on to more numbers if needed ( each digit has a TPIC6B595 high power latch driver that can drive massive digits )

The headers have 7 pins for segments a-g, and 3 pins for the LED supply.


Heres a v22 sketch for the " Bollywood Bomb " that I have scratched up from another project of mine. I havn't tested this version, I dont have time to connect up the switches and display at the moment, but it should basically work, but if you try it we can debug any problems.


It drives 4 x TPIC6B595 serial register/drivers using shiftout, I have made comments about which pins go to which LED segments.

the " spare" output of the TPIC for minutes units connects to the two dots between the mins and secs, which stays on while counting down, and flashes when paused ( you could swap it round if you ant the opposite effect.)

I have put in a " bombPin " output that you could drive an LED to light for 2 seconds ( or a sounderwhatever ) when countdown reaches zero.

3a8082e126
Reply all
Reply to author
Forward
0 new messages