]> git.piffa.net Git - aerei/blob - libraries/aero/aero.cpp
Aero
[aerei] / libraries / aero / aero.cpp
1 /*
2   Aero 
3
4 Autore: Andrea Manni
5
6 Link: http://aero.piffa.net
7 Licenza:    GPLv3
8
9 */
10
11 #include "Arduino.h"
12 #include "aero.h"
13
14 #define dEBUG
15
16 //////////////////
17 // Funzioni
18
19 boolean toggleRead (byte togglePin, const unsigned int freq ) {
20 // Variabili Toggle
21 long static unsigned toggleTime ; // Timestamp per switch
22 static int toggleValue = 0 ; // Valore catturato
23 static int toggleIn = 0 ; // Valore filtrato
24 const int soglia = 1400; // soglia per scatto toggle a 2 posizioni
25 // const unsigned int freq = 500 ; // Ogni quanti millisecondi leggere il valore
26
27     if (millis() - toggleTime > freq) {
28
29         toggleIn = pulseIn(togglePin, HIGH, 25000);
30         if (toggleIn != 0 && toggleIn > 1000 && toggleIn <2000)  {
31             // get only resonable values
32             toggleValue = toggleIn;
33             toggleTime = millis() ;
34         } ;
35     };
36 #ifdef DEBUG
37     Serial.print(toggleIn);
38     Serial.print(" - Filtrato: ");
39     Serial.println(toggleValue);
40 #endif
41
42 if (toggleValue > soglia) {
43     return 1;
44 } else {
45     return 0;
46 } ;
47
48 }