6 Link: http://aero.piffa.net
19 boolean toggleRead (byte togglePin, const unsigned int freq ) {
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
27 if (millis() - toggleTime > freq) {
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() ;
37 Serial.print(toggleIn);
38 Serial.print(" - Filtrato: ");
39 Serial.println(toggleValue);
42 if (toggleValue > soglia) {