Controlling WS2812 LEDs

I thought this might come in use for people wanting to simply control a strip of WS2811/2812/2812B LEDS. This is not all-singing – you can control individual LEDS but the fancy stuff you’ll find elsewhere.  In my case I wanted to smoothly update a whole array of these things in a home control board using the minimum of room and having to do the least setup or re-programming.

I’ve been using the ADAFRUIT library for some time – that is all singing – but.. it also has bugs. I found when adjusting colour and brilliance of strips of LEDS at the same time there were inconsistencies – also the library was using up a lot of space I could not afford. So I went off looking.

I stumbled across THIS library.

https://github.com/cpldcpu/light_ws2812

You’ll find if your needs are simple this does a lot of what you want – basically you define an array of LEDS – set the colour for each one – or the lot in a loop – and call the update routine – no setup for different types – it just WORKS and works quickly and takes up very little room.

But it was a TAD too basic. So I added some stuff. I wanted to be able to dynamically adjust the number of LEDS without reprogramming the chip. On inspection the room for each led (3 bytes per LED in RAM)  is MALLOCed… so a simple addition to the library…

Add this to the public definitions in the header

image

and some code into the main SW2812.cpp file..

tmp7B7F

And that’s it – so now you can change clear an array of LEDS to off – OR specify an RGB colour for the lot.

All of that was fine – all I needed now was a routine that could be called in the background…..

I have a byte variable which contains the brilliance of the strip – and another which contains a colour from a FLASH-based lookup table…

For historical reasons these bytes are called neocol and neobright.

Here’s the lookup table – you don’t need it of course but I was short of room.

tmpD7A4

 

And here is a routine you might call – every few milliseconds – to arrange smooth change of colour and brilliance to your array as you set those two values…

tmp1C33

I hope that proves useful to you – compared to similar code using Adafruit I gained over 1k of code space back and it does a smoother job.

Advertisements

100,000 Hours Bollocks

As someone who’s used LEDs both professionally and for my hobby since, oh, the 80s, I’ve always had my suspicions about WHITE LEDs.

As you may know, WHITE LEDs differ from the rest in that there is no such thing as white – it’s a combination of wavelengths, unlike blue or green or red… so in order to make white LEDs you can either:

1. Put a phosphor on a blue/UV led

or

2. Make a die with red, green and blue close together on the same chip and run them together with the right proportions

Mostly we chose (1) and for some time now manufacturers have been belting out WHITE LEDs en-masse without regard to lifespan – merely quoting the ideal-case figure of 100,000 hours in most cases.

But a trip to MAPLIN or any lighting store (B&Q) where demo white LED spotlights are running will reveal – duff or dim LEDS.. why is that?

Well, it seems that coloured LEDs, as long as they don’t overheat really CAN manage obscene lifetimes – but the whites? That’s nowhere near as clear.  My gut feelings tell me they don’t last anywhere NEAR as long – but that’s all it’s it – or was – take a look at this link and read for yourself – this kind fellow has taken the time to do a little research of his own.

http://www.nickhill.co.uk/white_LED_life_expectancy.html

What’s the answer? Well my answer – I plan to use the new RGB LED strip (WAY more expensive than the one-colour-per-LED stuff) with 3 colours in one chip – as much as possible.. and the added advantage…   you can chose what white temperature you want – think there’s only one WHITE? Think again.  Warm white, Cool white, Cold white – it’s all down to the mix of colours and with modern LED strip you can have any mix you like – without using phosphors!!