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 22:00] – [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 99: | Line 97: | ||
| {{ : | {{ : | ||
| \\ | \\ | ||
| + | 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.1783634425.txt.gz · Last modified: by walkeradmin
