LAN Protocol switching between colour and white

HI,
Having some more fun with my little light switch, I’m trying to swap between colour and whites but it doesn’t seem to take effect until the brightness is adjusted.

Does anyone know how switching between colour and white is supposed to be done?

What I’m doing at the moment is setting Saturation to 0 for white and to 100 for colour while retaining HBK.

also it seem that when I adjust the brightness sometime it flick to colour and other it flick to white (I think this is more to do with my programming or it could be me misunderstanding how to change the brightness of a colour vs. a white)

For refinance below are the function I built to try and toggle colours, cycle the colour/temperature and control the Britishness.

[code]void lifx::toggleColor()
{
HSBK _hsbk;
bool _colorMode;
for(auto &Light : Lights)
{
_hsbk = Light.getHSBK();
if(_hsbk.saturation > 0)
{
Light.setLastColorHSBK(_hsbk);
_hsbk.saturation = 0;
_colorMode = false;
} else {
Light.setLastWhiteHSBK(_hsbk);
_hsbk.saturation = 65535;
_colorMode = true;
Light.setLastColorHSBK(_hsbk);
}
Light.setColorMode(_colorMode);
Light.setColor(_hsbk);
}
}

void lifx::cycleColor(float step)
{
//Serial.printlnf(Time.timeStr() + " - Cycle Colour…");
HSBK _hsbk;
float _hue;
float _kelvin;
for(auto &Light : Lights)
{
_hsbk = Light.getHSBK();

    if(Light.getColorMode() == true)
    {
        Serial.printlnf(Time.timeStr() + " - Cycle Colour...");
       //0 - 65535 := 0 - 100%
       _hue = _hsbk.hue - (65535 * (step/100.00));
       // range limit
        if (_hue > 65535)
        {
            _hue = 0 + (_hue - 65535);
        } else if (_hue < 0) {
            _hue = 65535 + _hue;
        }
        _hsbk.hue = (uint16_t)_hue;
    } else {
        Serial.printlnf(Time.timeStr() + " - Cycle White...");
       // 2500 - 9000
       _kelvin = _hsbk.kelvin - (6500 * (step/100.00));
       // range limit
        if (_kelvin > 9000)
        {
            _kelvin = 9000;
        } else if (_kelvin < 2500) {
            _kelvin = 2500;
        }
        _hsbk.kelvin = (uint16_t)_kelvin;
    }
    Light.setColor(_hsbk); 
}

}

void lifx::dimLights(float step)
{
Serial.printlnf(Time.timeStr() + " - Dimmer…");
//65535
HSBK _hsbk;
float _brightness;
for(auto &Light : Lights)
{
_hsbk = Light.getHSBK();
//0 - 65535 := 0 - 100%
_brightness = _hsbk.brightness - (65535 * (step/100.00));
// range limit
if (_brightness > 65535)
{
_brightness = 65535;
} else if (_brightness < 0) {
_brightness = 0;
}
// send new brightness
_hsbk.brightness = (uint16_t)_brightness;
Light.setColor(_hsbk);
}
}[/code]

Got this working, coding bug :stuck_out_tongue:

But I would still like to know how others control colour.

The bulbs don’t treat whites or colors any differently. Every color is just a set of HSBK values.

To make it easier for the user in our application we present both separately, but essentially all we are doing is altering what each axis controls. In the white mode the wheel controls the kelvin value with the hue locked, and in color mode the wheel controls the hue, with the kelvin value locked. Brightness and saturation are both controlled by the intensity control in the middle.

Thanks Daniel,
I’ll give that ago just one small question, when controlling brightness and saturation is it done with a ratio i.e. 1 brightness to 2 saturation or a split i.e. ramp saturation up then brightness once saturation max’s out (or vise versa)?

Our app uses something we call intensity. Intensity goes from 0 to 100% and that’s the number we show you in the application. As intensity increases from 0% -> 50% we set the saturation between 0 -> 1, and as the intensity increases 50% -> 100% we raise the brightness. You should be able to reverse engineer this if you want specifics by controlling the bulb with the application and checking the values of each component using the API.

Let me know if you’d like further details and I’ll ask one of the app developers to give a thorough description.