The adafruit_fruitjam library makes controlling the five neopixels on the board pretty easy...
Start with the basics
We begin by initializing the library and setting things up:
[note these are code snippets only - not a complete project]
# include the following in your import statements: from adafruit_fruitjam import FruitJam # then define the board (I am using "jam" to reference the board) and optionally set the brightness: jam = FruitJam() jam.neopixels.brightness = 0.1
From here you can use the standard neopixel "fill" and "show" to control the neopixels altogether. To refer to the neopixel object you reference them by 'jam.neopixels' (note the s on the end) followed by the command. For example, a classic red blink would simply be:
print("Blink Forever!")
while True:
jam.neopixels.fill(0xFF0000)
jam.neopixels.show()
time.sleep(1)
jam.neopixels.fill(0x000000)
jam.neopixels.show()
time.sleep(1)
We can also address each pixel individually using their index (0 - 4). Recall that addressing individuals pixels in a strip of neopixels you just set the specific neopixel index to the color you want (fill is used for all on the strip), To blink only the middle neopixel, the code would be:
while True:
jam.neopixels[2] = 0xFF0000 # make the middle pixel red
time.sleep(1)
jam.neopixels[2] = 0x000000 # make the middle pixel black (off)
time.sleep(1)
Getting Fancy
Once I had the basics down, I thought it might be useful to create a function that could feed a color and an index - sort of a Swiss Army Knife function. First, I set up a dictionary for color names to make it easier to specify colors:
COLORS = {
'red': 0xFF0000,
'blue': 0x0000FF,
'green': 0x00FF00,
'yellow': 0xFFFF00,
'magenta': 0xFF00FF,
'black': 0x000000,
}
You can create as many different colors as you want with a name/hex value pair. For example you might want to include 'white' : 0xFFFFFFÂ in your list.
I also wanted the flexibility to control more than one at a time to the same color. So, I turned to my new pal AI (I use CoPilot in VS Code using Claude Sonnet 4.5). It came up with the following function:
def set_neopixel(pixel_index=None, color=None):
"""Set one or more neopixels to a specific color.
Args:
pixel_index (int, list, tuple, or None): Single index (0-4), list/tuple of indices, or None for all pixels
color (int or str): RGB color value in hexadecimal format (e.g., 0xFF0000)
or color name from COLORS dictionary (e.g., 'red', 'blue')
Example usage:
set_neopixel() # Set all pixels to black (off) - no index or color specified
set_neopixel(color='red') # Set all pixels to red (no index specified - defaults to all)
set_neopixel([0, 1, 2, 3, 4], 'green') # Set all pixels to green - indexes each individually
set_neopixel(0, 'red') # Set pixel 0 to red
set_neopixel([0, 2], 'magenta') # Set pixels 0 and 2 to magenta - input is a list
set_neopixel((1, 3, 4), 'blue') # Set pixels 1, 3, and 4 to blue - input is a tuple
set_neopixel(4, 0x0000FF) # Set pixel 4 to blue using hex value
"""
# If no index is provided, set all pixels (0-4)
if pixel_index is None:
indices = [0, 1, 2, 3, 4]
# Convert single index to list for uniform processing
elif isinstance(pixel_index, int):
indices = [pixel_index]
elif isinstance(pixel_index, (list, tuple)):
indices = list(pixel_index)
else:
print("Error: pixel_index must be an integer, list, tuple, or None.")
return
# Validate all indices are in range
for idx in indices:
if not (0 <= idx <= 4):
print(f"Error: Pixel index {idx} is out of range. Valid range is 0-4.")
return
# Default to black (off) if no color is specified
if color is None:
color_value = 0x000000
# Convert color name to hex value if needed
elif isinstance(color, str):
if color.lower() in COLORS:
color_value = COLORS[color.lower()]
else:
print(f"Error: Color '{color}' not found. Available colors: {list(COLORS.keys())}")
return
else:
# Assume it's already a hex value
color_value = color
# Set all specified pixels to the color
for idx in indices:
jam.neopixels[idx] = color_value
# Update display once after all changes
jam.neopixels.show()
It is important to note that this function references the board as jam which was the definition that I used to set up the board. If you use a different reference, make sure your function reflects the same. Likewise, the function references the dictionary COLORS. If you use a different name, be sure to update the function.
It was a pretty impressive function on the first try. For example, it suggested that the index inputs could be a single integer (for one) or a tuple or a list to refer to multiple index values.Â
I did go through a couple iterations with the AI to fine tune the functionality. For example, I asked to default the index to all if no index is specified (so it is easy to set them all at once). Then, since you typically need to turn them all off before doing something else, I added the color default to 'black' (i.e. off). This way, a simple call to the function with no arguments sets all neopixels to off. Easy peasy!
AI also did a good job documenting the code - there is a good list of embedded examples.Â
Last Watchout
Note that the power of the Fruit Jam library is that it handles a lot of the board's functionality, not just the neopixels. As such, the library sometimes uses the neopixels for status indicators.
For example, wi-fi connectivity is indicated by the neopixel colors. If, say, you use the set_neopixel() function to set the colors one way, then you do something that triggers connecting to wi-fi, the other library activity will take over what you have set the neopixels to. So, if you set your neopixels just so... and then they all turn blue, this is probably why. Be prepared to deal with this and consider where you set the colors of your neopixels. [There is probably a way to turn off this behavior, but I haven't figured that out yet].
This page (Fun with Fruit Jam Neopixels) was last updated on October 20, 2025.
Text editor powered by tinymce.