QUESTION: are DELAY ms and us blocking?

Issue #57 resolved
Turgut Guneysu created an issue

Hi John

Writing some code involving timings and wanted to know if the two delay functions (ms and us) were blocking or not?

ie: when a delay is executing in one stream does the rest of the code in other streams keep running or not?

thx.

Comments (2)

  1. John Maloney repo owner

    Yes, a “wait” command only block the MicroBlocks task that executes it. Other MicroBlocks tasks continue to run independently.

    That’s the case for both the “wait _ milliseconds” and “wait _ microseconds” commands.

    Note that the wake up time is accurate only to within about 20 microseconds in the best case (i.e. only one task running) and it can be less precise if the other tasks are doing uninterruptible low-level operations such as updating NeoPixels or interacting with a device via the I2C or SPI bus. Also, on single-CPU WiFi boards (e.g. ESP8266 boards), the WiFi system steals CPU time from MicroBlocks, making the timing less precise.

    That said, MicroBlocks has good enough timing precision to generate audio tones and music by toggling a digital pin in a loop that uses “wait _ microseconds” blocks to control the frequency. That’s pretty good real-time performance!

  2. Log in to comment