First, we have
led.value = True
. This line tells the LED to turn on. On the next line, we have
time.sleep(0.5)
. This line
is telling CircuitPython to pause running code for 0.5 seconds. Since this is between turning the led on and off, the led
will be on for 0.5 seconds.
The next two lines are similar.
led.value = False
tells the LED to turn off, and
time.sleep(0.5)
tells CircuitPython to
pause for another 0.5 seconds. This occurs between turning the led off and back on so the LED will be off for 0.5
seconds too.
Then the loop will begin again, and continue to do so as long as the code is running!
So, when you changed the first
0.5
to
0.1
, you decreased the amount of time that the code leaves the LED on. So it
blinks on really quickly before turning off!
Great job! You've edited code in a CircuitPython program!
More Changes
We don't have to stop there! Let's keep going. Change the second
0.5
to
0.1
so it looks like this:
Now it blinks really fast! You decreased the both time that the code leaves the LED on and off!
Now try increasing both of the
0.1
to
1
. Your LED will blink much more slowly because you've increased the amount
of time that the LED is turned on and off.
Well done! You're doing great! You're ready to start into new examples and edit them to see what happens! These
were simple changes, but major changes are done using the same process. Make your desired change, save it, and
get the results. That's really all there is to it!
Naming Your Program File
CircuitPython looks for a code file on the board to run. There are four options: code.txt, code.py, main.txt and main.py.
CircuitPython looks for those files, in that order, and then runs the first one it finds. While we suggest using code.py as
your code file, it is important to know that the other options exist. If your program doesn't seem to be updating as you
work, make sure you haven't created another code file that's being read instead of the one you're working on.
while True:
led.value = True
time.sleep(0.5)
led.value = False
time.sleep(0.5)
while True:
led.value = True
time.sleep(0.1)
led.value = False
time.sleep(0.1)
© Adafruit Industries
https://learn.adafruit.com/adafruit-feather-m4-express-atsamd51
Page 53 of 183