Timer interrupt
Run a function 2 times a second in the background with a hardware timer.
A starter program from the MantisIDE Full IDE (Tools › Examples). Press Open in Full IDE to run it on your board, change it, and save it as your own.
# Run a function 2 times a second in the background with a hardware timer.
from machine import Pin, Timer
led = Pin(2, Pin.OUT)
ticks = 0
def tick(t):
global ticks
ticks += 1
led.value(not led.value())
timer = Timer(0) # Pico: Timer()
timer.init(freq=2, mode=Timer.PERIODIC, callback=tick)
print("Timer started. Stop it with timer.deinit() in the shell.")
Comments