from machine import Pin
from time import sleep_ms, ticks_ms
led = Pin (2, Pin.OUT)
bot = Pin (27, Pin.IN)
agora = antes = bot.value()
estado = False
vaiPiscar = ticks_ms()
while True:
agora = bot.value()
if agora != antes:
print ('algo aconteceu')
if agora == 1:
if estado == True:
estado = False
else:
estado = True
antes = agora
sleep_ms(200)
if estado == True:
if ticks_ms() >= vaiPiscar:
if led.value() == 1:
led.off()
else:
led.on()
vaiPiscar = ticks_ms() + 300