h1

Cloak v2.2

12 November, 2013

The Colour Stealing Cloak got some good reactions, but I wasn’t entirely happy with the version I took to Burning Man. With a Burner party coming up, I wanted to fix some annoying problems:

  • The solid colour showed up the strings of LEDs too clearly.
  • There was an ugly pause while the colour was detected.
  • The buttons weren’t working properly.*
  • The colour sense action was too slow.

I started by repairing the buttons, but in the process I blew up** my last Arduino Nano, so I had to repair that first.

... if you don't look too closely.

Good as new.

With the buttons working, I then moved the various functions into interrupt service routines. ISRs, when they are working, are beautiful things that give me the warm fuzzies; no polling for events, just set up what you want to happen and let the hardware take care of it.

  • Interrupt 0: when the ‘sense’ button is pressed, command the sensor to detect a colour.
  • Interrupt 1: when the ‘mode’ button is pressed, change the twinkle colour back to white.
  • Timer 1: set a flag to indicate that the twinkle animation needs updating.
  • Main loop***: if there’s any serial data available, interpret it and change the twinkle colour. If the twinkle flag is set, update the animation.
The box of laminating pouches makes a useful palette for testing the sensor.

Testing.

Much better: now the cloak twinkles continuously and the colour sensing is fast and reliable****. I also added a couple of rainbow modes, inspired by the guy who brought one of his interactive LED costumes***** to TOG’s last Coder Night, and improved the colour wipe when a colour is sensed. And with that******, Cloak v2.2 is ready to go:


* Due to an extra connection inside the button board, I could detect when a button was pressed but not which one. Thus Cloak v2.0 was controlled by long and short presses, which contributed to the slowness of the colour sense action. This is what you get if you build your hardware in Dublin and don’t actually test it until you get to Reno.

** Failed to spot the bridged tracks on the stripboard. Result: everything worked perfectly until I pressed the button and blew up the board. A Button Of Doom is upsetting, but not as bad as these Suicide Machines.

*** Originally the main loop was empty and everything was in ISRs and it was lovely. Except that that didn’t work, because the processor spent so long updating the twinkle animation that the serial timing was affected and the colour data was corrupted. This is because ISRs, by default, are not themselves interruptable. You can make them interruptable… or you can keep things simple.

**** Except for yellow. Don’t ask.

***** See, all the cool kids are doing it.

****** Well, that and an interesting bug caused by button bouncing and the external interrupt flag register, and hitting a memory limitation in a way that exactly mimicked a catastrophic hardware failure, and some rather pretty memory overrun problems that inspired me to add a bit of randomness to the solid colours. Good times.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: