Imports & Libraries
Each CircuitPython program you run needs to have a lot of information to work. The
reason CircuitPython is so simple to use is that most of that information is stored in
other files and works in the background. The files built into CircuitPython are called m
odules, and the files you load separately are called libraries. Modules are built into
CircuitPython. Libraries are stored on your CIRCUITPY drive in a folder called lib.
import board
import digitalio
import time
The
statements tells the board that you're going to use a particular library or
import
module in your code. In this example, you imported three modules:
, and
digitalio
separate library files are needed. That's one of the things that makes this an excellent
first example. You don't need anything extra to make it work!
These three modules each have a purpose. The first one,
the hardware on your board. The second,
as inputs/outputs. The third,
ways, including passing time by 'sleeping'.
Setting Up The LED
The next two lines setup the code to use the LED.
led = digitalio.DigitalInOut(board.LED)
led.direction = digitalio.Direction.OUTPUT
Your board knows the red LED as
output. You set
led
all out again later in our code.
Loop-de-loops
The third section starts with a
"forever do the following:".
condition is "true" (vs. false), and as
All code that is indented under
©Adafruit Industries
. All three of these modules are built into CircuitPython, so no
time
, let's you control the flow of your code in multiple
time
LED
to equal the rest of that information so you don't have to type it
while
while True:
True
while True:
board
, lets you access that hardware
digitalio
. So, you initialise that pin, and you set it to
statement.
while True:
creates a loop. Code will loop "while" the
is never False, the code will loop forever.
is "inside" the loop.
,
board
, gives you access to
essentially means,
Page 49 of 263
Need help?
Do you have a question about the ESP32-S3 and is the answer not in the manual?