In implementing my own home control solution which you’ll find in this blog “home control 2015” the software has been and remains a work in progress – mainly because I keep finding bugs and adding new features. I’m fairly confident that most of the bugs that have plagued me over the months are gone. For example NONE of my boards has failed in the last week – running constantly, turning things on and off, monitoring temperature and humidity, powering RGB LEDS…
And that brings me onto tonight’s subject. You may have noticed elsewhere that I’m getting fanatical about the Nextion displays because now at last I have the potential of a nice touch display for the wall to control things. You’ll also notice I’m realising their code is VERY early – but that’s another subject.
The first addition I made today to the home control system was to allow any of the ESP boards to send an MQTT message to any other board. Of course that is built into the MQTT library in the first place and there would not be a lot of use in having the Raspberry Pi brains send a message to one board to send a message to another.. but it occurred to me that an essential feature of a serial wall mounted display would be to control more than just the ESP8266 board that it is actually attached to!
So – in went a new command to send out an MQTT command from the serial input on the board so that the ESP board could pass the message on. That’s a little tougher than it sounds as I only had one string argument available in my line parser so I had to delve into that – however, it is now all done.
And that led me to thinking about how my wife Maureen would control the coloured lighting around the house, from the wall.
Obvious really, RGB sliders – you can make any colour or hue from RGB can’t you – any techy will tell you that for free. Sadly the rest of the world does NOT know how to manipulate RGB. Any paper artist will tell you that the primary colours are red, yellow and blue! Not in my world they are not.
And so we have a problem – how to better enable any old user to play with colours – and hence I started reading and it is pretty clear that a better model is HSV, or hue, saturation and value – brilliance in other words – I looked up HSV on Google but the best I could find was Herpes Simples Virus. I’m going to continue to refer to brilliance as the word “value” means nothing to me in this context. The problem with RGB is – let’s say you get a really nice pink. That’s fine at full brilliance but how would you keep that shade of pink as you turn down the brilliance… even for a techy that is not easy faced with 3 sliders. With HSV it’s a snap.
And so I’ve been looking at code – I found some great Javascript code and in fact I now have that running on my little WEBSOCKETS project – but what about C to put into the home control project… I found this after much searching. http://www.ruinelli.ch/rgb-to-hsv Excellent code and simple to implement – do I put that into the ESP C compiler? NOPE – it needed a couple of includes that screwed everything else up because of the FLOOR function… so then I found this…
int inline fasterfloor( const float x ) { return x < 0 ? (int) x == x ? (int) x : (int) x -1 : (int) x; }
That solved the floor function and I was up and running. H values 0-359, saturation 0-255 and brilliance 0-255.
Thinking about a display, a simple colour wheel with touch points along the way, then 2 sliders… that’s it – full intuitive colour touch control.
Well, it was enlightening for me – I hope you found this useful.
Looks like you want HSB, not HSV…:-)