Make a free website with Yola
The Pi Pico can handle interrupts.
An interrupt is an arrangement in which the normal flow of a program is paused, when an input pin changes state.
When this happens a designated function is made to run.
This is set up by a command in the program, using a "method" of the chosen pin ( .irq() ) that attaches a function to a pin - See below
def stpirq(PinId): #PinId is the oin it happened on
global Markers # count of stop sensors
global ssense # sensor "value" for main prog
if (stp.value() == 1): # Black
led2.off() # side LED
ssense = 0
else: # white
led2.on() # side LED
ssense = 100
Markers+=1 # increase count
# set up interrupts on pin "stp"
# to cause function "stpirq()"
# to run whenever it changes from 0-1 or 1-0.
stp = Pin(28, Pin.IN) # set up stop sensor input as digital not analogue
# set up interrupt handler for pin stp as stpirq()
stp.irq(handler=stpirq,trigger=Pin.IRQ_FALLING|Pin.IRQ_RISING)
| | |
| |
Make a free website with Yola