Modding a silicone cat lamp to have a nicer rainbow fade.
First I wrote some simple C programs that made sure that all the connections to the LEDs worked and a little program that displayed one color when the sensor value is low and another when it is high. I already put parts of different concern in separate C files for later inconvenience.
I wanted to keep the functionality that the beating of the cat changed the mode. This results in a very simple state machine with the sensor ping going low and high again as the only type of transition. That I made into an enum variable which is incremented in a interrupt service function.
The problem in the first place was that there was the need for smooth color transitions. to accomplish that I went for an implementation of a sinusoidal HSB fade.
To accomplish that on an Attiny in a fast and efficient manner I chose to use a lookup table which generated on python. Because right now I went with only doing 8 bit software PWM I chose an amplitude of 255.
from math import cos, pi LUT_LEN = 512 LUT_AMP = 2**8-1 lut = [int(cos(i*pi/2/LUT_LEN)*LUT_AMP) for i in range(0,LUT_LEN)] print(lut)
The printout can be copy pasted into C code.
The result right now looks like this. The striped one can only see on camera of course due to aliasing.
The original controller get's the charge status (charging or not charging) via a pin and accordingly makes an LED blink. The substitution for that is a wire bridging the ingoing and outgoing ping, resulting in the charge status LED glowing when the cat charges.
Because the original controller has no IC markings and I couldn't determine the type, I decided to desolder it and replace it with an Attiny85. I soldered the DIP-8 version of this controller onto a double sided prototyping board and filled and wired the holes in the middle in a way that I can program it with the use of pogo pins. Then I hot glued it onto a place on the PCB where the LEDs wouldn't cast a shadow.
The last step was to wire the power traces to the power pins, the RGBW traces to PB0..3 and the sensor trace to PB4.
The cat is a LED lamp with a lithium battery cell that is to be charged via a micro USB port. With the push of a button next to micro USB port the cat can be turned on and off.
By beating the body or the base of the cat, the mode is changed. The Modes are "warm white light on", "RGB color steps" and "LEDs off". The color steps are very annoying and the goal of this project was to replace this with pleasant color fading.
On the base of the lamp is the main PCB which is single sided and holds basic components for battery charging and protection, the main IC which does all the smarts, some analog circuitry for the "beating sensor", transistors and resistors for the LEDs, and the LEDs themselves - four warm white ones and four RGB ones. Each color is connected in parallel.
The beating sensor is a piezo element which is held in the middle of the base.
Under the main PCB is the battery and an interfacing PCB which is connected via a 4 leads cable and holds the USB port, a switch and a LED which blinks when charged.
The main IC does everything. It has contacts going in for the power, the charge status and the sensor and going out for the four colors and the charging status LED. Some pins are not used. Here you can see the footprint after removal and cleanup.
In the picture the upper left pin is pin 1.
|2||Charge Status IN||NC||13|
|3||Piezo IN||Charge Status LED OUT||12|
|5||Warm White OUT||Blue OUT||10|
|6||Button IN||Red OUT||9|