From 848bebda4a1093fe92a21b68abb7247f5f2b660d Mon Sep 17 00:00:00 2001 From: Andrea Manni Date: Sun, 5 Feb 2017 02:18:17 +0100 Subject: [PATCH 1/1] Calibrazione servo in --- libraries/common/common.cpp | 36 ++++++++++++++++++++++++++++++++++++ libraries/common/common.h | 6 +++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/libraries/common/common.cpp b/libraries/common/common.cpp index 01f07cf..413b86f 100644 --- a/libraries/common/common.cpp +++ b/libraries/common/common.cpp @@ -355,3 +355,39 @@ byte lum(byte val) { // storata in SRAM return pgm_read_byte_near(BCORRECT + val); }; + + +int calibraTrim(int pin, byte ledPin) { +/* START Calibrazione TRIM canale: + Lettura di 10 smaple + calcolo del valore medio esclusi gli 0 + + I canali come alettoni / elevatore possono avere un TRIM + (generalmente il throttle non ha un TRIM impostato), + questa funzione nel setup serve per trovare il punto medio + all'avvio dello sketch. + */ + byte a = 0; + int ail = 0; + int ailIn = 0; + Serial.println(">> Calibrazione: "); + while (a < 10) { + ailIn = pulseIn(pin, HIGH, 25000); + if (ailIn != 0 ) { + ail = ail + ailIn ; + a++ ; + Serial.print(a); + Serial.print(": "); + Serial.println(ail); + digitalWrite(ledPin, !digitalRead(ledPin)); + delay(10); + } + } + Serial.print(">> Fine Calibrazione: "); + Serial.print(ail / 10); + Serial.println("--"); + Serial.flush() ; + return(ail / 10) ; +// END calibrazione +} + diff --git a/libraries/common/common.h b/libraries/common/common.h index 97893fc..7f87600 100644 --- a/libraries/common/common.h +++ b/libraries/common/common.h @@ -154,6 +154,10 @@ class Sequenza { // Funzioni void brilla(byte pin, int velocita = 200) ; -#endif byte lum(byte val); + +int calibraTrim(int pin, byte ledPin = 13); + + +#endif -- 2.39.2