The NeoTrellis M4 is "some awesome hardware" as Charlotte the Spider would say. There are some pretty great demos on the Adafruit Learning System for using it.

All work and no play, well let's say the NeoTrellis isn't going to heavy lifting 24/7. Say you or your young one want a simple game in between gigs? 

This tutorial turns your NeoTrellis into a simple paint program in seconds. Fun for young and old. You can change the keys to any of 12 colors (plus off/black).

Parts

Hands pressing buttons on lit up NeoTrellis M4
So you've got a cool/witty name for your band, a Soundcloud account, a 3D-printed Daft Punk...
$59.95
In Stock
USB cable - USB A to Micro-B - 3 foot long
This here is your standard A to micro-B USB cable, for USB 1.1 or 2.0. Perfect for connecting a PC to your Metro, Feather, Raspberry Pi or other dev-board or...
Out of Stock

Optional portable power

Angled shot of a blue long rectangular USB battery pack.
A smaller-sized rechargeable battery pack for your Raspberry Pi or Raspberry...
$14.95
In Stock

Plug your NeoTrellis into a USB port on your computer with a known good USB data+power cable. In your file explorer/finder, you should see a new flash drive named CIRCUITPY pop up.

If you see a new drive named TRELM4BOOT, you will need to load CircuitPython onto your NeoTrellis first. See this page to do so. Your board should reboot when you put the code on the board and a CIRCUITPY drive should now be available.

Code

Click the Download Project Bundle below to get a zip file with the code.py file and the library files needed. 

Copy the files over to the CIRCUITPY drive, the code.py into the main directory, the .mpy file into the /lib subdirectory.

# SPDX-FileCopyrightText: 2018 Anne Barela for Adafruit Industries
#
# SPDX-License-Identifier: MIT

# Simple paint program for Trellis M4 Express
# Press any button it will cycle through a palette of colors!
#
# Anne Barela for Adafruit Industries   November, 2018
#
import time
import adafruit_trellism4

trellis = adafruit_trellism4.TrellisM4Express()

# See https://www.w3schools.com/colors/colors_picker.asp
RED = 0xFF0000
ORANGE = 0xB34700
YELLOW = 0xFFFF00
OLIVE = 0x66DD00
GREEN = 0x008000
AQUA = 0x00FF66
TEAL = 0x00BFFF
BLUE = 0x0080FF
NAVY = 0x000080
MAROON = 0x800000
PURPLE = 0x800080
PINK = 0xFF66B3
WHITE = 0xFFFFFF
BLACK = 0x000000

color_cycle = [BLACK, RED, ORANGE, YELLOW, OLIVE, GREEN, AQUA,
               TEAL, BLUE, NAVY, MAROON, PURPLE, PINK, WHITE]

colors = 13  # Number of colors in color_cycle

key_state = [0 for _ in range(32)]  # All keys are color 0 (BLACK)

trellis.pixels.fill(BLACK)  # Turn off all pixels

current_press = set()
while True:
    pressed = set(trellis.pressed_keys)
    for press in pressed - current_press:
        if press:
            print("Pressed:", press)
            x, y = press
            pixel = (press[1] * 8) + press[0]
            if key_state[pixel] == colors:  # If we're at white
                key_state[pixel] = 0        #  Set back to black
            else:
                key_state[pixel] += 1       # Use next color
            # Change the pushed pixel to the next color
            trellis.pixels[x, y] = color_cycle[key_state[pixel]]

    time.sleep(0.08)
    current_press = pressed

Play!

Press the buttons to get colors. Use multiple presses to advance through the rainbow available. You can change the color of a button any time just by pushing it and cycling through the color palette.

The colors are defined in the code as RED, ORANGE, YELLOW, OLIVE, GREEN, AQUA, TEAL, BLUE, NAVY, MAROON, PURPLE, PINK, WHITE, and BLACK. You can change the value of any of these colors by changing the hexadecimal code next to the name.

Use any text editor to change the code. We suggest the Mu editor but you can use any editor that saves plain text. See this guide on installing Mu.

What values are good? I like to use the color picker at w3schools.com to make choices. Get the 6 digit alphanumeric (hexadecimal) code and put it after the # (which tells CircuitPython that the number following it is hexadecimal).

If you are adventurous, you can add or delete colors from color_cycle, just keep BLACK & WHITE where they are and change the variable colors to the number of colors in color_cycle including BLACK & WHITE.

The code looks for key pressed events and selects the next color in the palette when it detects a key has been pressed. 

There is no save/load in the code but you can look to modify the code as you'd like.

This guide was first published on Dec 19, 2018. It was last updated on Apr 16, 2024.