import time # Import Time Package
from machine import Pin # Import the Pin Function from the machine package
# Define the LED pins - EX. (GPIO PIN NUMBER, TYPE)
led_red = machine.Pin(1, Pin.OUT) # Red Pin is connected to GPIO 1 and declared as an output
button = machine.Pin(28, Pin.IN, Pin.PULL_DOWN)
state = 0 # Variable to hold the LED state
# 1 = Pressed
# 0 = Not Pressed
## Never Ending Loop - Therefore the code will repeat forever
while True:
#print(button.value()) # Print the value of the button - Good for debuging code/finding issues
# If the button is pressed - Run this code
if button.value() == 1:
print("okaoskd")
if state == 0:
led_red.value(1);
state = 1;
else:
led_red.value(0);
state = 0;
time.sleep(0.1) # Add a delay
# TASK 1 -
# Modify the code to turn the LED on when the button is pressed and keep it on until the button is pressed again
# Hints -
# if button.value() == 1 - Then the button is pressed
# Now check the state - If the state is equal to 0 - Then the LED is off
# - Turn the led on - led_red.value(1) and state = 1
#
# Now add the else - If the state is not equal to 0 - Then the LED is on
# - Turn the led off - led_red.value(0) and state = 0