Pull request submitted
Once this is approved, here’s a nice way to toggle the connect on and off:
#include "application.h"
bool ModeBtnPressed();
bool WE_SO_CONNECTED = false;
bool MODE_PRESSED = false;
void setup() {
Spark.disconnect(); // Disconnect from the Cloud on startup
}
void loop() {
if(ModeBtnPressed()) {
if(WE_SO_CONNECTED == false) {
RGB.control(true);
for(uint8_t x=0; x<2; x++) { // Ready the Hyperdrive!
RGB.color(255,0,0); //red
delay(50);
RGB.color(255,100,0); //orange
delay(50);
RGB.color(255,255,0); //yellow
delay(50);
RGB.color(0,255,0); //green
delay(50);
RGB.color(0,255,255); //cyan
delay(50);
RGB.color(0,0,255); //blue
delay(50);
RGB.color(255,0,255); //magenta
delay(50);
RGB.color(255,255,255); //white
delay(50);
}
RGB.control(false);
Spark.connect(); // Engage Hyperdrive!
WE_SO_CONNECTED = true;
}
else {
Spark.disconnect(); // Power down the Hyperdrive...
WE_SO_CONNECTED = false;
}
}
}
bool ModeBtnPressed() {
if(BUTTON_GetDebouncedTime(BUTTON1) > 100) {
// Detect mode pressed only once
if(!MODE_PRESSED) {
MODE_PRESSED = true;
return 1;
}
// wait until button is released before indicating it's pressed again
return 0;
}
else {
MODE_PRESSED = false;
return 0;
}
}