I am trying to get an precise repeat rate of 41.6 milliseconds .
I Come fairly close , but "no cigar" .
I would like to get some help on how to do this .
Example A (SetTimer_) , gives a avg repeat rate of 40 milliseconds .
Example B (Elapsed + Delay) , gives a avg repeat rate of 46 milliseconds .
Example C (Elapsed + Delay) , gives a avg repeat rate of 46 milliseconds .
I didn't try AddWindowTimer , because Help said:
"Timers are therefore not suited for precise timing " .
Example A :
Code: Select all
; output average = 40
Global toggleColor.i , LastElapsedMilliseconds ,
totalTimesThru.i , totalElapsedTimes.i = 0 , avgElapsedTime.i ,
currentElapsedMilliseconds.i , calcElapsedMilliseconds , STOP = #False
#PROGRESS_TIME = 3500
OpenWindow(1, 0, 0, 300, 100, "Timed Progress...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ProgressBarGadget(1, 10, 10, 280, 50, 0, #PROGRESS_TIME / 10, #PB_ProgressBar_Smooth)
Time = ElapsedMilliseconds()
LastElapsedMilliseconds = ElapsedMilliseconds()
Repeat
If GetGadgetState(1) < #PROGRESS_TIME / 10 ; returns the current value of the ProgressBar.
totalTimesThru = totalTimesThru + 1
currentElapsedMilliseconds = ElapsedMilliseconds()
calcElapsedMilliseconds = ( currentElapsedMilliseconds - LastElapsedMilliseconds )
totalElapsedTimes = totalElapsedTimes + calcElapsedMilliseconds
SetGadgetState(1, GetGadgetState(1) + 1) ; increment progressBar
Debug "ElapsedMilliseconds() " + Str( calcElapsedMilliseconds )
LastElapsedMilliseconds = ElapsedMilliseconds()
Delay(41)
Else
Debug "Time took to fill gadget: " + Str(ElapsedMilliseconds() - Time)
avgElapsedTime = totalElapsedTimes / totalTimesThru -1 ; because 1st time thru = 0
Debug "avgElapsedTime = " + Str(avgElapsedTime)
MessageRequester("avgElapsedTime" , "avgElapsedTime = " + avgElapsedTime + " milliSeconds")
STOP = #True
EndIf
Until STOP
Code: Select all
; output average = 46
Global Window_0 = 0 , Container_0, Button_0
Global toggleColor.i , LastElapsedMilliseconds ,
totalTimesThru.i , totalElapsedTimes.i , avgElapsedTime.i ,
currentElapsedMilliseconds.i , calcElapsedMilliseconds
If OpenWindow(Window_0, 0, 0, 500, 240, "", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
Container_0 = ContainerGadget(#PB_Any, 10, 10, 310, 125)
SetGadgetColor(Container_0 , #PB_Gadget_BackColor , $FF0000)
Button_0 = ButtonGadget(#PB_Any, 60, 70, 100, 25, "")
CloseGadgetList()
LastElapsedMilliseconds = ElapsedMilliseconds()
toggleColor = 1
Repeat
Event = WaitWindowEvent()
totalTimesThru = totalTimesThru +1
currentElapsedMilliseconds = ElapsedMilliseconds()
calcElapsedMilliseconds = ( currentElapsedMilliseconds - LastElapsedMilliseconds )
If calcElapsedMilliseconds > 0 ; And LastElapsedMilliseconds <> 0
Debug Str(calcElapsedMilliseconds)
totalElapsedTimes = totalElapsedTimes + calcElapsedMilliseconds
If (Mod(toggleColor, 2) <> 0 )
SetGadgetColor(Container_0 , #PB_Gadget_BackColor , $00FF00)
LastElapsedMilliseconds = ElapsedMilliseconds()
EndIf
If (Mod(toggleColor, 2) = 0 )
SetGadgetColor(Container_0 , #PB_Gadget_BackColor , $FF0000)
LastElapsedMilliseconds = ElapsedMilliseconds()
EndIf
toggleColor = toggleColor + 1
EndIf ;
Delay(41)
Until Event = #PB_Event_CloseWindow
avgElapsedTime = totalElapsedTimes / totalTimesThru
MessageRequester("avgElapsedTime" , "avgElapsedTime = " + avgElapsedTime + " milliSeconds")
EndIf
End
Code: Select all
; output average = 40
Global toggleColor.i , LastElapsedMilliseconds ,
totalTimesThru.i , totalElapsedTimes.i = 0 , avgElapsedTime.i ,
currentElapsedMilliseconds.i , calcElapsedMilliseconds , STOP = #False
#PROGRESS_TIME = 3500
OpenWindow(1, 0, 0, 300, 100, "Timed Progress...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ProgressBarGadget(1, 10, 10, 280, 50, 0, #PROGRESS_TIME / 10, #PB_ProgressBar_Smooth)
Time = ElapsedMilliseconds()
LastElapsedMilliseconds = ElapsedMilliseconds()
Repeat
If GetGadgetState(1) < #PROGRESS_TIME / 10 ; returns the current value of the ProgressBar.
totalTimesThru = totalTimesThru + 1
currentElapsedMilliseconds = ElapsedMilliseconds()
calcElapsedMilliseconds = ( currentElapsedMilliseconds - LastElapsedMilliseconds )
totalElapsedTimes = totalElapsedTimes + calcElapsedMilliseconds
SetGadgetState(1, GetGadgetState(1) + 1) ; increment progressBar
Debug "ElapsedMilliseconds() " + Str( calcElapsedMilliseconds )
LastElapsedMilliseconds = ElapsedMilliseconds()
Delay(41)
Else
Debug "Time took to fill gadget: " + Str(ElapsedMilliseconds() - Time)
avgElapsedTime = totalElapsedTimes / totalTimesThru -1 ; because 1st time thru = 0
Debug "avgElapsedTime = " + Str(avgElapsedTime)
MessageRequester("avgElapsedTime" , "avgElapsedTime = " + avgElapsedTime + " milliSeconds")
STOP = #True
EndIf
Until STOP