Trinket projects have their own unique challenges. It’s not simply the matter of less RAM, code space and fewer pins. In such a constrained system, the interactions between parts sometimes require careful planning and working in unusual ways…
- To simplify the parts list, we’re using the USB connection for power. Trinket pins #3 and #4 are involved in USB communication. Even when we’re not uploading to the chip, there may be other “chatter” on the bus…and using these pins as inputs would cause false readings. An alternative design to regain use of these pins would be to disconnect the board from USB after programming and attach a battery to the BAT and GND pins. But these same pins are usually fine for outputs and won’t interfere.
- Pins #0 and #2 are reserved when using I²C communication (via the Wire library), required for the LED backpack in this project.
- That leaves pin #1 as the last possible input…but this pin is also connected to the board’s red status LED. The usual technique for connecting a button — using the microcontroller’s internal pull-up resistors — won’t work here (the LED turns on and always pulls the input low). So we cheat a little here and use the same LED (and its associated resistor) as a pull-down. One leg of the pushbutton connects to this pin, the other leg to the +5V/3V supply. The pin then reads as HIGH when the button is pressed, LOW when released. This has a nifty secondary bonus effect that the LED lights each time the button is pressed. (Pin #1 is fine as an input as long as you don’t require the internal pull-up.)
While the 7-segment LED backpack works with Trinket, our 8x8 LED matrix backpacks do not. There simply isn’t enough room for the code. Yet we still need to #include the Adafruit_GFX library…the LED backpack library depends on it (only the 7-segment parts are linked into our sketch, that’s how it manages to fit). That’s not to say that Trinket couldn’t control the matrices…but it would require developing a smaller, limited library for that one task.