from machine import Pin
from utime import sleep

# Configuração dos pinos do display de 7 segmentos
#       A
#      ---
#  F |  G  | B
#      ---
#  E |     | C
#      ---
#       D

pins = [
    Pin(2, Pin.OUT),  # A
    Pin(3, Pin.OUT),  # B
    Pin(4, Pin.OUT),  # C
    Pin(5, Pin.OUT),  # D
    Pin(6, Pin.OUT),  # E
    Pin(8, Pin.OUT),  # F
    Pin(7, Pin.OUT),  # G
    Pin(0, Pin.OUT)   # DP (não utilizado)
]

digits = [
    [0, 0, 0, 0, 0, 0, 1, 1], # 0
    [1, 0, 0, 1, 1, 1, 1, 1], # 1
    [0, 0, 1, 0, 0, 1, 0, 1], # 2 
    [0, 0, 0, 0, 1, 1, 0, 1], # 3
    [1, 0, 0, 1, 1, 0, 0, 1], # 4
    [0, 1, 0, 0, 1, 0, 0, 1], # 5
    [0, 1, 0, 0, 0, 0, 0, 1], # 6
    [0, 0, 0, 1, 1, 1, 1, 1], # 7
    [0, 0, 0, 0, 0, 0, 0, 1], # 8
    [0, 0, 0, 1, 1, 0, 0, 1], # 9
]

def reset():
    """Desliga todos os segmentos do display de 7 segmentos."""
    for pin in pins:
        pin.value(1)

reset()

pir_sensor = Pin(1, Pin.IN)

counter = 0

def display_digit(number):
    for i in range(len(pins)):
        pins[i].value(digits[number][i])



while True:
    if pir_sensor.value() == 1:
        counter += 1
        if counter > 9:
            counter = 0  
        display_digit(counter)
        sleep(2)  
    else:
        reset()
BOOTSELLED1239USBRaspberryPiPico©2020RP2-8020/21P64M15.00TTT