Photon Mode Button - User Access

Is it possible to access the Mode button on the Photon?

It was possible on the Core but that same code doesn't work on the Photon.

1 Like

Bump! I’m interested in accessing the mode button state as well. The old example didn’t work for me either.

I am having the same issue. Tried various ways to getting the status of the MODE / SETUP pin and none seemed to work.

Hey guys… we just abstracted the same functions with the HAL. Here’s a slightly different example, same concept though:

// SETUP BUTTON monitoring on PHOTON
// Toggle Cloud Connection ON/OFF

#include "core_hal.h"

SYSTEM_MODE(MANUAL);

void setup() {
}

void loop() {
    // Button press needs to be 1 second long
    if (HAL_Core_Mode_Button_Pressed(1000)) {
        if (!Spark.connected()) {
            WiFi.on();
            Spark.connect();
        }
        else {
            Spark.disconnect();
            WiFi.off();
        }
        // delay 2.1 more seconds before resetting debounce time
        // in case user is trying to enter Listening Mode
        delay(2100);
        HAL_Core_Mode_Button_Reset();
    }
    Spark.process();
}

Because of the way the button is debounced in the background, this is not perfect… but it works if you want to prototype with it. And you can still enter listening mode if need be.

4 Likes

Thank you sir!

Is there a way to catch this on the start of the button state transition, instead of waiting for a press and release to complete? So I could press the button and a function of mine gets called, even if I keep holding to initiate an operational state change?

by a funny coincidence, the 0.4.6 release includes events for button pressed/released and the ability to determine how long the button has been pressed.

2 Likes

Hi mdma, can you point to the documentation where I can see how to program against this event? Regards, Marcus

A starting point might be found here
https://github.com/spark/firmware/pull/611

Unfortunately these seem to be not documented yet.