naive implementation
authorTom Parker <tom@carrott.org>
Sat, 31 Jan 2015 09:13:03 +0000 (22:13 +1300)
committerTom Parker <tom@carrott.org>
Sat, 31 Jan 2015 09:13:03 +0000 (22:13 +1300)
speedo_scaler.ino [new file with mode: 0644]

diff --git a/speedo_scaler.ino b/speedo_scaler.ino
new file mode 100644 (file)
index 0000000..97188f4
--- /dev/null
@@ -0,0 +1,41 @@
+#include <Streaming.h>
+
+int inPin = 2;
+int outPin = 3;
+int ledPin = 13;
+int threshold = 5;
+
+
+int lastState = 0;
+int count = 0;
+int outputState = LOW;
+
+void setup() {
+  pinMode(inPin, INPUT_PULLUP);
+  pinMode(outPin, OUTPUT);
+  pinMode(ledPin, OUTPUT);
+  digitalWrite(outPin, outputState);
+  digitalWrite(ledPin, outputState);
+  
+  Serial.begin(115200);
+  Serial << "online" << endl;
+}
+
+void loop() {
+  int current = digitalRead(inPin);
+  if (current != lastState) {
+    lastState = current;
+    digitalWrite(ledPin, current);
+    count++;
+    Serial << current << " " << count << endl;
+    if (count >= threshold) {
+      if (outputState == LOW) {
+        outputState = HIGH;
+      } else {
+        outputState = LOW;
+      }
+      digitalWrite(outPin, outputState);
+      count = 0;
+    }
+  }
+}