from machine import Pin import time button1 = Pin(16, Pin.IN, Pin.PULL_UP) led = Pin(12, Pin.OUT) count = 0 while True: btnVal1 = button1.value() # Reads the value of button 1 #print("button1 =",btnVal1) #Print it out in the shell if(btnVal1 == 0): time.sleep(0.01) while(btnVal1 == 0): btnVal1 = button1.value() if(btnVal1 == 1): count = count + 1 print(count) val = count % 2 if(val == 1): led.value(1) else: led.value(0) time.sleep(0.1) #delay 0.1s