260 of 307
ZBasic System Library 250 ZX Microcontroller Family Sleep Type Subroutine Invocation Sleep(time) Parameter Method Type Description time ByVal Single or int16 The amount of time to delay, in seconds (Single) or RTC ticks (int16) Discussion This routine suspends the current task for a period of time up to as long as specified. The actual delay depends on what other tasks actually do that may run in the interim. It is possible that the task will be suspended indefinitely depending on what another task might do. Note that if the current task is locked, this call will unlock it. There is a subtle difference between Delay() and Sleep() when the arguments are non-zero. For Delay() the specified time is the minimum amount of delay that the task will experience assuming that no other task is ready to run. The actual delay could be up to 1.95ms longer than the specified delay. For Sleep(), the specified time is the maximum amount of delay that the task will experience assuming that no other task is ready to run. The actual delay could be up to 1.95ms less than the specified delay. Example Do Call PutPin(25, 0) Call Sleep(0.5) ' a half-second delay Call PutPin(25, 1) Call Sleep(256) ' a half-second delay Loop This loop causes the red LED to turn on an off alternately for a half second each. Compatibility The BasicX documentation specifically indicates that Sleep() will unlock a locked task. However, tests indicate that this only happens if the parameter to Sleep() is non-zero. This implementation unlocks a task on any Sleep() call. See Also Delay, DelayUntilClockTick, Pause, WaitForInterval, Register.RTCStopWatch