That’s a pretty cool project, my LED dagger build runs LEDS via PWM or GPIO in response to IMU input.
you can define KRGBWYCM pretty easy with #defines here’s psuedo code for a non-blocking ws2812 animation system to do a strobe.
//start of pseudo code.
struct color = {unit8 G,unit8 R,unit8 B};
#define K = {0,0,0} //Black
#define W = {255,255,255} //Black
func def:
rgbled_drawpixel{pixel_index, color}
rgbled_drawpixel{pixel index, K}; // set pixel at pixel index to black (off)
main loop:
Main,
{
//init section
init imu,
init buffer for rgbleds
bool strobestate;
timer_strobedelay = 50ms
int mode; //0 = off, 1 == strobe, 2 == not impliemented.
main loop starts:
//Read IMU to buffer for later here, scale the imu value for Z height to 0-255, //then add a case that updates the led based on that input each time the timer //calls the animation system.
//for bonus points, run this on core 2 of a dual core system, and manage it //from core 1 using IPC.
on timer tick, we call
animation(
Select
case 0
for i = 0 to number of leds
}
rgbled_drawpixel(i,k);// set all leds to black (off)
}
break;
case 1 //strobing at 50ms timer rate.
strobestate = !strobestate; (flip strobe state each time this is called by timer)
if strobestate == 1 then
color = K;
else
color = W;
for i = 0 to number of leds
}
rgbled_drawpixel(i,color);//
}
break;
)end of animation loop
end of main
)