[{"element_type":"text","content":"\n        \u003cp\u003eThe \u003cstrong\u003eadafruit_fruitjam\u003c/strong\u003e library makes controlling the five neopixels on the board pretty easy...\u003c/p\u003e\n\u003ch2\u003e\u003cstrong\u003eStart with the basics\u003c/strong\u003e\u003c/h2\u003e\n\u003cp\u003eWe begin by initializing the library and setting things up:\u003c/p\u003e\n\u003cp\u003e\u003cem\u003e[note these are code snippets only - not a complete project]\u003c/em\u003e\u003c/p\u003e\n      ","metadata":{}},{"element_type":"code","content":"# include the following in your import statements:\n\nfrom adafruit_fruitjam import FruitJam\n\n# then define the board (I am using \"jam\" to reference the board) and optionally set the brightness:\n\njam = FruitJam()\njam.neopixels.brightness = 0.1","metadata":{"language":"python","linenums":false,"filename":""}},{"element_type":"text","content":"\n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n        \u003cp\u003eFrom 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 '\u003cem\u003ejam.neopixels\u003c/em\u003e' (note the s on the end) followed by the command. For example, a classic red blink would simply be:\u003c/p\u003e\n      \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n","metadata":{}},{"element_type":"code","content":"print(\"Blink Forever!\")\nwhile True:\n    jam.neopixels.fill(0xFF0000)\n    jam.neopixels.show() \n    time.sleep(1)\n    jam.neopixels.fill(0x000000)\n    jam.neopixels.show()\n    time.sleep(1)","metadata":{"language":"python","linenums":false,"filename":""}},{"element_type":"text","content":"\n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n        \u003cp\u003eWe 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 (\u003cem\u003efill\u003c/em\u003e is used for all on the strip), To blink only the middle neopixel, the code would be:\u003c/p\u003e\n      \n\n\n\n\n\n\n\n\n\n\n","metadata":{}},{"element_type":"code","content":"while True:\n    jam.neopixels[2] = 0xFF0000 # make the middle pixel red\n    time.sleep(1)\n    jam.neopixels[2] = 0x000000 # make the middle pixel black (off)\n    time.sleep(1)","metadata":{"language":"auto","linenums":false,"filename":""}},{"element_type":"text","content":"\n  \n  \n  \n  \n  \n  \n  \n  \n  \n        \u003ch2\u003e\u003cstrong\u003eGetting Fancy\u003c/strong\u003e\u003c/h2\u003e\n\u003cp\u003eOnce 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 \u003cem\u003eSwiss Army Knife\u003c/em\u003e function. First, I set up a dictionary for color names to make it easier to specify colors:\u003c/p\u003e\n      \n\n\n\n\n\n\n\n\n","metadata":{}},{"element_type":"code","content":"COLORS = {\n    'red': 0xFF0000,\n    'blue': 0x0000FF,\n    'green': 0x00FF00,\n    'yellow': 0xFFFF00,\n    'magenta': 0xFF00FF,\n    'black': 0x000000,\n}","metadata":{"language":"auto","linenums":false,"filename":""}},{"element_type":"text","content":"\n  \n  \n  \n  \n  \n  \n  \n  \n        \u003cp\u003eYou can create as many different colors as you want with a name/hex value pair. For example you might want to include \u003cstrong\u003e'white' : 0xFFFFFF\u0026nbsp;\u003c/strong\u003ein your list.\u003c/p\u003e\n\u003cp\u003eI 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:\u003c/p\u003e\n      \n\n\n\n\n\n\n\n","metadata":{}},{"element_type":"code","content":"def set_neopixel(pixel_index=None, color=None):\n    \"\"\"Set one or more neopixels to a specific color.\n    \n    Args:\n        pixel_index (int, list, tuple, or None): Single index (0-4), list/tuple of indices, or None for all pixels\n        color (int or str): RGB color value in hexadecimal format (e.g., 0xFF0000) \n                           or color name from COLORS dictionary (e.g., 'red', 'blue')\n    \n    Example usage:\n        set_neopixel()                      # Set all pixels to black (off) - no index or color specified\n        set_neopixel(color='red')           # Set all pixels to red (no index specified - defaults to all)\n        set_neopixel([0, 1, 2, 3, 4], 'green') # Set all pixels to green - indexes each individually\n        set_neopixel(0, 'red')              # Set pixel 0 to red\n        set_neopixel([0, 2], 'magenta')     # Set pixels 0 and 2 to magenta - input is a list\n        set_neopixel((1, 3, 4), 'blue')     # Set pixels 1, 3, and 4 to blue - input is a tuple\n        set_neopixel(4, 0x0000FF)            # Set pixel 4 to blue using hex value\n    \"\"\"\n    # If no index is provided, set all pixels (0-4)\n    if pixel_index is None:\n        indices = [0, 1, 2, 3, 4]\n    # Convert single index to list for uniform processing\n    elif isinstance(pixel_index, int):\n        indices = [pixel_index]\n    elif isinstance(pixel_index, (list, tuple)):\n        indices = list(pixel_index)\n    else:\n        print(\"Error: pixel_index must be an integer, list, tuple, or None.\")\n        return\n    \n    # Validate all indices are in range\n    for idx in indices:\n        if not (0 \u003c= idx \u003c= 4):\n            print(f\"Error: Pixel index {idx} is out of range. Valid range is 0-4.\")\n            return\n    \n    # Default to black (off) if no color is specified\n    if color is None:\n        color_value = 0x000000\n    # Convert color name to hex value if needed\n    elif isinstance(color, str):\n        if color.lower() in COLORS:\n            color_value = COLORS[color.lower()]\n        else:\n            print(f\"Error: Color '{color}' not found. Available colors: {list(COLORS.keys())}\")\n            return\n    else:\n        # Assume it's already a hex value\n        color_value = color\n    \n    # Set all specified pixels to the color\n    for idx in indices:\n        jam.neopixels[idx] = color_value\n    \n    # Update display once after all changes\n    jam.neopixels.show()","metadata":{"language":"python","linenums":false,"filename":""}},{"element_type":"text","content":"\n  \n  \n        \u003cp\u003eIt is important to note that this function references the board as \u003cem\u003e\u003cstrong\u003ejam\u003c/strong\u003e\u003c/em\u003e 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 \u003cem\u003e\u003cstrong\u003eCOLORS\u003c/strong\u003e\u003c/em\u003e. If you use a different name, be sure to update the function.\u003c/p\u003e\n\u003cp\u003eIt 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.\u0026nbsp;\u003c/p\u003e\n\u003cp\u003eI did go through a couple iterations with the AI to fine tune the functionality. For example, I asked to default the index to\u0026nbsp;\u003cstrong\u003eall\u003c/strong\u003e 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 \u003cstrong\u003e'black'\u0026nbsp;\u003c/strong\u003e(i.e. off). This way, a simple call to the function with no arguments sets all neopixels to off. Easy peasy!\u003c/p\u003e\n\u003cp\u003eAI also did a good job documenting the code - there is a good list of embedded examples.\u0026nbsp;\u003c/p\u003e\n\u003ch3\u003e\u003cstrong\u003eLast Watchout\u003c/strong\u003e\u003c/h3\u003e\n\u003cp\u003eNote 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.\u003c/p\u003e\n\u003cp\u003eFor example, wi-fi connectivity is indicated by the neopixel colors. If, say, you use the\u0026nbsp;\u003cem\u003eset_neopixel()\u003c/em\u003e 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].\u003c/p\u003e\n      \n\n","metadata":{}}]