I am trying to view the status LED on the exterior of an enclosed case with sensors externally connected. I lifted this partially from someone’s project here, and docs.
I have a rather large project going and this is the OnChange(handler) Neopixel pertinent code, everything compiles and works except this only follows the on status change flashing green to cyan, then stays static. I am assuming there is a better way to mirror system to neopixels.
#define PIXEL_PIN D6
#define PIXEL_COUNT 1
#define PIXEL_TYPE WS2812B
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
void ledChangeHandler(uint8_t r, uint8_t g, uint8_t b) {
// Initial boot, control all teh LEDs
if(!Particle.connected() && !has_booted) {
for(uint8_t i=0; i<PIXEL_COUNT; i++)
strip.setPixelColor(i, strip.Color(r, g, b));
strip.show();
}
}
void setup(){
strip.begin(); // initialize the strip
strip.show(); // initialize all pixels to 'off'
RGB.onChange(ledChangeHandler);
WiFiSetup();
Particle.connect();
while(!Particle.connected()) {
Particle.process();
delay(1);
}
So I tried that, and @ScruffR 's suggestion. First of which, the bool has_booted = false; is a global, then I call has_booted = true; at the end of setup I don’t see why that would be an issue, its just confirming it’s made it through setup without errors on any other sensors.
The best I can get it to do is follow the rapid boot flash from green to cyan, then it stays static.
Once you are connected to the cloud !Particle.connected() will become false and hence the if() condition will never ever become true again and never ever update the strip again - no matter what has_booted will be.
Because you only update the strip when both conditions (Particle.connected()andhas_booted) are false. As soon one becomes true you stop updating the strip!