]> git.piffa.net Git - aerei/blob - esempi/base_th/base_th.ino
430c94d89ad744ed625dd45764d9070111ef04fb
[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   thr = constrain(map(thrIn, 983, 2000, 0, 255), 0, 255) ;
35
36
37
38 // Attivazione LEDs
39   left.Blink(1120 - 4 * thr);   
40   right.Blink(1120 - 4 * thr);
41   sotto.lSet(thr);   // Luminosita' proporzionale al throttle
42   delay(10); // Opzionale 
43 }