# imports the libraries needed
from machine import Pin
import time
# assign switch GPIO terminal
switch_terminal = 15
# assign led GPIO terminal
led_terminal = 16
# configure the GPIO pin to Output
led_pin = Pin(led_terminal, mode=Pin.OUT)
# configure the GPIO pin to Input (responds when theres an input voltage)
switch_pin = Pin(switch_terminal, mode=Pin.IN, pull=Pin.PULL_DOWN)
# function to control the turning On/Off of LED
def control_led(input_value):
# make the declared variable accessible
global led_pin
# this controls the LED output based on the input value
led_pin.value(input_value)
# returns to where it was called from
return
# main routine
while 1:
# check if the push button is pressed
if switch_pin.value() == 1:
# repeat the loop 30 times
for i in range(1, 30):
# turn LED On
control_led(1)
# delays for 1 second
time.sleep(1)
# turn LED Off
control_led(0)
# delays for 1 second
time.sleep(1)
# do this if the push button is not pressed
else:
# turn LED Off
control_led(0)