How I Coded my Costume

A few weeks ago we had our annual costume party at the office. This year I had no idea what am I going to do… I thought about it a bit, tossed around some ideas, but I was blocked.

Then a friend at work gave me a great idea: Why not dress up as H.A.L. 9000? I’ve used H.A.L. character to brand our Continuous Deployment efforts (especially in the launch day we had for the process a few months back), so this sounded like a awesome.

H.A.L 9000

I had two ways to go: the easy way, and the cool way.

The easy way was to print H.A.L. on a t-shirt – cool but mundane. Why not create a working version – with the halo and all??!!

So, I started to collect the parts I needed:

For the halo: Netduino and a very bright red LED (“Wait!”, you might think, “Why not simply use a blinking light from Christmas decorations, or something from a kid’s toy? Well, I wanted the halo to be random and soft, and I couldn’t find one that matches my needs… And again, much cooler doing it with Netduino), some long copper wires to connect it all, a 9V battery and a power connector for Netduino which a friend patched up.

I’ve used Netduino Plus 2 that I had for some time now. The challenge here was to create the halo so the light will be smoothly dimmed – in just the right way. For that I couldn’t just use a simple digital port, since it will create only an on-off effect. I consulted a friend which suggested using PWM, which is available as part of the Netduino framework (not the .Net micro framework). In essence, what it does is to blink the LED for short interval to create a virtual change in the light’s strength. playing with the interval with a sin function creates the diming effect I wanted:

var led = new PWMPWMChannels.PWM_ONBOARD_LED, /*Frequency*/ 1000, /* Duty cycle - aka interval */ .5, false);  
led.Start();

while(true)  
{
    /* One on-off cycle */
    for (var startValue = /* Low end of the sin wave */ 5.212; startValue < 10.495; startValue = startValue + 0.1)
    {
        var ledIntensity = Math.Sin(startValue) * .5 + .5;
        led.DutyCycle = ledIntensity;
    }
}

To add the randomness I added Thread.Sleep at the top of the sin and in the beginning of a cycle:

const double initialIntensity = 5.212;  
const double topIntesity = 7.8;  
const double finalIntensity = 10.495;

var led = new PWM(channel, 1000, .5, false);  
led.Start();

while (true)  
{
    Thread.Sleep(RandomSleepTime(MaxOffTime));

    for (var startValue = initialIntensity; startValue < finalIntensity; startValue = startValue + 0.1)
    {
        var ledIntensity = Math.Sin(startValue) * .5 + .5;
        led.DutyCycle = ledIntensity;

        Thread.Sleep(FadeInterval);

        // While Sin is in max value, so is the led intensity. So, to create the random pulsing affect, we need to pause.
        if (startValue > topIntesity - 0.09 && startValue < topIntesity + 0.09)
            Thread.Sleep(RandomSleepTime(MaxOnTime));
    }
}

The entire code needed for this available at https://github.com/ysa23/Netduino-HAL

For the actual construct, I used a piece of cardboard to hold the LED and wiring. To create the halo effect to spread evenly, I created a cone from a piece of black paper, cut a hole in the middle (for the LED) and covered it with a printed picture of H.A.L. All of this will be based on a lid from a coffee cup, which I’ve cut to let the wires through:

The hardest part in all this was to find the transparent dome to create the final touch. For this I have to thank my wife who found a top from a milkshake cup.

The frame is constructed from a piece of flexible cardboard I colored in silver, shaped it as a cone, and cut a hole to fit the construct in.

After a couple of hours of glue (three types of glue!!!), I came up with this:

All of this was sewed on a black t-shirt I bought, by my wife (at 1AM). The wires were also sewed from within the shirt running to the waist. The wires were connected to the Netduino which I put in a small pack attached to my belt. The end result was:

After it was all done, we went to sleep happy and excited about the accomplishment. At 10:00AM we woke up – late as hell to the party…

I can’t wait for next year… Do you have any ideas?

Yossi Shmueli

Technologist, enjoy solving technical challenges for real world applications. Keeping it Green since 1995

comments powered by Disqus