Skip to content

Instantly share code, notes, and snippets.

@fvdbosch
Last active January 2, 2016 15:36
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 fvdbosch/c6e4648c0b9299a11dc8 to your computer and use it in GitHub Desktop.
Save fvdbosch/c6e4648c0b9299a11dc8 to your computer and use it in GitHub Desktop.
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