Christmas RGB Animation

Cloe admiring my Christmas lights

My ESP8266 home control code contains not only RGB code for serial LEDs but also a complete programming setup to generate and loop sequences… and so with merely one wire and VERY  little work, we end up with some fancy animation.

Here we see an old, gutted plastic Christmas window decoration which WAS filled with old fashioned white lights but now has a string of 69 serial LEDs running animation around the inside.

I made one of these last year but when it came to trying out my animated LED Christmas lighting this year – nothing happened – dead. After wasting hours I remembered I’d changed the code earlier this year so for anyone using my ESP8266 software and wanting to knock up a quick Christmas animation – here it is…

My code lets you refer to a string of RGB lights - up to 300 of them and do things like -  make the first 10 LEDs RED and pause for a second, then make the second 20 LEDs GREEN and wait for 5 seconds, clear the lot wait 1 second. 

LED AnimationThat will then continue to do that forever in a loop – and that’s just a trivial example – here I set up a nice colourful display (the actual unit is white – no colour at all – the cat has nothing to do with anything.

This is now INCOMPATIBLE with earlier code so if you have something already running from last Christmas, you’ll need to add a new first parameter (1) to keep compatibility.

Here is how to make a Christmas light as above with yellow-white flashing tips…

if (msg.payload=="reset") context.global.stepper=0;

var steps=[
"{rgbstop}",
"{rgbstart:12,94}",
"{rgbadd:1,8,22,255,0,0,5}",
"{rgbadd:1,36,24,255,0,0,5}",
"{rgbadd:1,66,20,255,0,0,5}",
"{rgbadd:1,0,8,0,255,0,5}",
"{rgbadd:1,86,8,0,255,0,5}",
"{rgbadd:1,60,6,255,255,0,5}",
"{rgbadd:1,30,6,255,255,255,200}",
"{rgbadd:1,60,6,255,255,80,5}",
"{rgbadd:1,30,6,255,255,150,200}",
"{rgbadd:1,60,6,255,255,150,5}",
"{rgbadd:1,30,6,255,255,80,200}",
"{rgbadd:1,60,6,255,255,255,5}",
"{rgbadd:1,30,6,255,255,0,200}",

"{rgbadd:1,60,6,255,255,0,5}",
"{rgbadd:1,30,6,255,255,255,200}",
"{rgbadd:1,60,6,255,200,40,5}",
"{rgbadd:1,30,6,255,255,150,200}",
"{rgbadd:1,60,6,255,255,80,5}",
"{rgbadd:1,30,6,255,255,120,200}",
"{rgbadd:1,60,6,255,255,200,5}",
"{rgbadd:1,30,6,255,255,30,200}",

"{rgbadd:1,60,6,255,255,0,5}",
"{rgbadd:1,30,6,255,255,00,200}",
"{rgbadd:1,60,6,255,200,80,5}",
"{rgbadd:1,30,6,255,255,130,200}",
"{rgbadd:1,60,6,200,200,150,5}",
"{rgbadd:1,30,6,255,180,80,200}",
"{rgbadd:1,60,6,255,255,200,5}",
"{rgbadd:1,30,6,255,255,0,200}" ];

msg.topic="xmas/toesp";
msg.payload=steps[context.global.stepper++];
return msg;

Node-Red Flow

In the node-Red code above, I wait for the ESP to login as usual – and when it does I sent it a sequence of instructions, once, which will set up the display. Once set the code will do nothing more. Purple nodes are MQTT talking to the display unit which is called “xmas”

That function that says “Continue until end of array is merely this..

if (msg.payload!==undefined) return msg;

I’ve also included an “inject” mode for manual testing. It merely sends out text with the word “reset” in the payload.

Looking at the list above, the first command stops anything already running. The second sets up 96 LEDs on GPIO12 (count is the second parameter).

An example of a simple light up is the third instruction – code 1, from LED 9, light  up 4 LEDs in RED (255,0,0) for 5ms.

The other instructions are the same, lighting up segments of the display for X amount of time, I do the tips of the candles in white, wait a while then change them to yellow – the rest of the display is static – of course one could be a HELL of a lot cleverer than that. This is documented in the WORD document for the ESP8266 code.

There is also a command 4 which means END – you’d only use that if you wanted to perform a series of loops and then stop permanently. That has no parameters.

Assuming you’ve used the latter and have a sequence which does whatever and then stops – it might be nice to store this in FLASH and recall it when needed. There are four non-volatile buffers available to store this information.

{rgbstore:X} where X is 0-3

You can play back any of these as below, again assuming in this case GPIO12 and 12 LEDs. Set X to be 0-3

{rgbrecall:X}
{rgbstart:12,12}

The above will play back a stored sequence immediately.

The code is in the usual place and available via the OTA. See Home Control blog.

As you can imagine – you could set up a LOT of this stuff as the code is only sent out once.  Limits are 1 strip of up to 300 RGB serial LEDs per ESP8266.

Facebooktwittergoogle_pluspinterestlinkedin

One thought on “Christmas RGB Animation

Leave a Reply

Your email address will not be published. Required fields are marked *