]> git.piffa.net Git - aerei/blobdiff - esempi/base_th/base_th.ino
Stati / RGB
[aerei] / esempi / base_th / base_th.ino
index 0bb90e6ca1e77c553d67566b516b22d4a84ebdf2..5f534964e6423965999cbb2988ea340c33c2712c 100644 (file)
@@ -16,8 +16,11 @@ Pwm sotto = 9;
 
 // Variabili
 const byte thrPin = 3; // PIN collegato al CH3
-byte thr ; // Throttle
-int thrIn ;
+byte thr ; // Valore a 8bit per il throttle
+int thrIn ; // Valore rilevato del 3 Ch della RX 
+const int thMin = 983; // In genere il valore minimo del TH resta costante,
+// per calcolarlo si puo' usare la funzione di calibrazione nel setup
+
 
 void setup() {
     // I PINs vengono impostati dal constructor al momento
@@ -31,13 +34,12 @@ void setup() {
 void loop() {
 // Lettura CH3
     thrIn = pulseIn(thrPin, HIGH, 25000);
-    if (thrIn != 0 && ailIn > 983 && ailIn < 2000)  { // clean up
-        thr = map(thrIn, 983, 2000, 0, 255); // mappato su 8bit per PWM
-    }
+    if (thrIn >= thMin && thrIn < 2000)  { // clean up
+        thr = map(thrIn, thMin, 2000, 0, 255); // mappato su 8bit per PWM
+    };
 
 // Attivazione LEDs
         left.Blink(100 + thr);
         right.Blink(100 + thr);
         sotto.lSet(thr);   // Luminosita' proporzionale al throttle
-        delay(10); // Opzionale
     }