]> git.piffa.net Git - aerei/blobdiff - libraries/aero/aero.cpp
Aero
[aerei] / libraries / aero / aero.cpp
diff --git a/libraries/aero/aero.cpp b/libraries/aero/aero.cpp
new file mode 100644 (file)
index 0000000..1def2d7
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+  Aero 
+
+Autore: Andrea Manni
+
+Link: http://aero.piffa.net
+Licenza:    GPLv3
+
+*/
+
+#include "Arduino.h"
+#include "aero.h"
+
+#define dEBUG
+
+//////////////////
+// Funzioni
+
+boolean toggleRead (byte togglePin, const unsigned int freq ) {
+// Variabili Toggle
+long static unsigned toggleTime ; // Timestamp per switch
+static int toggleValue = 0 ; // Valore catturato
+static int toggleIn = 0 ; // Valore filtrato
+const int soglia = 1400; // soglia per scatto toggle a 2 posizioni
+// const unsigned int freq = 500 ; // Ogni quanti millisecondi leggere il valore
+
+    if (millis() - toggleTime > freq) {
+
+        toggleIn = pulseIn(togglePin, HIGH, 25000);
+        if (toggleIn != 0 && toggleIn > 1000 && toggleIn <2000)  {
+            // get only resonable values
+            toggleValue = toggleIn;
+            toggleTime = millis() ;
+        } ;
+    };
+#ifdef DEBUG
+    Serial.print(toggleIn);
+    Serial.print(" - Filtrato: ");
+    Serial.println(toggleValue);
+#endif
+
+if (toggleValue > soglia) {
+    return 1;
+} else {
+    return 0;
+} ;
+
+}