button_controlled_led

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
button_controlled_led [2026/07/09 21:44] – [A Simple LED Button Project] walkeradminbutton_controlled_led [2026/07/09 23:48] (current) – [Introduction] walkeradmin
Line 1: Line 1:
 ====== Button Controlled LED ====== ====== Button Controlled LED ======
 <color #db5f0b>Jul 2026</color> <color #db5f0b>Jul 2026</color>
-\\  
-<color #ed1c24>**THIS IS WORK IN PROGRESS AND IS NOT FINISHED YET.**</color> 
 \\  \\ 
 \\  \\ 
Line 12: Line 10:
 ===== Introduction ===== ===== Introduction =====
 \\  \\ 
-I did not want to lead of talking about a simulator, if you have your Pico, have installed Thonny, have some basic parts, breadboard, LEDs, switches, wires etc, and you want to build something physical, please skip this section and come back to it later.+I did not want to lead by talking about a simulator, if you have your Pico, have installed Thonny, have some basic parts, breadboard, LEDs, switches, wires etc, and you want to build something physical, please skip this section and come back to it later.
 \\  \\ 
 \\  \\ 
Line 70: Line 68:
 {{ :wokwi_pico_simulator_5_.png?900 |}} {{ :wokwi_pico_simulator_5_.png?900 |}}
 \\  \\ 
-While the resistor is selected, you can change its properties, just under the <color #00a2e8>blue +</color> button. Set the resistor to 330 ohms, and use the rotate symbol to get the correct orientation.+While the resistor is selected, you can change its properties, just under the <color #00a2e8>blue +</color> button. Set the resistor to 330 ohms, and use the rotate symbol to get the correct orientation. The colour code on the resistor will also change to reflect the resistor value.
 \\  \\ 
 \\  \\ 
 +For those of you paying attention, yes, my LED has changed colour, only temporarily though :)
 +\\ 
 +\\ 
 +The last component we are going to add, is a push button. Click the <color #00a2e8>blue +</color> button and select Pushbutton. (There are two options, Pushbutton and Pushbutton 6mm, the 6mm button is visibly smaller).
 +\\ 
 +\\ 
 +{{ :wokwi_pico_simulator_6_.png?900 |}}
 +\\ 
 +You will see a Pushbutton added to your project.
 +\\ 
 +\\ 
 +{{ :wokwi_pico_simulator_7b_.png?900 |}}
 +\\ 
 +While selected, the Pushbutton has some options, you can change the button colour, X-Ray shows you the button wiring (helpful to use the correct pins) there is a keyboard shortcut, so instead of mouse-clicking the button, you can press a button on your keyboard, and you can rotate the button.
 +\\ 
 +\\ 
 +Now we can start to wire up the project, this is very simple, you click on the leg of a component, and drag to the leg of another component or to the Raspberry Pi Pico.
 +\\ 
 +\\ 
 +{{ :wokwi_pico_simulator_8_.png?900 |}}
 +\\ 
 +It takes a little practice to get the routing correct, but have a go, you should end up with something identical to the image below.
 +\\ 
 +\\ 
 +{{ :wokwi_pico_simulator_9_.png?900 |}}
 +\\ 
 +This is the hardware part complete. What we have done, is connected the following:
 +\\ 
 +  * The LED/Resistor between the Raspberry Pi Pico GP14 pin and GND. 
 +  * The button between GPIO 16 and GND. (GND = Ground).
 +\\ 
 +\\ 
 +Now, we need to add the Micro Python code.
 +\\ 
 +<code:python | download>
 +# Hardware Test
 +# Blink and LED (GP14) slowly/quickly while a button (GP16) is not-pressed/pressed
  
 +from machine import Pin          # Import Pin class to control GPIO pins
 +from time import sleep_ms        # Import millisecond sleep function
 +
 +led = Pin(14, Pin.OUT)           # Create an output pin on GPIO14 for the LED
 +button = Pin(16, Pin.IN, Pin.PULL_UP)  # Create an input pin on GPIO16 with internal pull‑up resistor
 +
 +while True:                      # Infinite loop
 +    if button.value() == 0:      # If button is pressed (input pulled LOW)
 +        delay = 100              # Use short delay (fast blink)
 +    else:                        # Otherwise (button not pressed)
 +        delay = 1000             # Use long delay (slow blink)
 +
 +    led.toggle()                 # Flip LED state: ON → OFF or OFF → ON
 +    sleep_ms(delay)              # Wait for the chosen delay before next toggle
 +</code>
 +
 +Download the above code, and paste it in to the left hand window of the WokWi page.
 +\\ 
 +\\ 
 +You will see the code displayed in the WokWi application.
 +\\ 
 +\\ 
 +{{ :wokwi_pico_simulator_10_.png?900 |}}
 +\\ 
 +To start the Micro Python code, click the <color #22b14c>green</color> play button.
 +\\ 
 +\\ 
 +You will see the LED start to flash slowly.
 +\\ 
 +\\ 
 +{{ :undefined:wokwi_pico_simulator_11_.png?900 |}}
 +\\ 
 +If you click the button with the mouse (or shortcut if you created one) then the LED will start to flash much faster.
 +\\ 
 +\\ 
 +----
 +Congratulations, you have created your first simulated project. You could now build a physical version of this project to do a real world test. Hopefully you can now see the value of this simulator, its great to test stuff before going to the effort of building something physical, which can be very time consuming. It's great to know if an idea you have will work, before you build it, only to find it does not :)
 +\\ 
 +\\ 
 +----
button_controlled_led.1783633492.txt.gz · Last modified: by walkeradmin