Skip to content

Instantly share code, notes, and snippets.

@elktros
Created February 27, 2021 10:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elktros/7b7e61eda164e238aa8b8424fc3089f6 to your computer and use it in GitHub Desktop.
Save elktros/7b7e61eda164e238aa8b8424fc3089f6 to your computer and use it in GitHub Desktop.
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

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