button_controlled_led
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| button_controlled_led [2026/07/09 21:48] – [A Simple LED Button Project] walkeradmin | button_controlled_led [2026/07/09 23:48] (current) – [Introduction] walkeradmin | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Button Controlled LED ====== | ====== Button Controlled LED ====== | ||
| <color # | <color # | ||
| - | \\ | ||
| - | <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: | ||
| {{ : | {{ : | ||
| \\ | \\ | ||
| - | While the resistor is selected, you can change its properties, just under the <color # | + | While the resistor is selected, you can change its properties, just under the <color # |
| \\ | \\ | ||
| \\ | \\ | ||
| Line 76: | Line 74: | ||
| \\ | \\ | ||
| \\ | \\ | ||
| - | The last component we are going to add, is a push button. Click the <color # | + | The last component we are going to add, is a push button. Click the <color # |
| \\ | \\ | ||
| \\ | \\ | ||
| {{ : | {{ : | ||
| \\ | \\ | ||
| + | You will see a Pushbutton added to your project. | ||
| + | \\ | ||
| + | \\ | ||
| + | {{ : | ||
| + | \\ | ||
| + | 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. | ||
| + | \\ | ||
| + | \\ | ||
| + | {{ : | ||
| + | \\ | ||
| + | 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. | ||
| + | \\ | ||
| + | \\ | ||
| + | {{ : | ||
| + | \\ | ||
| + | This is the hardware part complete. What we have done, is connected the following: | ||
| + | \\ | ||
| + | * The LED/ | ||
| + | * The button between GPIO 16 and GND. (GND = Ground). | ||
| + | \\ | ||
| + | \\ | ||
| + | Now, we need to add the Micro Python code. | ||
| + | \\ | ||
| + | < | ||
| + | # Hardware Test | ||
| + | # Blink and LED (GP14) slowly/ | ||
| + | from machine import Pin # Import Pin class to control GPIO pins | ||
| + | from time import sleep_ms | ||
| + | led = Pin(14, Pin.OUT) | ||
| + | button = Pin(16, Pin.IN, Pin.PULL_UP) | ||
| + | |||
| + | 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() | ||
| + | sleep_ms(delay) | ||
| + | </ | ||
| + | |||
| + | 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. | ||
| + | \\ | ||
| + | \\ | ||
| + | {{ : | ||
| + | \\ | ||
| + | To start the Micro Python code, click the <color # | ||
| + | \\ | ||
| + | \\ | ||
| + | You will see the LED start to flash slowly. | ||
| + | \\ | ||
| + | \\ | ||
| + | {{ : | ||
| + | \\ | ||
| + | If you click the button with the mouse (or shortcut if you created one) then the LED will start to flash much faster. | ||
| + | \\ | ||
| + | \\ | ||
| + | ---- | ||
| + | Congratulations, | ||
| + | \\ | ||
| + | \\ | ||
| + | ---- | ||
button_controlled_led.1783633717.txt.gz · Last modified: by walkeradmin
