Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Read the Button connected to Raspberry Pi Pico and toggle the status of LED.
#Import Pin class from machine library to configure GPIO Pins.
from machine import Pin
#Import utime library to implement delay
import utime
#create an object of Pin class and set GPIO Parameters (GPIO Pin, Direction).
ledPin = Pin(16, Pin.OUT)
buttonPin = Pin(15, Pin.IN, Pin.PULL_DOWN)
#Create an infinite loop. This is similar to while(1) in C.
while True:
if buttonPin.value() == 1:
utime.sleep_ms(20)
ledPin.toggle()
@evilcloud
Copy link

evilcloud commented Mar 13, 2021

Line 10: if buttonPin.value():

any content other than 0 and False is Truth in Python

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment