Ok, this is fun… will disconnect you from the Cloud on start up, and then if you need to reflash your code just press the Mode button to reconnect to the Cloud first. It also ignores the Mode button for the first 3 seconds after start up, so you have enough time to get your Core into Smart Config if you need it.
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 > 3000) { // wait at least 3s for smart config
if(BUTTON_GetDebouncedTime(BUTTON1) >= 100) {
BUTTON_ResetDebouncedState(BUTTON1);
return 1;
}
}
return 0;
}