**************************** *test_timer_pi.py (text) * **************************** Description: By D@CC (tested OK) This Python program for the Raspberry Pi uses a timer (with interrupts) to schedule tasks to run when certain events occur. It has a timer that counts down (once per tick) and loops back continually. It has three events with tasks: - task1: once/tick, - task2: once/loop, - task3: when scheduled. Just define the Tick period and it works . . . e.g. with DT (1 Tick) =.5 sec. But how tiny can a Tick be. It still works when 1 Tick=50 microseconds. It cannot keep up when 1 Tick=5 microseconds. This is very good performance. . . even for the Raspberry Pi model 4 that the author was testing. Of course, as more code is processed at each event, the processor will be more heavily taxed. This code can be used as the basis for a software-coded UART (and many other devices.). Name: test_time03_pi.py aka test_timer03_pi.py (very similar) By D@CC (not the original author) On 2024DApr05 Created: 2022EMay30 Language: Python 3 Article: 164.html #13 uSD/SSD: none (Fla53S ?) TimesOut: unknown Issue 01:in Project/pix/pico (but is for RPi) Purpose: An ultra-simple Scheduler that permits: 1) run a task at a certain time 2) run a task repeatedly (after interval N) 3) run a task every tick Notes: 1) runs forever OR for a limited time 2) stopping the scheduler 3) defining the DT (tick time) 4) DT can even be 50 microseconds on a RPi 4 5) only 60 Python statements long 6) does NOT use PIO (probably) 7) stop by ^C or Stop/Restart Backend Uses: 15 functions/methods import asyncio #Source: https://stackoverflow.com/questions/5177439/postponing-functions-in-python/14040516#14040516 #Source: https://docs.python.org/3/library/asyncio.html#:~:text=asyncio%20is%20used%20as%20a,high%2Dlevel%20structured%20network%20code. #Output #10 #9 #8 #7 #6 #5 #4 #3 #timer went off! #2 #1 #done # D@CC stops here if loop.stop() is not commented out # # if no loop.stop ... 10,9,8,7 ..... 3, timer went off, 2, 1, 10, 9 etc #end test_timer03_pi.py #/test_time03_pi.py #/test_timer_pi.txt