-
-
Save fvdbosch/c6e4648c0b9299a11dc8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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