I have started using the RGB API to control the LED to prevent it from remaining lit during sleeping hours so that the pulsing LED does not bother my family. For the most part the behavior works as expected. The code I use can be found below. The problem I see is with this line: RGB.brightness(0); If I have this line in my code then the LED will not ever light again unless I power cycle the device. However if I remove this line then it works as expected. I believe that when the OS regains control of the LED it should re-set the brightness to whatever value it used before control of the LED was taken from it.
This code will first check if the device is connected to the cloud. If it is not then control of the RGB LED is granted to the OS. If the device is connected however then control of the RGB LED depends on the time of day. Specifically the hour. Within a certain hour range the LED is disabled and outside of that range the LED control is granted to the OS.
if (Particle.connected()) {
int hour = Time.hour();
// Turn off the LED from the hours of 9pm to 7am
if (!RGB.controlled() && IsInControlledTimeRange(hour)) {
// take control of the LED
RGB.control(true);
RGB.color(0,0,0);
RGB.brightness(0); // This is the line that causes the issue.
} else if (RGB.controlled() && !IsInControlledTimeRange(hour)) {
RGB.control(false);
}
} else {
// Give control back to the OS when the device is
// not connected to the cloud.
if (RGB.controlled()) {
RGB.control(false);
}
}