/ adafruit_led_animation / __init__.py
__init__.py
1 # SPDX-FileCopyrightText: 2020 Kattni Rembor for Adafruit Industries 2 # 3 # SPDX-License-Identifier: MIT 4 5 """ 6 Timing for Adafruit LED Animation library. 7 8 Author(s): Kattni Rembor 9 """ 10 11 try: 12 from micropython import const 13 except ImportError: 14 15 def const(value): # pylint: disable=missing-docstring 16 return value 17 18 19 try: 20 from time import monotonic_ns 21 22 monotonic_ns() # Test monotonic_ns in 6.x 23 24 def monotonic_ms(): 25 """ 26 Return monotonic time in milliseconds. 27 """ 28 return monotonic_ns() // NANOS_PER_MS 29 30 31 except (ImportError, NotImplementedError): 32 import time 33 34 def monotonic_ms(): 35 """ 36 Implementation of monotonic_ms for platforms without time.monotonic_ns 37 """ 38 return int(time.monotonic() * MS_PER_SECOND) 39 40 41 NANOS_PER_MS = const(1000000) 42 MS_PER_SECOND = const(1000)