from machine import Pin
from time import sleep
push = Pin(13, Pin.IN, Pin.PULL_UP) # declaring GPIO0 as an INPUT pin.
led = Pin(2, Pin.OUT) # declaring GPIO2 as an OUTPUT pin.
while True:
# we use if() function to compare the GPIO0 reading state with the LOW state.
# if the GPIO0 reading is LOW, light ON the LED on GPIO2 with LOW state.
# else means, the GPIO0 reading is HIGH, light OFF the LED on GPIO2 with HIGH state.
if push.value() == 0:
led.value(0)
sleep(0.5)
led.value(1)
sleep(0.5)