0

Adafruit MagTag Individual Neopixels
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Adafruit MagTag Individual Neopixels

by benvien on Wed Feb 17, 2021 4:57 pm

I am trying to address the Neopixels on D1 of the MagTag using the code below, but it doesn't seem to take. I know this can be done with other boards such as Circuit Playground. Are the individual Neopixels on the MagTag addressable in this way?

This code works and lights up all Neopixels
Code: Select all | TOGGLE FULL SIZE
import time
from adafruit_magtag.magtag import MagTag

magtag = MagTag()

button_colors = ((0, 255, 0), (255, 0, 0), (255, 255, 0), (0, 0, 255))
button_low_tones = (130.82, 146.83, 164.81, 174.61)
button_mid_tones = (261.63, 293.66, 329.63, 349.23)

while True:
    magtag.peripherals.neopixel_disable = False
    magtag.peripherals.neopixels.fill(button_colors[3])


This code does not work and gives the error below
Code: Select all | TOGGLE FULL SIZE
import time
from adafruit_magtag.magtag import MagTag

magtag = MagTag()

button_colors = ((0, 255, 0), (255, 0, 0), (255, 255, 0), (0, 0, 255))
button_low_tones = (130.82, 146.83, 164.81, 174.61)
button_mid_tones = (261.63, 293.66, 329.63, 349.23)

while True:
    magtag.peripherals.neopixel_disable = False
    magtag.peripherals.neopixels[1].fill(button_colors[3])

Error is :
code.py output:
Traceback (most recent call last):
File "code.py", line 14, in <module>
AttributeError: 'tuple' object has no attribute 'fill'

benvien
 
Posts: 5
Joined: Tue Feb 20, 2018 10:43 pm

Re: Adafruit MagTag Individual Neopixels

by dastels on Wed Feb 17, 2021 6:12 pm

Right.

Code: Select all | TOGGLE FULL SIZE
magtag.peripherals.neopixels[1]

is the color of the second NeoPixel, a tuple (red, green, blue)

If you want to set the color of a single pixel you would assign to that:

Code: Select all | TOGGLE FULL SIZE
magtag.peripherals.neopixels[1] = button_colors[3]

Dave

dastels
 
Posts: 5394
Joined: Tue Oct 20, 2015 3:22 pm

Please be positive and constructive with your questions and comments.