LEDStatus setPattern not working

I am attempting to use LEDStatus.setPattern to blink the RGB LED on a certain state. But it does not blink (stays solid red). It also stays solid during my relay trigger function. The LED does go blue but doesn’t blink. Is there some special consideration I need to take?

Code running on the Photon and RelayShield: https://gist.github.com/andyshinn/94b0e606f21b5841fde578160a88b048

Can you try also setting the blink speed with enabling the red blink pattern?

That did not work. However, if I remove the setSpeed (keeping only the one in setup()) and then initialize with LEDStatus statusLED(LED_PATTERN_BLINK); it does work properly (blinking on error or when triggering relay but solid color on other states).

The behavior seems strange. Is this a possible bug?

When I try your code with some slight alterations (to circumvent the need for the external contacts) it works as expected

https://go.particle.io/shared_apps/5f2079c6e83d020016459612

You can use the Particle.function("setState", setStateFn) to test the patterns.

BTW, there are better ways to do the state check in loop().
You’d read the state of your pins only once per iteration and then use if() ... else if() ... or a switch() block or even better a numeric correlation to prevent confusion with the combinations.

e.g.

enum DoorState : int 
{ DOOR_ERROR   = 0b00
, DOOR_CLOSED  = 0b01
, DOOR_OPEN    = 0b10
, DOOR_UNKNOWN = 0b11
};

void loop() {
  buttonOpenState = digitalRead(buttonOpen);
  if (buttonOpenState) {
    Particle.publish("triggerFrom", "buttonOpen", PRIVATE);
    triggerRelay(doorRelay);
    delay(1000); // lazy way to prevent hitting the publishing rate limit 
  }

  static int prevState = DOOR_UNKNOWN;
  int state = digitalRead(switchUpper) << 1 
            + digitalRead(switchLower) << 0;

  if (state != prevState) {
    setState((DoorState)state);
    prevState = state;
  }
}

This requires rearranging your state enum but makes for cleaner code :wink:

I think this is the reason why you are no seeing the blinking as you keep restarting the blinking faster than the blink pattern is.
Hence you should only act on a change of state (as in my code above).

You should also consider debouncing your digital inputs.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.