Created
January 22, 2015 01:49
-
-
Save dmiddlecamp/02f2f0c2d7c36a0ab685 to your computer and use it in GitHub Desktop.
keen laser code
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
int laser = 0; | |
unsigned int lastPublish = 0; | |
bool lastState = false; | |
void setup() { | |
pinMode(A0, INPUT_PULLDOWN); | |
pinMode(D7, OUTPUT); | |
} | |
void loop() { | |
int val = analogRead(A0); | |
unsigned int now = millis(); | |
unsigned int elapsed = now - lastPublish; | |
bool broken = val < 4000; | |
if (broken == lastState) { | |
return; | |
} | |
digitalWrite(D7, (broken) ? HIGH : LOW); | |
if (elapsed >= 1000) { | |
String topic = ((broken) ? "laser/alarm" : "laser/reset"); | |
String message = String(val); | |
Spark.publish(topic, message); | |
lastState = broken; | |
lastPublish = millis(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment