Obviously, since the hardware was so simple, this project is all about the code.
But you can just grab the code and upload it to your board.
Upload the Code
Use the Arduino IDE to upload the code to your board.
If you don't already have the Arduino IDE set up, check Simon Monk's excellent tutorial.
This was my first time using the Adafruit Metro. I chose this board because it uses surface-mount components which gives it a smooth bottom so it can sit on the floor of the pumpkin. It also has a real USB->Serial which makes development easier.
If you are running Windows or Mac, you will want to get the latest FTDI drivers.
I did that, but still had issues communicating with the Metro. Rebooting the computer solved the issue. Figuring out that I needed to reboot was the longest part of the project!
The code simulates "flames," each made of 3 NeoPixels. This allows us to use more resolution in the colors. Instead of each color channel having 256 possibled values, it has 768.
This makes color transitions smoother at low levels.
Each flame ramps from "off" to a color selected from the "flamecolors" table.
You can adust the colors in that table to change to colors of your candle.
This version is mostly reds, oranges, and yellows, with an occasional blue spike.
After a flame reaches it's peak value, it ramps back down to black.
To create a flicker effect, every time we decrease the brightness of a flame, we introduce a chance to reverse direction and start increasing brighness again.
You can adjust this with "FLICKER_CHANCE" constant. The higher the value, the more flickering.
The functions at end of the sketch, GetStepSize() and GetMaxBrightness() specify these values.
The larger the step size, the faster the flames grow.
GetMaxBrightness() has some alternative models commented out. If you want your flame "height" to be more uniform, try those models.