EasyManuals Logo

Adafruit Feather M4 Express User Manual

Adafruit Feather M4 Express
178 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 #123 background imageLoading...
Page #123 background image
CircuitPython Internal RGB LED
Every board has a built in RGB LED. You can use CircuitPython to control the color and brightness of this LED. There
are two different types of internal RGB LEDs: DotStar (https://adafru.it/kDg) and NeoPixel (https://adafru.it/Bej). This
section covers both and explains which boards have which LED.
The first example will show you how to change the color and brightness of the internal RGB LED.
Copy and paste the code into code.py using your favorite editor, and save the file.
Create the LED
First, we create the LED object and attach it to the correct pin or pins. In the case of a NeoPixel, there is only one pin
necessary, and we have called it NEOPIXEL for easier use. In the case of a DotStar, however, there are two pins
necessary, and so we use the pin names APA102_MOSI and APA102_SCK to get it set up. Since we're using the
single onboard LED, the last thing we do is tell it that there's only 1 LED!
import time
import board
# For Trinket M0, Gemma M0, ItsyBitsy M0 Express, and ItsyBitsy M4 Express
import adafruit_dotstar
led = adafruit_dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1)
# For Feather M0 Express, Metro M0 Express, Metro M4 Express, and Circuit Playground Express
# import neopixel
# led = neopixel.NeoPixel(board.NEOPIXEL, 1)
led.brightness = 0.3
while True:
led[0] = (255, 0, 0)
time.sleep(0.5)
led[0] = (0, 255, 0)
time.sleep(0.5)
led[0] = (0, 0, 255)
time.sleep(0.5)
© Adafruit Industries https://learn.adafruit.com/adafruit-feather-m4-express-atsamd51 Page 128 of 183

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Adafruit Feather M4 Express and is the answer not in the manual?

Adafruit Feather M4 Express Specifications

General IconGeneral
BrandAdafruit
ModelFeather M4 Express
CategoryMicrocontrollers
LanguageEnglish

Related product manuals