from machine import Pin
import time
time.sleep(0.1) # Wait for USB to become ready
# The onboard LED for raspberry Pi Pico W, "HAS TO" be referenced with the string "LED"
onboard_led = Pin("LED", Pin.OUT)
# Define the LED pin:
led = Pin(1, Pin.OUT)
button = Pin(14, Pin.IN, Pin.PULL_UP) # Connect button to GP14 & GND
while True:
# button.value() returns 0 when pressed (pulled down to ground)
# and 1 when not pressed (pulled up to 3.3V)
if button.value() == 0:
led.value(1) # Turn on the LED (set the pin value to 1/High)
onboard_led.value(1) # Turn LED on (1)
print("Button Pressed")
time.sleep(0.05) # Wait for 1 second
else:
led.value(0) # Turn on the LED (set the pin value to 1/High)
onboard_led.value(0) # Turn LED on (1)
print("Button Not Pressed")
time.sleep(0.05) # Wait for 1 secondLoading
pi-pico-w
pi-pico-w