spikedev.stopwatch¶
Example¶
from spikedev.button import ButtonCenter
from spikedev.stopwatch import StopWatch
button = ButtonCenter()
sw = StopWatch()
print("Press the center as soon as possible)
sw.start()
button.wait_for_bump()
sw.stop()
print("center button pressed in {} ms".format(sw.value_ms))
Classes¶
A StopWatch class for tracking the amount of time between events
-
class
spikedev.stopwatch.StopWatch(desc=None)¶ Bases:
objectA timer class which lets you start a virtual stopwatch and later check the amount of time elapsed
-
start()¶ Start the timer. If the timer is already running, raise
StopWatchAlreadyStartedException
-
stop()¶ Stop the timer. The time value of this
Stopwatchis paused and will not continue increasing.
-
reset()¶ Reset the timer and leave it stopped
-
restart()¶ Reset and start the timer
-
property
is_started¶ Return
Trueif theStopWatchhas been started but not stopped (i.e., it’s currently running), else returnFalse
-
property
value_ms¶ Return the value of the
StopWatchin milliseconds
-
property
value_secs¶ Return the value of the
StopWatchin seconds
-
property
value_hms¶ Return the
StopWatchelapsed time as a tuple(hours, minutes, seconds, milliseconds).
-
property
hms_str¶ Return the stringified value of the
StopWatchin HH-MM-SS.msec format
-
is_elapsed_ms(duration_ms)¶ Return
Trueif this timer has measured at leastduration_msmilliseconds, else returnsFalse. Ifduration_msis None, returnFalse.
-
is_elapsed_secs(duration_secs)¶ Return
Trueif this timer has measured at leastduration_secsseconds, else returnsFalse. Ifduration_secsis None, returnsFalse.
-
-
exception
spikedev.stopwatch.StopWatchAlreadyStartedException¶ Bases:
ExceptionException raised when start() is called on a StopWatch which was already start()ed and not yet stopped.