from machine import Pin import time _init() LedPin = 0 led = Pin(LedPin, Pin.OUT) class Button: def __init__(self, p, pressSate): self.pin = Pin(p, Pin.IN) self.pressSate = pressSate self.oldState = not pressSate def onPress(self): state = self.pin.value() if state != self.oldState: self.oldState = state if state == self.pressSate: return True return False btn = Button(16, 1) while True: if btn.onPress(): led.on() time.sleep(1) led.off()