A few months ago I created a Jam Jar light with a programmable weatherproof RGB NeoPixel strip from Adafruit. It’s a simple, fun, interactive gadget for short camping trips that helps me see at night. Using a bit of code that I placed on a Flora micro controller, and an accelerometer and a compass, the jam jar’s orientation relative to the local magnetic field determined its colour, and giving the jar a good shake turns the lights on and off.
When I took the little gadget camping with me back in February, I decided it needed a few modifications, which I just got around to finishing last weekend.
- Rather than having the colour of the lights fixed when the jar is stationary, the colours now very slowly cycle through red, green, and blue. I find that the jar is more relaxing when the colours are slowly changing.
- It was hard to adjust the brightness of the lights on the campsite without getting into the code, so now they’re adjusted by turning the jar: the local magnetic field changes the brightness according to the function B = (tan-1(Mx/My)/π + 1)/2, where Mx and My are components of the local magnetic field. The number B ranges from 0 to 1: when B is close to zero, the lights are off, and when B is close to 1, the lights are at their maximum brightness.
- The acceleration threshold was a bit too low: whenever the picnic bench jiggled, the light would turn off/on. So I doubled the threshold that determines whether the lights turn off/on.