On my board I configured an irq interrupt button. I put the board into a light sleep mode. When a button is pressed during sleep, an interrupt and its associated function are triggered. And after activating waking up timer, another function is triggered. Here's my example:
Code: Select all
import machine, pyb
#пины с прерыванием
tm0 = machine.Timer(mode=machine.Timer.PERIODIC, period = 100, callback = lambda x: pyb.LED(1).toggle())
def button_interrupt():
print("Interruption...")
tm0.deinit()
tm0.init(mode=machine.Timer.PERIODIC, period = 1000, callback = lambda x: pyb.LED(1).toggle())
Button = pyb.Pin(pyb.Pin.board.PB4, pyb.Pin.IN, pyb.Pin.PULL_DOWN)# пин кнопка включения экрана
Button.irq( trigger=pyb.Pin.IRQ_RISING, handler = lambda x: button_interrupt())
def wakeup_callback():
tm0.deinit()
tm0.init(mode=machine.Timer.PERIODIC, period = 5000, callback = lambda x: pyb.LED(1).toggle())
#--------start----------
print("Sleep interruption test...")
pyb.delay(5000) #delay for LED blink view
b_rtc = pyb.RTC()
b_rtc.wakeup(60000, lambda x: wakeup_callback() ) #плата засыпает (light_sleep) на X мин
pyb.stop()