Created
August 11, 2012 08:27
-
-
Save KarbonDallas/3322493 to your computer and use it in GitHub Desktop.
orobos-orias opened/closed circuit trigger sketch
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 trigger = 0; | |
int inPin = 8; | |
int outPin = 9; | |
unsigned long lastReport; | |
unsigned long currentStamp; | |
String output; | |
void setup() { | |
Serial.begin(115200); | |
pinMode(outPin, OUTPUT); | |
pinMode(inPin, INPUT); | |
digitalWrite(inPin, HIGH); | |
currentStamp = millis(); | |
lastReport = currentStamp; | |
} | |
void loop() { | |
currentStamp = millis(); | |
trigger = digitalRead(inPin); | |
if(trigger == HIGH) { | |
report(HIGH); | |
} | |
else { | |
report(LOW); | |
} | |
} | |
void report(int state) { | |
if(currentStamp - lastReport > 500) { | |
lastReport = currentStamp; | |
output = "STATUS::"; | |
output += state; | |
Serial.println(output); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment