This year’s Halloween preparations were a coping mechanism. There is so much going on in the world that I cannot control, objectively more so than ever. Taking on good projects that involve making and coding is a good way to take back a sense of that control.
Halloween has always been an effective deadline for making things happen. I also have a history of making things that involve blinking LEDs for what I wear going out. My first such attempt was an NYC Crosswalk sign thirteen years ago. With my Advanced Automation learning to use state machines, I also wanted to give examples of how these work.
Each of the projects below has links to the code. I teach my students to think about state machines in three steps:
- what are the different states that the system should be in?
- what changes to sensors, timers, or other system variables should trigger changes between states?
- what system variables do you need to read, update, or keep track of during each loop for the system to function?
I’ve found that teaching state machines this way is getting students to write more organized code that is easier to debug because it is more modular than it would otherwise be. I might talk more about this approach in a later post. Right now, let’s talk about getting some circuit boards to light up for Halloween!
Heart of Te Fiti from Moana
My daughter wanted to dress like Moana this year. I knew the best way I could contribute to the costume was to build her a glowing version of the Heart of Te Fiti, the green stone that pushes forward the plot of the movie. I traced the image from this Instagram post to make an SVG that I could use in a 3D model:
I used Onshape to build several versions of a 3D model of the heart that could hold an Adafruit Trinket Express to handle the glowing part. I also added a hole so that this could be used as a necklace after trick-or-treating. Here’s the final version:
I learned a lot about building a model to be 3D printed that press fits together. The back of the necklace presses in to the front with just enough friction that it stays together well enough for at least one night of a nearly five year old to run around with it. There is enough space for a 50 mAh LiPo battery to sit inside and power the necklace for a couple of hours.
The heart in the movie glows a beautiful green. I wanted to add two variations on this steady glow. One is a slowly pulsating green light that is timed to pulse with relaxed breaths in and out. This uses the analog out pin of the Trinket. The other is a pulse resembling a heart beat, handled by the Dotstar pixel in the middle of the Trinket. In the final version, I added a random pause between heartbeats that makes this act like it is actually alive. I really like the effect of the final product:
Tony Stark Arc Reactor
Finishing the heart necklace got me thinking about doing something similar for my own costume, but I was running out of time. I decided to go for an Infinity War version and 3D printed this model.
Since I had a Circuit Playground Bluefruit, the ring of Neopixels was perfect to use for powering the glowing effect. The Cyan color of red: 0, green: 255, blue: 255 was about right for the blue glow shown in the movie.
In the version I wore during the day on Friday, the pulsating was really subtle and slow. I changed the code before heading out for the evening because I realized I wasn’t taking full advantage of the Bluetooth capabilities of the Circuit Playground Bluefruit. I added the ability to change the base color of the flash using the Bluefruit LE connect app. I also added some math to make the flashing move between the minimum brightness and the color values, but this led to some weird behavior that I didn’t get to smooth out. Speeding up the flash rate made it hard to see this happen, but this still bugs me. Here’s the final version:
These were really fun projects, and got me to dig into some details of using CircuitPython in more creative ways than in the past. I’m excited to share more as I learn more.