As last year, Eric's and Stuart's halloween costumes were home-made, thanks to a month of crazy late-night sewing sessions by Juimiin. Eric wanted to dress as a lamp, and Stuart eventually decided on a comparatively simple tiger.

Juimiin wrestled for a long time with the various internal stiffeners and odd shapes to make the thing look like that. She used prototypes from cardboard, miniature and full-sized, until it was good enough.

My small contribution was to add a bit of glitter to Eric's lamp headpiece: something to light it up. A simple disembodied flashlight was ruled out as not interesting enough. Instead, the idea was to put a ring of LEDs around the rim of the lamp shade, and have the lights do some little dance. That needed a little microcontroller, a little power supply, some LEDs, and some connecting wires.

Our home electronics supplies running a little low, but a bit of shopping around suggested that the Lilypad Arduino system would be a good choice. A few days after ordering a bunch of parts from SparkFun, and grieving over the hideous shipping/handling charges to get the stuff here, a big box arrived. It was perfect.

The microcontroller has 12 digital outputs, which can be wired directly to the tiny LED+resistor modules. Software for it is written in C, with a reasonable amount of on-board flash storage. The workstation connection hardware and the editor/compiler/loader software is straightforward. My little animation program worked the first time I tried it, with only a few LEDs connected with alligator clips.

It was time to install the thing into the costume. I decided to sew all the machinery into the face of the cone, where it would be visible to people curious about how it worked. In the Lilypad scheme, the specially provided sewing thread not only fastens the boards to the cloth, but also functions as conductive wiring.. It was important not to short-circuit parts of the circuit, so loose ends of the threads had to be meticulously trimmed. Yet, to make a good surface-touching (unsoldered) connection to the connectors, several nested loops were needed.

Eric showed off the complete glittery costume -- let's just call it "crazy desk lamp with lights" -- several times during the next few days. He liked it and a lot of people just stared. Mission accomplished.

void setup () {
  unsigned i;
  for (i=2; i<13; i++)
    pinMode(i,OUTPUT);
  randomSeed (analogRead (0));
}

// mode 0: ring around the daisy
void mode0 () {
  static int horse = 2;
  const int interval = 80;
  static unsigned long lt = 0;
  unsigned long t = millis();
  unsigned i;
  if (lt == 0) lt = t;
  if (t > (lt + interval)) {
    lt = lt + interval;
    digitalWrite (horse, LOW);
    horse = horse + 1; if (horse == 14) horse = 2;
    digitalWrite (horse, HIGH);
  }  
}

// random sparkle
void mode1 () {
  static int horse = 2;
  const int interval = 20; // flash interval
  static int dark = 10; // number of intervals of darkness
  static unsigned long lt = 0;
  unsigned long t = millis();
  unsigned i;
  if (lt == 0) lt = t;
  if (t > (lt + interval)) {
    lt = lt + interval;
    digitalWrite (horse, LOW);
    dark --;
    if (dark <= 0) {
      horse = random (2, 14);
      digitalWrite (horse, HIGH); 
      dark = 10;
    }
  }  
}

void loop () {
  static unsigned long lt = 0;
  unsigned long t = millis();
  static int mode = 0;
  const int interval = 7500;
  if (lt == 0) lt = t;
  if (t > lt+interval) {
    lt = lt + interval;
    mode ++;
  }
  switch (mode) {
    case 0: mode0(); break; 
    case 1: mode1(); break;
    default: mode = 0; break;
  }
}