At work, I have a need: to do sampling every 0.08 seconds in 10 seconds.
I use while loop but it fails.
import time
start_t =time.time()
while time.time() -start_t <=10:
if float(time.time() -start_t) % float(0.08) == 0:
"""do sample record""
finally, I got no data at all, I think the if float(time.time() -start_t) % float(0.08) == 0:
does not work.
I am confused how to set the condition to enter the sampling code.
The easiest way is to use
time.sleep
:You probably get no data because you collect the time only at discrete moments. In these moments, they will never be perfect multiples of 0.08.