# LedStrip Shader Language

The intent of this project is to allow you to program effects for your LED strips
in a dynamic way. Generally used LED-strip firmware has the downside that if you want
to define a (dynamic) effect, you need to open the source code, add the effect to 
the firmware, recompile and flash the microcntroller with new firmware. This project,
on the other hand, allows you to write effects like that 'live' in a webpage where
you can see the changes immediately.

This project came into being because I have several LED-strips and spotlight strings
using WS2812-like LEDs around my home. Some of those need very specific lighting 
scenarios (e.g. make the lights for the plants green but color-cycle the rest) and I 
didn't want to integrate these effects in the (universal) firmware.

This project is inspired by OpenGL shaders, which are small programs that assign a color
value to each pixel in a rendered triangle; the 'shader language' in the name stems
from that. It's also inspired by <a href="https://electromage.com/pixelblaze">Pixelblaze</a>,
a commercial product that uses a Javascript dialect to implement the same idea. (If
you don't want to mess around with firmware, I suggest you buy their modules; they
seem like a great off-the-shelf solution.) The downside of Pixelblaze is that the software
is not open-source, though, and I needed the capability to add e.g. my own output routines
and my own control protocols.

LedStrip Shader Language (LSSL) itself is a language that derives bits from C and 
Javascript. It compiles into a binary that can be executed on a small virtual machine
which is called to calculate the LED values.

## Example

```C
function set_led(pos, time) {
	var a=pos*0.01+time*0.1;
	var r=sin(a)*127+128;
	var g=sin(a+2.1)*127+128;
	var b=sin(a+4.2)*127+128;
	led_set_rgb(r, g, b);
}

function main() {
	set_led(0, 0);
	set_led(0, 0);
	set_led(0, 0);
	set_led(0, 0);
	register_led_cb(set_led);
	return 42;
}


```