EasyManuals Logo

SunFounder ESP32 User Manual

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
Page #384 background image
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

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the SunFounder ESP32 and is the answer not in the manual?

SunFounder ESP32 Specifications

General IconGeneral
BrandSunFounder
ModelESP32
CategoryController
LanguageEnglish