Skip to content

Instantly share code, notes, and snippets.

@dmiddlecamp
Created July 11, 2014 15:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmiddlecamp/b2e39f6d48f33f39e16f to your computer and use it in GitHub Desktop.
Save dmiddlecamp/b2e39f6d48f33f39e16f to your computer and use it in GitHub Desktop.
turn a spark core cc3000 on/off every 45 seconds, give or take
#include "application.h"
#include "spark_disable_wlan.h"
#include "spark_disable_cloud.h"
int state = 0;
int awake = 0;
unsigned int lastWakeup = 0;
//wakeup once a minute
unsigned int wakeupDelay = 60 * 1000;
unsigned int timeAwake = 15 * 1000;
void setup() {
pinMode(D0, OUTPUT);
lastWakeup = millis();
}
void loop() {
unsigned int now = millis();
if ((now - lastWakeup) >= wakeupDelay) {
lastWakeup = now;
awake = 1;
WiFi.on();
Spark.connect();
}
else if (awake && ((now - lastWakeup) >= timeAwake)) {
WiFi.off();
awake = 0;
}
else if (awake && (WiFi.status() == WIFI_ON)) {
Spark.publish("awake", String(awake));
}
//toggle once a second
state = !state;
digitalWrite(D0, (state) ? HIGH : LOW);
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment