How to execute code regularly with timer on Raspberry Pi Pico?
In MCU projects, we often need to execute a piece of code regularly. For example, reading a sensor every few milliseconds or toggling an LED every second. Naively, we will use delay to achieve this effect. When there are multiple things going on the project with different periods, it becomes hard to manage with delay. Furthermore, delay blocks the CPU and we cannot perform other tasks during the delay. This is where timer comes in handy. We can achieve precise timing without blocking the CPU. In this blog, I will go through the basics of using pico_time API on the Raspberry Pi Pico to execute code regularly.