Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
const int ldr = A0;
int lightlevel = 0;
String charged = "init";
int threshold = 750;
void setup() {
pinMode(ldr, INPUT);
delay(5000);
}
void loop() {
lightlevel = analogRead(ldr);
if(lightlevel < threshold && charged != "true") {
Spark.publish("status", "charged (" + String(lightlevel) + ")");
charged = "true";
}
else if(lightlevel > threshold && charged != "false") {
Spark.publish("status", "charging (" + String(lightlevel) + ")");
charged = "false";
}
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment