# Photon Mode Button - User Access

**URL:** <https://community.particle.io/t/photon-mode-button-user-access/13471>\
**Category:** Firmware\
**Created:** [July 19, 2015, 12:26pm UTC](https://community.particle.io/t/photon-mode-button-user-access/13471 "2015-07-19T12:26:07Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![BDub](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/bdub/32/5137_2.png) [@BDub](https://community.particle.io/u/BDub)\
**Post date:** [August 11, 2015, 4:12am UTC](https://community.particle.io/t/photon-mode-button-user-access/13471/4 "2015-08-11T04:12:50Z")

</div>

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

```auto
// 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.

---

_[View the full topic](https://community.particle.io/t/photon-mode-button-user-access/13471)._
