spark/core-firmware — pull request #135 by technobly (2014-02-28 16:02:10+00:00)
Title: Mode button debounce time reset automatically

This change cleans up some code, and makes it easier to use the Mode button in user code. Sample application:

```cpp
#include "application.h"
bool ModeBtnPressed();

void setup() {
Spark.disconnect(); // Disconnect from the Cloud on startup
}

void loop() {
if(ModeBtnPressed()) {
RGB.control(true);
for(uint8_t x=0; x<2; x++) { // Ready the Hyperdrive!
RGB.color(255,0,0); //red
delay(100);
RGB.color(255,100,0); //orange
delay(100);
RGB.color(255,255,0); //yellow
delay(100);
RGB.color(0,255,0); //green
delay(100);
RGB.color(0,255,255); //cyan
delay(100);
RGB.color(0,0,255); //blue
delay(100);
RGB.color(255,0,255); //magenta
delay(100);
RGB.color(255,255,255); //white
delay(100);
}
RGB.control(false);
Spark.connect(); // Engage Hyperdrive!
}
}

bool ModeBtnPressed() {
if(BUTTON_GetDebouncedTime(BUTTON1) > 100) {
return 1;
}
return 0;
}
```

Before this, we had to use code like this to protect against blocking the Smart Config:

```cpp
#include "application.h"
bool ModeBtnPressed();
uint32_t startTime = 0;

void setup() {
startTime = millis(); // capture the time that our app starts
Spark.disconnect();
}

void loop() {
if(ModeBtnPressed()) {
RGB.control(true);
for(uint8_t x=0; x<2; x++) { // Ready the Hyperdrive!
RGB.color(255,0,0); //red
delay(100);
RGB.color(255,100,0); //orange
delay(100);
RGB.color(255,255,0); //yellow
delay(100);
RGB.color(0,255,0); //green
delay(100);
RGB.color(0,255,255); //cyan
delay(100);
RGB.color(0,0,255); //blue
delay(100);
RGB.color(255,0,255); //magenta
delay(100);
RGB.color(255,255,255); //white
delay(100);
}
RGB.control(false);
Spark.connect(); // Engage Hyperdrive!
}
}

bool ModeBtnPressed() {
if(millis() - startTime > 10000) { // wait at least 10s for smart config hooks
if(BUTTON_GetDebouncedTime(BUTTON1) > 100) {
BUTTON_ResetDebouncedState(BUTTON1);
return 1;
}
}
return 0;
}
```