EasyManua.ls Logo

SunFounder ESP32

Default Icon
771 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
SunFounder ESP32 Starter Kit
Code
Note:
Open the 5.6_transistor.py file located in the esp32-starter-kit-main\micropython\codes path, or
copy and paste the code into Thonny. Then, click “Run Current Script” or press F5 to execute it.
Make sure to select the “MicroPython (ESP32).COMxx” interpreter in the bottom right corner.
import machine
button = machine.Pin(14, machine.Pin.IN) # Button
led = machine.Pin(26, machine.Pin.OUT) # LED
# Start an infinite loop
while True:
# Read the current value of the 'button' object (0 or 1) and store it in the 'button_
˓status' variable
button_status = button.value()
# If the button is pressed (value is 1)
if button_status == 1:
led.value(1) # Turn the LED on
# If the button is not pressed (value is 0)
else:
(continues on next page)
378 Chapter 3. For MicroPython User

Table of Contents