import time
from machine import Pin
mode1 = Pin(5, Pin.IN, Pin.PULL_UP)
mode2 = Pin(6, Pin.IN, Pin.PULL_UP)
push = Pin(7, Pin.IN, Pin.PULL_UP)
led1 = Pin(8, Pin.OUT)
led2 = Pin(9, Pin.OUT)
interrupt_mode1_flag = 0
interrupt_mode2_flag = 0
interrupt_push_flag = 0
def callback_mode1(pin):
global interrupt_mode1_flag
#global interrupt_mode2_flag
#global interrupt_push_flag
interrupt_mode1_flag = 1
print('mode1 interrupted!')
def callback_mode2(pin):
#global interrupt_mode1_flag
global interrupt_mode2_flag
#global interrupt_push_flag
interrupt_mode2_flag = 1
print('mode2 interrupted!')
def callback_push(pin):
#global interrupt_mode1_flag
#global interrupt_mode2_flag
global interrupt_push_flag
interrupt_push_flag = 1
print('push interrupted!')
print('los gehts')
mode1.irq(handler=callback_mode1, trigger=Pin.IRQ_FALLING)
mode2.irq(handler=callback_mode2, trigger=Pin.IRQ_FALLING)
push.irq(handler=callback_push, trigger=Pin.IRQ_FALLING)
while True:
if interrupt_mode1_flag is 1:
print('MODE1')
led1.on()
led2.off()
interrupt_mode1_flag = 0
elif interrupt_mode2_flag is 1:
print('MODE2')
led1.off()
led2.on()
interrupt_mode2_flag = 0
elif interrupt_push_flag is 1:
print('PUSH')
led1.on()
led2.on()
interrupt_push_flag = 0