View Categories

LED Control Dengan Push Button Di Pi Pico

Persiapan Bahan #

– Raspberry Pi Pico / Pico W
– LED
– Breadboard
– Push Button
– Kabel Jumper Male to Male
– Kabel Micro USD
– Aplikasi Thonny IDE

Wiring LED dan Push Button dengan Raspberry Pi Pico #

  • Connect the Push Button Pin to GP0 & its cross pin to GND.
  • Connect the LED positive Pin to Raspberry Pi Pico GP1 Pin
  • Negative Pin LED to GND Pin.

Sampling Code #

from machine import Pin
from utime import sleep_ms
button = Pin(0, Pin.IN, Pin.PULL_UP)   #Internal pull-up
led = Pin(1, Pin.OUT)
State=0                                #0 means that the light is currently off
if __name__ == '__main__':
    while True:
        print(button.value())
        if button.value() == 0:       #key press
            if State==0: 
                led.value(1)
                sleep_ms=100
                while button.value() == 0:
                   State=1        
            else:
                led.value(0)
                sleep_ms=100
                while button.value()== 0:
                    State=0

Run the script and you can start checking the LED State by pressing the button.

When a button is pressed the LED will turn ON.

Select the fields to be shown. Others will be hidden. Drag and drop to rearrange the order.
  • Image
  • SKU
  • Rating
  • Price
  • Stock
  • Availability
  • Add to cart
  • Description
  • Content
  • Weight
  • Dimensions
  • Additional information
Click outside to hide the comparison bar
Compare
What are you looking for in Partdo?
× How can I help you?