From 164d686df3ecdcb2ecef120d68d9ca3ad39338fc Mon Sep 17 00:00:00 2001 From: Jimmy Date: Thu, 17 Jun 2021 19:52:02 +1200 Subject: [PATCH] Add pin change interrupt --- interrupt/external.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 interrupt/external.py diff --git a/interrupt/external.py b/interrupt/external.py new file mode 100644 index 0000000..c39e9aa --- /dev/null +++ b/interrupt/external.py @@ -0,0 +1,17 @@ +from machine import Pin +from time import sleep + +led = Pin(2, Pin.OUT) + +def callback(p): + print('pin change', p, p.value()) + sleep(0.1) + +button1 = Pin(13, Pin.IN) +button1.irq(trigger=Pin.IRQ_FALLING, handler=callback) + +button2 = Pin(14, Pin.IN) +button2.irq(trigger=Pin.IRQ_FALLING, handler=callback) + +while True: + pass