]> git.piffa.net Git - aerei/blob - esempi/base_th/base_th.ino
0bb90e6ca1e77c553d67566b516b22d4a84ebdf2
[aerei] / esempi / base_th / base_th.ino
1 /* Esempio
2
3    Esempio base:
4    2 LED / Strisce laterali che lampeggiano alternativamente
5    1 LED / Striscia sotto in FADE
6
7    Lettura del canale Throttle (3) con la funzione Pulsein
8 */
9
10 #include <common.h>
11
12 // LED disponibili
13 Lampeggiatore left = 12;
14 Lampeggiatore right = 11;
15 Pwm sotto = 9;
16
17 // Variabili
18 const byte thrPin = 3; // PIN collegato al CH3
19 byte thr ; // Throttle
20 int thrIn ;
21
22 void setup() {
23     // I PINs vengono impostati dal constructor al momento
24     // della dichiarazione dell'ogetto.
25
26     right.Invert() ;  // Opzionale: inverte l'ordine del lampeggio da
27     // HI -> LOW --> LOW -> HI
28     // per avere 2 LED che lampeggiano alternativamente
29 }
30
31 void loop() {
32 // Lettura CH3
33     thrIn = pulseIn(thrPin, HIGH, 25000);
34     if (thrIn != 0 && ailIn > 983 && ailIn < 2000)  { // clean up
35         thr = map(thrIn, 983, 2000, 0, 255); // mappato su 8bit per PWM
36     }
37
38 // Attivazione LEDs
39         left.Blink(100 + thr);
40         right.Blink(100 + thr);
41         sotto.lSet(thr);   // Luminosita' proporzionale al throttle
42         delay(10); // Opzionale
43     }