Article Index

Page 100
 
def HelloIRQ1(pin):
    print("IRQ1")
   
def HelloIRQ2(pin):
    print("IRQ2")

pin1=Pin(4,Pin.IN,Pin.PULL_DOWN)
pin2=Pin(5,Pin.IN,Pin.PULL_DOWN)

pin1.irq(HelloIRQ1,Pin.IRQ_RISING)
pin2.irq(HelloIRQ2,Pin.IRQ_RISING)

Page 101

import time
from machine import Pin
t = 0
def myHandler(pin):
    global t
    temp = time.ticks_us()
    print(time.ticks_diff(temp,t))
    t = temp
    time.sleep(1.5)  
    return

pin = Pin(4, Pin.IN, Pin.PULL_DOWN)
pin.irq(myHandler, Pin.IRQ_FALLING)

Page 101

import time
from machine import Pin
t = 0
def myHandler(pin):
    global t
    pin.irq(None, Pin.IRQ_FALLING)
    temp = time.ticks_us()
    print(time.ticks_diff(temp,t))
    t = temp
    time.sleep(1.5)
    pin.irq(myHandler, Pin.IRQ_FALLING)
    return
pin = Pin(4, Pin.IN, Pin.PULL_DOWN)
pin.irq(myHandler, Pin.IRQ_FALLING)

Page 104

import time
from machine import Pin

data = bytearray(b'\xf0\xf1\xf2')

def myHandler(pin):
    global data
    for i in range(3):
        data[i]=0

pin = Pin(4, Pin.IN, Pin.PULL_DOWN)
pin.irq(myHandler, Pin.IRQ_RISING)

while True:
    for i in range(3):
        data[i] = 255
    if data[0]!=data[1] or data[1]!=data[2] or data[2]!=data[0]:
        print(data)

Page 105

from machine import Pin

data=bytearray(b'\xf0\xf1\xf2')
def myHandler(pin):
    global data
    for i in range(3):
        data[i] = 0
    print(data)

pin = Pin(4, Pin.IN, Pin.PULL_DOWN)
pin.irq(myHandler, Pin.IRQ_RISING)
while True:
    pin.irq(None, Pin.IRQ_RISING)
    for i in range(3):
        data[i] = 255

    if data[0]!=data[1] or data[1]!=data[2] or data[2]!=data[0]:
        print(data)
    pin.irq(myHandler, Pin.IRQ_RISING)

Page 106

import time

from time import sleep 

from machine import Pin
pin=Pin(4,Pin.IN,Pin.PULL_DOWN)
event=0
def rise(pin):
    global event
    event=1

def fall(pin):
    global event
    event=2

while True:
    pin.irq(rise, Pin.IRQ_RISING)
    while  not(event==1):
        pass
    t=time.ticks_us()
    pin.irq(fall, Pin.IRQ_FALLING)
    while  not(event==2):
        pass
    t=time.ticks_diff(time.ticks_us(),t)
    print(t)
    sleep(1)