Skip to content

Instantly share code, notes, and snippets.

@KarbonDallas
Created August 11, 2012 08:27
Show Gist options
  • Save KarbonDallas/3322493 to your computer and use it in GitHub Desktop.
Save KarbonDallas/3322493 to your computer and use it in GitHub Desktop.
orobos-orias opened/closed circuit trigger sketch
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