Interrupt on both edges of a switch #13150
Closed
DracoTomes
started this conversation in
General
Replies: 1 comment 2 replies
-
This works: from machine import Pin
from time import sleep_ms
p0 = Pin(0, Pin.OUT)
def p_isr(pin):
print(f"pin {pin} is now {'high' if pin() else 'low'}")
p0.irq(trigger=Pin.IRQ_RISING | Pin.IRQ_FALLING, handler=p_isr)
p0(1)
sleep_ms(20)
p0(0)
sleep_ms(20)
p0(1)
sleep_ms(20)
p0(0) Output:
And it should work the same if the pin mode is |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello all,
I wanna detect a physical switch being flipped on a pin with mode
Pin.OUT
.From what I've researched it's impossible to have multiple
Pin.irq()
active at the same time, one forPin.IRQ_FALLING
and one forPin.IRQ_RISING
.In this old Reddit post someone got it working with
trigger=Pin.IRQ_RISING | Pin.IRQ_FALLING
but I couldn't get it to work on my pi pico with 1.20 thus far.Should I just run a regular check in an asyncio coroutine?
Beta Was this translation helpful? Give feedback.
All reactions