Matrix Portal Jack-o-lantern
2020-10-29 | By Nate_Larson
License: General Public License
Halloween is a great opportunity to get creative. It is the one holiday where the possibilities are endless with very few guidelines. Whether you prefer a campy approach to delight the children, or a more ghoulish atmosphere to scare and excite those of a hardier constitution, Halloween is a chance to let your imagination run free. And while some may be content searching for the elusive 12ft skeleton with animated eyes from their local big box home improvement store, many of us like to take this opportunity to show off our skills with some custom creations.
(BTW, if you have a skeleton or skull with static eyes that you are looking to add some flair to, check out Adafruit’s Hallowing or Monster M4sk.)
This year we decided to add our spin to a classic from the before times, the infamous KXVO “Pumpkin Dance”, but of course, in homage to this cornerstone of modern Halloween internet virality, we needed to add some electronic panache. Cue the Adafruit Matrix Portal.
(Image Source: Adafruit)
The Matrix Portal is a CircuitPython and Arduino compatible ATSAMD M4 microcontroller board designed to plug directly onto any HUB-75 compliant LED matrix. The board also features an ESP32 module providing Wi-Fi connectivity making for a quick and easy solderless connected display.
(Image source: Adafruit)
For this build, we utilized two of the Matrix Portal boards, two of the 1528-2094-ND 64x32 LED matrices, and one pushbutton from the 1528-4431-ND STEMMA Wired Tactile Push-Button Pack, along with some assorted lengths of wire. Essentially, the build is two independent systems, the first consisting of just the Matrix Portal and LED matrix and following Adafruit’s Matrix Portal Creature Eyes learn guide by Phillip Burgess.
The eyes were modified from the werewolf example with changes made to the stencil, eyes, and upper and lower lid bitmaps, along with some adjustments to the data.py file to accommodate the new shapes. The eyes and mouth are going to be diffused through the thin orange plastic of our pumpkin, so only the whites of the eyes and open mouth should appear illuminated to correspond to the look of a lighted jack-o-lantern. All other regions of the display were adjusted to black.
The mouth was created by modifying the Halloween Countdown Display Matrix learn guide by John Park. Simplifying it down to a very basic stop motion animation that cycles through four frames from a closed to open mouth when a button is pressed, and back again when the button is released.
import time
import board
from adafruit_matrixportal.matrixportal import Matrix Portal
from digitalio import DigitalInOut, Direction, Pull
mouth = DigitalInOu(board.BUTTON_UP)
mouth.direction = Direction.INPUT
mouth.pull = Pull.UP
FRAME_DURATION = 0.05
FRAMES = (
“bmps/jack_closed_black.bmp”,
“bmps/jack_narrow_black.bmp”,
“bmps/jack_mid_black.bmp”,
“bmps/jack_wide_black.bmp”,
)
# --- Display setup ---
matrixportal = MatrixPortal(status_neopixel=board.NEOPIXEL, debug=True
current_frame=0
while True:
while not mouth.value:
If current_frame< 3:
Matrixportal.set_background(FRAMES[current_frame])
time.sleep(FRAME_DURATION)
current_frame + = 1
else:
matrixportal.set_background (FRAMES[current_frame])
while mouth.value:
if current_frame > 0:
matrixportal.set_background (FRAMES[current_frame])
time.sleep(FRAME_DURATION)
current_frame -= 1
else:
matrixportal.set_background (FRAMES[current_frame])
The code above makes use of the onboard “UP” button to activate the animation, but later this was changed to pin A4 and the Pull.UP statement removed when a handheld pushbutton was added, allowing our masked pumkineer to easily actuate the mouth to the sound while wearing the jack-o-lantern. Check out the video below to see the completed project in action and share your Halloween creations with us on social media using #MakeWithDigiKey.
Have questions or comments? Continue the conversation on TechForum, DigiKey's online community and technical resource.
Visit TechForum