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.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.