Skip to content

Sample Pin Interrupt – Switch detection

Takeo Takahashi edited this page Feb 17, 2022 · 4 revisions

image

  • Pressing Button Switch, print (“intr”) is executed.

  • Example for RA4M1 Clicker: specify P304

from pyb import Pin,ExtInt

callback = lambda e: print("intr")
ext = ExtInt(Pin(Pin.cpu.P304, Pin.IN, Pin.PULL_UP), ExtInt.IRQ_RISING, Pin.PULL_UP, callback)
  • Example for EK-RA6M2: specify P105
from pyb import Pin,ExtInt

callback = lambda e: print("intr")
ext = ExtInt(Pin(Pin.cpu.P105, Pin.IN, Pin.PULL_UP), ExtInt.IRQ_RISING, Pin.PULL_UP, callback)
  • In order to perform pin interrupt, the pin needs to be assigned as IRQx, and IRQ interrupt must be enabled in MicroPython Firmware.

Home

ホーム

Clone this wiki locally