Code: Select all
seconds:=60
gui timer:new
gui timer:color, white
Gui timer:+AlwaysOnTop
Gui timer:Font, s50
SetTimer, timer, 1000
return
timer:
seconds:=seconds-1
gui timer:add, text, cGreen, %seconds%
gui timer:show
return
Code: Select all
seconds:=60
gui timer:new
gui timer:color, white
Gui timer:+AlwaysOnTop
Gui timer:Font, s50
SetTimer, timer, 1000
return
timer:
seconds:=seconds-1
gui timer:add, text, cGreen, %seconds%
gui timer:show
return
Code: Select all
seconds := 60
Gui, timer:New, +AlwaysOnTop
Gui, Color, White
Gui, Font, s50
Gui, Add, Text, cGreen vtime Center, %seconds%
Gui, Show,, Time
SetTimer, Timer, 1000
Timer:
SoundBeep, 1700
GuiControl, timer:, time, %seconds%
seconds -= 1
Return
GuiEscape:
GuiClose:
ExitApp
I am planning to create a timer with the countdown for several hours. So if the timing of seconds is not precise even without the beep, the total divergence from the actual time may be big if the countdown timer is run for a long time.Timing is not precise anyway
This should be about +/- 0.20 seconds off real time (for the whole run)Alexander2 wrote: ↑31 Jul 2021, 12:26Is there a way to make the countdown precise and independent of the delay caused by the sound beep?
Code: Select all
seconds := 60
remain := 0
Gui, timer:New, +AlwaysOnTop
Gui, Color, White
Gui, Font, s50
Gui, Add, Text, cGreen vtime Center, %seconds%
Gui, Show,, Time
SetTimer, Timer, 200
StartTime := A_TickCount
Timer:
if( ( A_TickCount - ( StartTime - remain ) ) > 1000 ) {
remain := ( A_TickCount - StartTime ) - 1000
StartTime := A_TickCount
SoundBeep, 1700
seconds -= 1
GuiControl, timer:, time, %seconds%
if(!Seconds)
SetTimer, Timer, off
}
Return
GuiEscape:
GuiClose:
ExitApp
Code: Select all
seconds := 60
Gui, timer:New, +AlwaysOnTop
Gui, Color, White
Gui, Font, s50
Gui, Add, Text, cGreen vtime Center, %seconds%
Gui, Show,, Time
SetTimer, Timer, 200
TargetTime := A_TickCount + ( seconds * 1000 )
Timer:
if( TargetTime - A_TickCount < ( seconds - 1 ) * 1000 ) {
SoundBeep, 1700
seconds -= 1
GuiControl, timer:, time, %seconds%
if(!Seconds)
SetTimer, Timer, off
}
Return
GuiEscape:
GuiClose:
ExitApp
Code: Select all
seconds := 60
TickCount := A_TickCount
Gui, timer:New, +AlwaysOnTop
Gui, Color, White
Gui, Font, s50
Gui, Add, Text, cGreen vtime Center, %seconds%
Gui, Show,, Time
Timer:
GuiControl, timer:, time,% seconds
if(seconds--)
SetTimer, Timer,% A_TickCount - TickCount += 1000
SoundBeep, 1700
Return
timerGuiEscape:
timerGuiClose:
ExitApp
Yeah, the timer is just used to check in with the real time and update things if needed.Alexander2 wrote: ↑01 Aug 2021, 12:43I can see now how the principle works. It is necessary to check the current value against the A_TickCount value during every iteration and then to make up for any differences in order to ensure the correct count of time.
Thank you. I have tested the script with different SoundBeep delays (900, 500, and 10), and it is evident that it makes up for tick delays by automatically adjusting the tick delay value to match one second.Rohwedder wrote: ↑01 Aug 2021, 03:43Hallo,
that one should keep perfect time ( +/- 20 ms ) for unlimited duration:Edit: As Hellbend correctly pointed out, my previous revision was wrong. I had inserted the script incompletely.Code: Select all
seconds := 60 TickCount := A_TickCount Gui, timer:New, +AlwaysOnTop Gui, Color, White Gui, Font, s50 Gui, Add, Text, cGreen vtime Center, %seconds% Gui, Show,, Time Timer: GuiControl, timer:, time,% seconds if(seconds--) SetTimer, Timer,% A_TickCount - TickCount += 1000 SoundBeep, 1700 Return timerGuiEscape: timerGuiClose: ExitApp