Causes the imp to halt code execution for a specified period
Device + Agent
|sleepTime||Float or integer||
The delay duration in seconds
This method causes the device to pause executing application code for a period of time expressed in seconds and with a resolution of 1μs (0.000001 seconds). The method will block for this period, and no other Squirrel code (eg. timers and event handlers) will run.
During the sleep period, impOS™ and its IRQ handlers will continue to run. This includes transferring data into and out of peripheral buffers. For example, even though Squirrel is sleeping, incoming data will still be placed in a UART RX FIFO — provided it is sufficiently large for the data the application expects to receive. Data pending in the TX FIFO will also be sent.
The imp remains connected to WiFi while paused, but does not process messages from the server. Very short sleep periods — under 20ms — are established using busy-waiting; longer periods by the use of system timers.
The method may also be used in agent code to suspend processing for the specified period, typically to introduce a delay of a fixed duration. When the agent is paused, it does not process messages from the device. No other Squirrel code, such as timers or event handlers, will run.
The following code oscillates the output of an imp pin every 50ms, using imp.sleep() to introduce a suitable pause before switching the pin’s state.