Skip to content

Commit 7d25a19

Browse files
pcarverdpgeorge
authored andcommitted
docs/library/utime: Fix incorrect example with ticks_diff args order.
The parameter order in the example for ticks_diff was incorrect. If it's "too early" that means that scheduled time is greater than current time and if it's "running late" then scheduled time would be less than current time.
1 parent 64f1147 commit 7d25a19

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

docs/library/utime.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,14 +187,14 @@ Functions
187187
# This code snippet is not optimized
188188
now = time.ticks_ms()
189189
scheduled_time = task.scheduled_time()
190-
if ticks_diff(now, scheduled_time) > 0:
190+
if ticks_diff(scheduled_time, now) > 0:
191191
print("Too early, let's nap")
192-
sleep_ms(ticks_diff(now, scheduled_time))
192+
sleep_ms(ticks_diff(scheduled_time, now))
193193
task.run()
194-
elif ticks_diff(now, scheduled_time) == 0:
194+
elif ticks_diff(scheduled_time, now) == 0:
195195
print("Right at time!")
196196
task.run()
197-
elif ticks_diff(now, scheduled_time) < 0:
197+
elif ticks_diff(scheduled_time, now) < 0:
198198
print("Oops, running late, tell task to run faster!")
199199
task.run(run_faster=true)
200200

0 commit comments

Comments
 (0)