PymateIO-Delaying: Difference between revisions

From pymate.io wiki
Jump to navigation Jump to search
Line 11: Line 11:


The solution for this is:
The solution for this is:
* use the '''DelayTimer''' class
* use the '''EventTimer''' class
* set the delay on the '''DelayTimer''' when the source event occurs.
* set the delay on the '''EventTimer''' when the source event occurs.
* check the '''DelayTimer.done''' at every mainloop cycle.  
* check the '''EventTimer.done''' at every mainloop cycle.  
* Once '''done''', it is time to executed the delayed code.
* Once '''done''', it is time to executed the delayed code.


Remark: the '''done''' will be True only once for every '''set()'''!
Remark: the '''done''' will assert True '''only once''' for every '''set()'''!
 
== Practical example ==
xx


{{PYMATE-TRAILER}}
{{PYMATE-TRAILER}}

Revision as of 17:54, 29 June 2026


Abstract

The "Cycle Timing" tutorial state the following:


NEVER USE BLOCKING INSTRUCTION in the mainloop

Blocking instruction locks the script execution in a waiting state... whereas critical operation may requires quick reaction from the script.


The sleep(), sleep_ms() are BLOCKING INSTRUCTIONS.
They should never be used in your script, neither in the mainloop

The solution for this is:

  • use the EventTimer class
  • set the delay on the EventTimer when the source event occurs.
  • check the EventTimer.done at every mainloop cycle.
  • Once done, it is time to executed the delayed code.

Remark: the done will assert True only once for every set()!

Practical example

xx


PymateIO all right reserved © 2026 - Written by MCHobby for PymateIO