This ESP8266 micropython tutorial 4: how to interrupt micropython, it's easy, learn!
mode:Pin.IN input
Pin.OUT output
value:output value
Pin.value ([value]) It means reading input level when it’s without parameter, and setting output level when it’s with parameter, which is 1/0.
Pin.irq(*,trigger, handler=None)
INTERRUPT
triggerPin.IRQ_FALLING, falling
Pin.IRQ_RISING, rising
Pin.IN, rising and falling
handler, callback
Interrupt function program
Copy code
"from machine import Pin[/align]value=1
counter=0
def func(v):
global value,counter
counter+=1
led.value(value)
if(value == 0):
value = 1
else:
value = 0
print("IRQ ",counter)
led = Pin(14, Pin.OUT)
led.value(0)
button = Pin(0, Pin.IN)
button.irq(trigger=Pin.IRQ_FALLING, handler=func)
while True:
pass"
I don’t need the compiling environment of how to find port no. and how to enter esp8266 micropython. Refer to the previously published documents if you don’t understand. As shown below, after entering the compiling environment, paste our interrupt program according to the said method.
Press Ctrl+d to complete pasting and then run the program. Now it output <IRQ>, which means our program is good and is under execution. At this time, we can see that led light is in extinguished state on our esp8266 development board.
We connect a DuPont line to GPIO0 port of the board. Touch other pins with the other end of the DuPont line. There will be result as shown below. Every time of touch, led light will flash for one time, and counter number will increase. Therefore, we realize the effect of interruption.
Read original article: ESP8266 Micropython - Tutorial 4: How To Interrupt Micropython