Setting up Arduino IDE

You'll need the Adafruit Arduino IDE and the special config for using the Trinket. Follow the introduction to Trinket guide for a full tutorial.
Once your Arduino IDE is setup for the 5V Trinket, create a new sketch. Paste in the example code. Goto file menu tools > Board > Adafruit Trinket 8Mhz. Then Tools > Programmer > USBtinyISP. Plug in a USB mini cable connecting your computer to the Trinket. Wait for the red LED to blink and get the upload code button.

Arduino Sketch

Use the code below to make the NeoPixel Ring LED's animate between two patterns. A spinning glow and a random spark effect.
// Low power NeoPixel goggles example.  Makes a nice blinky display
// with just a few LEDs on at any time...uses MUCH less juice than
// rainbow display!

#include <Adafruit_NeoPixel.h>

#define PIN 0

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(64, PIN);

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

void setup() {
  pixels.begin();
  pixels.setBrightness(255); // 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(64);
    pixels.setPixelColor(i, color);
    pixels.show();
    delay(10);
    pixels.setPixelColor(i, 64);
    break;
 
   case 1: // Spinny wheels (8 LEDs on at a time)
    for(i=0; i<64; i++) {
      uint32_t c = 0;
      if(((offset + i) & 7) < 4) c = color; // 4 pixels on...
      pixels.setPixelColor(   i, c); // First eye
      pixels.setPixelColor(32-i, c); // Second eye (flipped)
    }
    pixels.show();
    offset++;
    delay(40);
    break;
  }

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

This guide was first published on Jun 18, 2014. It was last updated on Jun 18, 2014.

This page (Code) was last updated on Jun 17, 2014.

Text editor powered by tinymce.