from machine import Pin
from time import ticks_ms
led = Pin(18, Pin.OUT) # LED do abajur
estado = False # Estado atual do LED
tempo_passado = 0 # Tempo da última mudança
tempo = 10000 # Temporizador: 10 segundos
while True:
contagem_de_tempo = ticks_ms()
if not estado:
led.value(1) # Liga o abajur
estado = True
tempo_passado = contagem_de_tempo
print("Abajur ligado")
if estado and contagem_de_tempo - tempo_passado >= tempo:
led.value(0) # Desliga após 10 segundos
estado = False
print("Abajur desligado após 10 segundos")