add circle spin fadeout whatever program

This commit is contained in:
true
2025-04-04 00:35:34 -07:00
parent 9413b9997a
commit e614e47d4a
4 changed files with 77 additions and 19 deletions

View File

@@ -9,15 +9,18 @@ tinyNeoPixel rgb = tinyNeoPixel(RGB_COUNT, PIN_PA1, NEO_GRB, rgbled);
// rgb program prototypes
uint8_t rgbp_rainbow(uint8_t init);
uint8_t rgbp_circlefade(uint8_t init);
uint8_t (*rgb_program[1])(uint8_t) = {
rgbp_rainbow
// rgb program function pointer array
uint8_t (*rgb_program[PROG_COUNT])(uint8_t) = {
rgbp_rainbow,
rgbp_circlefade
};
#define RGB_COUNT 5
uint8_t rgbled[3 * RGB_COUNT];
@@ -40,6 +43,8 @@ void conf_rgb_timer()
// globals for all rgb programs
uint16_t prog_timeout;
uint16_t hue;
uint8_t r, g, b;
// rgb program 0: rainbow puke
@@ -53,9 +58,7 @@ uint16_t rainbow_hue = 0;
uint8_t rgbp_rainbow(uint8_t init)
{
uint8_t i;
uint8_t r, g, b;
uint16_t hue;
uint8_t i;
// set our timer when initializing. otherwise every call is identical
if (init) {
@@ -89,4 +92,49 @@ uint8_t rgbp_rainbow(uint8_t init)
// done with program
return 0;
}
}
// rgb program 2: circle loops with fading
#define CF_TIMEOUT 90 // how long to show this program (max 255, ideally (20*loopcount)+10)
#define CF_BRIGHTNESS 64 // how bright to make the LED. don't make too bright or badge will brown out
#define CF_FADERATE 12 // how much to fade all LEDs each frame
uint8_t circlefade_idx = 0;
uint8_t rgbp_circlefade(uint8_t init)
{
uint8_t i;
uint8_t t;
// set our timer when initializing. otherwise every call is identical
if (init) {
prog_timeout = CF_TIMEOUT;
circlefade_idx = 0;
}
if (--prog_timeout) {
t = (uint8_t)(CF_TIMEOUT - prog_timeout); // get time elapsed
t &= 0x3; // light a new LED every 4th loop
// fade each LED down every cycle
for (i = 0; i < (sizeof(rgbled) / sizeof(rgbled[0])); i++) {
if (rgbled[i] >= CF_FADERATE) {
rgbled[i] -= CF_FADERATE;
} else {
rgbled[i] = 0;
}
}
// set the next LED in sequence on to full brightness every 4 cycles
if (prog_timeout >= 10) { // as long as >10 loops remain,
if (!t) { // then on a loop boundary, light the next LED
rgb.setPixelColor(circlefade_idx, CF_BRIGHTNESS, CF_BRIGHTNESS, CF_BRIGHTNESS);
if (++circlefade_idx > RGB_COUNT) { // then work on the next LED in sequence
circlefade_idx = 0;
}
}
}
}
}