adafruit_ticks

Work with intervals and deadlines in milliseconds

  • Author(s): Jeff Epler

Implementation Notes

Software and Dependencies:

adafruit_ticks.ticks_add(ticks: int, delta: int) int

Add a delta to a base number of ticks, performing wraparound at 2**29ms.

adafruit_ticks.ticks_diff(ticks1: int, ticks2: int) int

Compute the signed difference between two ticks values, assuming that they are within 2**28 ticks

adafruit_ticks.ticks_less(ticks1: int, ticks2: int) bool

Return true if ticks1 is before ticks2 and false otherwise, assuming that they are within 2**28 ticks

adafruit_ticks.ticks_ms() int

Return the time in milliseconds since an unspecified moment, wrapping after 2**29ms.

The wrap value was chosen so that it is always possible to add or subtract two ticks_ms values without overflow on a board without long ints (or without allocating any long integer objects, on boards with long ints).

This ticks value comes from a low-accuracy clock internal to the microcontroller, just like time.monotonic. Due to its low accuracy and the fact that it “wraps around” every few days, it is intended for working with short term events like advancing an LED animation, not for long term events like counting down the time until a holiday.