extract output into a function
authorTom Parker <tom@carrott.org>
Sat, 31 Jan 2015 09:20:10 +0000 (22:20 +1300)
committerTom Parker <tom@carrott.org>
Sat, 31 Jan 2015 09:20:10 +0000 (22:20 +1300)
speedo_scaler.ino

index 97188f4..7a8e575 100644 (file)
@@ -8,14 +8,13 @@ int threshold = 5;
 
 int lastState = 0;
 int count = 0;
-int outputState = LOW;
+int outputState = HIGH;
 
 void setup() {
   pinMode(inPin, INPUT_PULLUP);
   pinMode(outPin, OUTPUT);
   pinMode(ledPin, OUTPUT);
-  digitalWrite(outPin, outputState);
-  digitalWrite(ledPin, outputState);
+  next();
   
   Serial.begin(115200);
   Serial << "online" << endl;
@@ -29,13 +28,17 @@ void loop() {
     count++;
     Serial << current << " " << count << endl;
     if (count >= threshold) {
-      if (outputState == LOW) {
-        outputState = HIGH;
-      } else {
-        outputState = LOW;
-      }
-      digitalWrite(outPin, outputState);
+      next();3
       count = 0;
     }
   }
 }
+
+void next() {
+  if (outputState == LOW) {
+    outputState = HIGH;
+  } else {
+    outputState = LOW;
+  }
+  digitalWrite(outPin, outputState);
+}