diff --git a/umnp/microcontroller/tasks/periodictask.py b/umnp/microcontroller/tasks/periodictask.py index ce2801fde2fbb40480a770a38395866991e1bff3..bf37767637cb091aba9667a3fca5b6f82dafeeaf 100644 --- a/umnp/microcontroller/tasks/periodictask.py +++ b/umnp/microcontroller/tasks/periodictask.py @@ -18,10 +18,13 @@ class PeriodicTask: self._call_back = async_call_back async def run(self): + start_time = time.ticks_ms() + last = start_time func = self._function args = self._args call_back = self._call_back delay_seconds = 25 / 1000 + while True: last = time.time() print("A0", args) @@ -32,7 +35,9 @@ class PeriodicTask: await call_back(result) while True: - now = time.time() - if now - last > 0: + now = time.ticks_ms() + diff = time.ticks_diff(last, now) + if diff > self._every_ms: + last = now break await asyncio.sleep(delay_seconds)