In this experiment, we will apply both LED module and button module to form a lighting device.
Required:
Step 1
Step 2
Step 3
Step 4
Step 5
Step 6
Step 7
Step 8
Completed!
Open 4.1Manual_lighting.py and click.
'''
* Filename : Manual_lighting
* Thonny : Thonny 4.1.4
* Auther : http//www.keyestudio.com
'''
from machine import Pin
import time
led = Pin(11, Pin.OUT)
button = Pin(3, Pin.IN)
while True:
if button.value() == 0: #press button
led.on() # led on
else:
led.off() # led off
Conceive:
Initialization: Set pins of white LED module and button module
Loop:
Determine whether the button is pressed. If it is, LED will light up. If not, LED will go off.
After uploading code, press the button, and LED lights up. When you release the button, LED is off.