import board
import digitalio
import time
led = digitalio.DigitalInOut(board.D13)
led.direction = digitalio.Direction.OUTPUT
while True:
led.value = True
time.sleep(0.5)
led.value = False
time.sleep(0.5)
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. These files are called
libraries. Some of them are built into CircuitPython. Others 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 in your code. In this example, we
import
imported three libraries:
separate files are needed. That's one of the things that makes this an excellent first example. You don't need any thing
extra to make it work!
board
as inputs/outputs and
time
Setting Up The LED
The next two lines setup the code to use the LED.
led = digitalio.DigitalInOut(board.D13)
led.direction = digitalio.Direction.OUTPUT
Your board knows the red LED as
of that information so we don't have to type it all out again later in our code.
Loop-de-loops
The third section starts with a
creates a loop. Code will loop "while" the condition is "true" (vs. false), and as
True:
loop forever. All code that is indented under
Inside our loop, we have four items:
© Adafruit Industries
,
, and
board
digitalio
time
gives you access to the hardware on your board ,
let's you pass time by 'sleeping'
. So, we initialise that pin, and we set it to output. We set
D13
statement.
while
while True:
while True:
https://learn.adafruit.com/adafruit-feather-m4-express-atsamd51
. All three of these libraries are built into CircuitPython, so no
essentially means, "forever do the following:".
is "inside" the loop.
lets you access that hardware
digitalio
to equal the rest
led
is never False, the code will
True
Page 52 of 183
while
Need help?
Do you have a question about the Feather M4 Express and is the answer not in the manual?