Timer Demo
This demo is based upon Scott Ferguson's Stopwatch demo from a few years ago, which uses a simple concept of checking the stopwatch/counter time against the device time. I have modified it to run to the second instead of 1/10 second for the purposes of this demo.
What this provides is:
A stopwatch - you simply press the StopWatch START and it will count the time until you press stop
A Count Up - you select a time to count up to, press the Count Up START, and the timer will count up to the time set, then sound an alert
A Count Down - you select a time to count down, press the CountDown START, and the timer will count down to the time set, then sound an alert
The app also shows the current date and time. Only one clock/timer is used.
A few notes:
It is a demo, it is not meant to be perfect, I am only human
It is not intended to work in the background (AI2 has no background services). If you want to run it for longer than your device's display time, use a keep awake routine, or the KeepScreenOn block from Taifun's Tools Extension
The blocks include an adjustment for Daylight Saving Time (DST) due to my locale. You may need to remove this or adjust accordingly.
The use of the Format Time block, and the DST adjustment, mean that 23:59:59 will briefly flash when the timer gets going!
You can't stop the count up or count down routines, but this is easily adjusted with the blocks (but the whole point of the count up /count down is that is what it is!)
The key element of the demo, which is really what it is all about, is this routine in the blocks:
You should be able to see how we get the time from the device clock, and check it against the time for the counter/timer. If there is a difference, then this is adjusted back/forward to the device time.