Photon 2 Mode Button

All of the tutorials show using System.on(button_click, handler) to get notified when the mode/setup button is pressed. I can't seem to get this to work on my Photon 2. When I press the button the light changes to show the RSSI, but no event is fired. I also logged all events to see if I had the wrong event, but none of 128, 4096, 8192 are fired. Single press, triple press (double press goes to sleep), long press, etc, nothing. Am I missing something?

#include "Particle.h"
SerialLogHandler logHandler(LOG_LEVEL_WARN);

void event_handler(system_event_t event, int param) {
  Log.warn("got event %d with value %d", (int)event, param);
}

void setup() {
  Serial.begin();
  System.on(all_events, event_handler);
}

Some events run at interrupt level and Log.info does not work from an ISR. I believe this is the case with the button handler, but I'm not 100% sure.

You could try setting a global variable flag and checking it from loop to be sure.

1 Like

Thank you for the fast response! Yes, that was the issue.