I'm Bob and I'm newbie of this forum and mPY.
I'm working on my first project with mPY with the intention to implemente a datalogger to records during the days , how many times flash a led and for each flash record date , time a incremantal counter.
I've already done this project using a PIC , but now I wont try to implement using the mPY.
Having not enough experience with Python I'm proceeding by steps and now I'm looking how use the ExtInt to detect every falling edge on X1 pin where will be connected the sensor the read the flash.
This is the code I'm using:
Code: Select all
import pyb
from pyb import Pin
from pyb import ExtInt
pin_sonda = Pin('X1', Pin.IN)
L = pyb.LED(2)
ExtInt.enable
contatore=0
def callback(line):
L.on()
pyb.delay(1000)
L.off()
print("interrupt")
contatore +=1
ext = pyb.ExtInt(pin_sonda, pyb.ExtInt.IRQ_FALLING,pyb.Pin.PULL_NONE,callback)
while True:
print("wait")
print(contatore)
I say that works partially because the green led flash for 1 second but i dont see using PuTTY the counter increment or the "interrupt" .
On the first I suspect because the counter variable isn't declared in the right way , but i dopn't understad why isn't printed "Interrupt".
Is there someone able to give me any suggestion on what is wrong in the code ?
P.S. Why is i write ExtInt.enable() i got an error from python while in the documentatio is declared in this way ?
Thanks Bob.