Software

Configure Trinket for Arduino

Install the proper modifications and libraries to your installation of Arduino to configure the Trinket.

Uploading Code to Trinket with Arduino

Copy and paste the code below into a new sketch in Arduino. Select Trinket 5V 8Mhz board from the Tools menu. Plug in a USB cable from the trinket to your computer. Make sure your programmer is set to USBtinyISP before you upload the code to the Trinket. Hit the upload code while the red LEDs are blinking on the Trinket.
Download: file
#include <Adafruit_NeoPixel.h>

#define PIN 0

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(54, PIN);

uint8_t  mode   = 1, // Current animation effect
         offset = 0; // Position of spinny eyes
uint32_t color  = 0x00ff96; // Start red
uint32_t prevTime;

void setup() {
  pixels.begin();
  pixels.setBrightness(50); // 1/3 brightness
  prevTime = millis();
}

void loop() {
  uint8_t  i;
  uint32_t t;

  switch(mode) {

   case 0: // Random sparks - just one LED on at a time!
    i = random(20);
    pixels.setPixelColor(i, color);
    pixels.show();
    delay(10);
    pixels.setPixelColor(i, 0);
    break;
 
   case 1: // Spinny wheels (8 LEDs on at a time)
    for(i=0; i<54; i++) {
      uint32_t c = 0;
      if(((offset + i) & 7) < 4) c = color; // 4 pixels on...
      pixels.setPixelColor(   i, c); // First eye
      pixels.setPixelColor(31-i, c); // Second eye (flipped)
    }
    pixels.show();
    offset++;
    delay(90);
    break;
  }

  t = millis();
  if((t - prevTime) > 8000) {      // Every 8 seconds...
    mode++;                        // Next mode
    if(mode > 1) {                 // End of modes?
      mode = 1;                    // Start modes over
      color >>= 0  ;                 // Next color R->G->B
      if(!color) color = 0x00ff96; // Reset to red
    }
    for(i=0; i<54; i++) pixels.setPixelColor(i, 0);
    prevTime = t;
  }
}

Customization

Some values to look for when adapting the sketch to your project are the number of pixels. Searching for "54" and replacing that value with whatever number of pixels are used your project is a good start. The color is conveniently formatted in HEX, "00ff96" makes a teal color. The duration of the animation can be changed by adjusting the delay "90" which is in measured in milliseconds.
This guide was first published on Jul 15, 2014. It was last updated on Jul 15, 2014. This page (Software) was last updated on Sep 15, 2019.