Trinket M0, Gemma M0, ItsyBitsy M0 Express, and ItsyBitsy M4 Express each have an onboard Dotstar LED, so no
changes are needed to the initial version of the example.
Feather M0 Express, Feather M4 Express, Metro M0 Express, Metro M4 Express, and Circuit Playground Express
each have an onboard NeoPixel LED, so you must comment out
import adafruit_dotstar
and
led =
adafruit_dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1)
, and uncomment
import neopixel
and
led =
neopixel.NeoPixel(board.NEOPIXEL, 1)
.
Brightness
To set the brightness you simply use the
brightness
attribute. Brightness is set with a number between
0
and
1
,
representative of a percent from 0% to 100%. So,
led.brightness = (0.3)
sets the LED brightness to 30%. The default
brightness is
1
or 100%, and at it's maximum, the LED is blindingly bright! You can set it lower if you choose.
Main Loop
LED colors are set using a combination of red, green, and blue, in the form of an (R, G, B) tuple. Each member of the
tuple is set to a number between 0 and 255 that determines the amount of each color present. Red, green and blue in
different combinations can create all the colors in the rainbow! So, for example, to set the LED to red, the tuple would
be (255, 0, 0), which has the maximum level of red, and no green or blue. Green would be (0, 255, 0), etc. For the
colors between, you set a combination, such as cyan which is (0, 255, 255), with equal amounts of green and blue.
The main loop is quite simple. It sets the first LED to red using
(255, 0, 0)
, then green using
(0, 255, 0)
, and finally
blue using
(0, 0, 255)
. Next, we give it a
time.sleep()
so it stays each color for a period of time. We chose
time.sleep(0.5)
, or half a second. Without the
time.sleep()
it'll flash really quickly and the colors will be difficult to
see!
Note that we set
led[0]
. This means the first, and in the case of most of the boards, the only LED. In CircuitPython,
counting starts at 0. So the first of any object, list, etc will be
0
!
Remember: To "comment out" a line, put a # and a space before it. To "uncomment" a line, remove the # +
space from the beginning of the line.
© Adafruit Industries
https://learn.adafruit.com/adafruit-feather-m4-express-atsamd51
Page 129 of 183