From 17d4bbd68301e55c3037a38c0cdbda99dc124af0 Mon Sep 17 00:00:00 2001 From: Andrea Manni Date: Wed, 15 Mar 2017 12:46:53 +0100 Subject: [PATCH] Aero --- libraries/aero | 1 - libraries/aero/aero.cpp | 48 +++++++++++++++++++ libraries/aero/aero.h | 22 +++++++++ libraries/aero/examples/tog_func/tog_func.ino | 42 ++++++++++++++++ libraries/aero/keywords.txt | 1 + libraries/aero/library.properties | 9 ++++ 6 files changed, 122 insertions(+), 1 deletion(-) delete mode 160000 libraries/aero create mode 100644 libraries/aero/aero.cpp create mode 100644 libraries/aero/aero.h create mode 100644 libraries/aero/examples/tog_func/tog_func.ino create mode 100644 libraries/aero/keywords.txt create mode 100644 libraries/aero/library.properties diff --git a/libraries/aero b/libraries/aero deleted file mode 160000 index 5d8011d..0000000 --- a/libraries/aero +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 5d8011da088d10d3baf1804159b19aead3c06f3a diff --git a/libraries/aero/aero.cpp b/libraries/aero/aero.cpp new file mode 100644 index 0000000..1def2d7 --- /dev/null +++ b/libraries/aero/aero.cpp @@ -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; +} ; + +} diff --git a/libraries/aero/aero.h b/libraries/aero/aero.h new file mode 100644 index 0000000..d946e22 --- /dev/null +++ b/libraries/aero/aero.h @@ -0,0 +1,22 @@ +/* + Aero + +Autore: Andrea Manni + +Link: http://aero.piffa.net +Licenza: GPLv3 + +*/ + +#include "Arduino.h" +#include + +#ifndef aero_h +#define aero_h + +////////////////////// +// Funzioni + +boolean toggleRead(byte togglePin, const unsigned int freq = 500) ; + +#endif diff --git a/libraries/aero/examples/tog_func/tog_func.ino b/libraries/aero/examples/tog_func/tog_func.ino new file mode 100644 index 0000000..c13a91c --- /dev/null +++ b/libraries/aero/examples/tog_func/tog_func.ino @@ -0,0 +1,42 @@ +/* Toggle con transizioni tra On | OFF con pulseIn + Funzione + + +Sketch di esempio per accensione spegnimento di tutto l'impianto luci +tramite un interruttore a due posizioni della radio utilizzando +la funzione toggleRead(pin) basata su pulseIn. + + +Input: + 1 pulseIn su A0 per accensione / spegnimento luci + + + Il codice e' blocking fin tanto che il segnale passa da RISE a FALL + quindi blocca per 1-2ms a ogni esecuzione. Con la variabile freq + si imposta ogni quanto fare una lettura (default = 500ms). + + +*/ + +#define dEBUG +#include +#include + +void setup() { + Serial.begin(9600); +} ; + +void loop() { + + +if (toggleRead(A0)) { // Numero del PIN a cui e' collegato il canale dell'interruttore +//if (toggleRead(A0,100)) { // Numero del PIN, frequenza di aggiornamento in milli sec + // Luci accese + Serial.println("Luci On "); +} else { + // luci spente + Serial.println("Luci Off "); +} ; + + +} diff --git a/libraries/aero/keywords.txt b/libraries/aero/keywords.txt new file mode 100644 index 0000000..591e203 --- /dev/null +++ b/libraries/aero/keywords.txt @@ -0,0 +1 @@ +toggleRead KEYWORD2 diff --git a/libraries/aero/library.properties b/libraries/aero/library.properties new file mode 100644 index 0000000..c6edb67 --- /dev/null +++ b/libraries/aero/library.properties @@ -0,0 +1,9 @@ +name=Aero +version=1.0 +author=Andrea Manni +maintainer=Andrea Manni +sentence=Funzioni specifiche per aerei +paragraph=Funzioni da richiamare negli sketch per aerei rc +category=Display +url=https://aerei.piffa.net +architectures=* -- 2.39.2