If this is your first time using Trinket, work through the Introducing Trinket guide first; you need to customize some settings in the Arduino IDE. Once you have it up and running (test the 'blink' sketch), then download and install the NeoPixel library:
Installing Arduino libraries is a frequent stumbling block. If this is your first time, or simply needing a refresher, please read the All About Arduino Libraries tutorial.
If the library is correctly installed (and the Arduino IDE is restarted), you should be able to navigate through the “File” rollover menus as follows:


You’ll need to change one line in this code. If using Trinket, change line #3 to:
#define PIN 4
And for Gemma, use:
#define PIN 1
From the Tools→Board menu, select Adafruit Trinket 8 MHz or Adafruit Gemma as appropriate. Connect the USB cable between the computer and Trinket, press the reset button on the board, then click the upload button (right arrow icon) in the Arduino IDE. When the battery is connected, you should get a light show from the LEDs.

If that’s working, you can then copy and paste this Larson scanner code into a new sketch. Change N_LEDS to match the number of LEDs in your strip, and if using Gemma change PIN to 1. Upload and get ready to be a Cylon!
#include <Adafruit_NeoPixel.h>

#define N_LEDS 22
#define PIN     4

Adafruit_NeoPixel strip = Adafruit_NeoPixel(N_LEDS, PIN, NEO_GRB + NEO_KHZ800);

void setup() {

int pos = 0, dir = 1; // Position, direction of "eye"

void loop() {
  int j;

  // Draw 5 pixels centered on pos.  setPixelColor() will clip any
  // pixels off the ends of the strip, we don't need to watch for that.
  strip.setPixelColor(pos - 2, 0x100000); // Dark red
  strip.setPixelColor(pos - 1, 0x800000); // Medium red
  strip.setPixelColor(pos    , 0xFF3000); // Center pixel is brightest
  strip.setPixelColor(pos + 1, 0x800000); // Medium red
  strip.setPixelColor(pos + 2, 0x100000); // Dark red;

  // Rather than being sneaky and erasing just the tail pixel,
  // it's easier to erase it all and draw a new one next time.
  for(j=-2; j<= 2; j++) strip.setPixelColor(pos+j, 0);

  // Bounce off ends of strip
  pos += dir;
  if(pos < 0) {
    pos = 1;
    dir = -dir;
  } else if(pos >= strip.numPixels()) {
    pos = strip.numPixels() - 2;
    dir = -dir;
Last updated on 2015-05-04 at 04.27.56 PM Published on 2013-09-23 at 04.55.27 PM