Photon Mode Button - User Access

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