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.