from machine import Pin
import time
pines_ids= [0, 1, 2, 3, 4, 5, 6]
segmentos= [Pin(p, Pin.OUT) for p in pines_ids]
sensor_pir= Pin(27, Pin.IN, Pin.PULL_DOWN)
contador_eventos= 0
evento_nuevo= False
tabla_digitos = {
0: (1, 1, 1, 1, 1, 1, 0),
1: (0, 1, 1, 0, 0, 0, 0),
2: (1, 1, 0, 1, 1, 0, 1),
3: (1, 1, 1, 1, 0, 0, 1),
4: (0, 1, 1, 0, 0, 1, 1),
5: (1, 0, 1, 1, 0, 1, 1),
6: (1, 0, 1, 1, 1, 1, 1),
7: (1, 1, 1, 0, 0, 0, 0),
8: (1, 1, 1, 1, 1, 1, 1),
9: (1, 1, 1, 1, 0, 1, 1)
}
def mostrar_digito(numero):
patron = tabla_digitos[numero]
for i in range(7):
segmentos[i].value(patron[i])
def isr_pir(pin):
global contador_eventos, evento_nuevo
contador_eventos= (contador_eventos + 1) % 10
evento_nuevo = True
sensor_pir.irq(trigger=Pin.IRQ_RISING, handler=isr_pir)
mostrar_digito(0)
while True:
if evento_nuevo:
mostrar_digito(contador_eventos)
print ('Deteccion acumulada:', contador_eventos)
evento_nuevo = False
time.sleep(0.01)