Providing access to the Mode Button and RGB LED from GPIO

Regarding your External Mode button question… I think you could get it done with hacking up the internal functions… but it’s pretty easy with just some user code. I whipped this up which works well:

#include <application.h>

#define MODE_PIN D5
uint32_t lastCheck = 0;
uint32_t debounceCount = 0;

void setup() {
  pinMode(MODE_PIN,INPUT_PULLUP);
  lastCheck = millis();
}

void loop() {
  // Every 100ms, check if the External Mode Button is pressed
  if(millis()-lastCheck > 100) {
    // Reset the lastCheck time
    lastCheck = millis();

    // Debounce input for 10 seconds!!
    if(digitalRead(MODE_PIN) == LOW)
      debounceCount += 100; // add up all of these 100ms
    else
      debounceCount = 0; // if the input is ever high, reset the count
    
    // Has it been pressed for 10 seconds?
    if(debounceCount > (100*10*10)) {
      // Perform same SmartConfig code that main.cpp does
      if(!SPARK_WLAN_SLEEP)
      {
        WiFi.listen();
      }
    }
  }
}

I haven’t looked into mimicking the Core’s RGB LED, but I’m assuming you’d just need to read the states and do the same thing. A little more complicated considering the RGB led updates via an interrupt service routine… so your not going to be able to do the same thing via user code super easy. Also since the core-firmware uses PWM to control the onboard RGB, it’s not going to be easy to do from the standpoint of potentially making the core-firmware just use some of your external pins as an RGB led #2. I think a TIMER based ISR in user code that reads the onboard RGB led state variables, and controls a Neopixel might be a good approach. Still, not easy.

Hmm, maybe just add a LIGHT PIPE to the on-board RGB :smile:

1 Like