Closed BAmercury closed 3 years ago
I have it set so the user can strike the lamp to ch ange through the animations (aside from the default fire animation - which can be toggled using a switch at the bottom of the lamp. It might be smarter to be able to cycle through all animations through striking so I might change it to that. But first I need to change all the code to stop using the delay() blocking function to setting the timer values using millis()
Referencing this code to update the Adafruit animations: https://github.com/ndsh/neopixel-without-delay
Now you can cycle throw all animations by striking the lamp, removed the whole toggle switch thing. Convereted the animations to use millis instead of delay - but the fire animation will need to be re-written to work like this
Fire animation is rewritten to work with the millis(), but the issue is the update rate. It's animating too fast so need to tune an appropriate time interval to make it look realistic and smooth
lol I'm dumb - found the issue:
// Read animation files from Colors.h and convert to RGB. Output to Neopixel strip
void animate_led()
{
uint8_t h, s, l;
hsl_values hsl;
for (int i = 0; i < sizeof(colors) / 3; ++i)
{
//Read the the next color from progmem
h = pgm_read_byte_near(colors + (i * 3));
s = pgm_read_byte_near(colors + (i * 3) + 1);
l = pgm_read_byte_near(colors + (i * 3) + 2);
hsl.h = (float)h / 255;
hsl.s = (float)s / 255;
hsl.l = (float)l / 255;
rgb_values rgb;
rgb = hsl2RGB(hsl);
for (int j = 0; j <= NUM_LED; j++)
{
strip.setPixelColor(j, rgb.red, rgb.blue, rgb.green);
}
strip.show();
// Updates every 33 ms (Can use this to control framerate of animation)
//delay(33);
}
}
The for loop is an issue, need to rewrite this function to support millis()
was able to fix the issue by removing the for loop and writing 2 new functions. one iterates through the colors array and one keeps track of the index and updates the LEDs. seems to be working now. may need to edit the time period value later but seems to be okay for now
add either a toggle button or a three way switch to button of lamp so I can change between the types of animations