I have some issues with time.sleep() management in Python. I would like to use some values in a second part of the script, but they have to be delayed 300 ms one from another and I want to delay only that part of the script and not all the rest. These values are the X coordinates of an object detected by a camera. The script is something like this:
while True:
       if condition is True:
             print(xvalues)
             time.sleep(0.3)
       
       if another_condition is True:
             #do other stuff and:
             np.savetxt('Xvalues.txt', xvalues)
 
In the second part of the script (#do other stuff), I will write G-code lines with the X-coordinate detected and send them to a CNC machine. If I write a time.sleep() in that position of the script, everything in the while loop will be delayed.
How can I extract some values sampled 300ms a time without influencing the rest of the script?
 
     
    