3 FSM: il throttle e' a posto
7 2 LED PWM ai lati con lampeggio alternato
8 2 LED PWM alle estremita ali
11 2 interrupts per th e alettone
14 PIN A1: interruttore On/Off
17 NOTE: aggiunta libreria aero per gestione interruttore,
22 * Vedere la calibrazione automatica
23 * Min e max a 1000 - 2000 per alettone
31 // Instanziamo un LED fuori dal loop
32 Lampeggiatore left = 6;
33 Lampeggiatore right = 9;
34 Lampeggiatore codasx = 5;
35 Lampeggiatore codadx = 10;
42 // Variabili per interrupt 0 si PIN 2
43 volatile unsigned int chValue2 = 1500; // Valore computato
44 volatile unsigned int chStart2 = 1500; // Inizio rilevamento
46 // Variabili per interrupt 1 su PIN 3
47 volatile unsigned int chValue3 = 1500; // Valore computato
48 volatile unsigned int chStart3 = 1500; // Inizio rilevamento
50 const byte chPin = A1; // PIN interruttore generale
52 // Variabili per autocalibrazione 0
53 const byte chPin2 = 2; // PIN per la calibrazione alettone
54 int mid_point2 = 1500;
56 // Variabili per autocalibrazione 1
57 const byte chPin3 = 3; // PIN per la calibrazione
58 int mid_point3 = 1000;
65 // I PINs vengono impostati dal constructor al momento
66 // della dichiarazione dell'ogetto.
70 // HI -> LOW --> LOW -> HI
71 // per avere 2 LED che lampeggiano alternativamente
72 // Funzione relativa a calibrazione con pulsein:
73 mid_point2 = calibraTrim(chPin2) ; // Calibrazione del TRIM attivo sul canale
74 //mid_point3 = calibraTrim(chPin3) ; // Calibrazione del TRIM attivo sul canale
75 attachInterrupt(0, chRise2, RISING); // PIN 2 su 328p / 168
76 attachInterrupt(1, chRise3, RISING); // PIN 3 su 328p / 168
83 if (toggleRead(A0)) { // Interruttore generale
85 if (chValue3 < 1050) {
96 else if (chValue3 > 1900) {
97 // Throttle al massimo: LED laterali lampeggiano a caso,
98 // Sotto luminosita' a caso
99 caso = random(30, 250) ;
108 thrBit = map(chValue3,1050, 1900, 0, 255);
109 codasx.Blink(1220 - 4 * thrBit );
110 codadx.Blink(1220 - 4 * thrBit );
111 left.Blink(map(chValue2,1000,2000,200,800 ));
112 right.Blink(map(chValue2,1000,2000,800,200 ));
116 Serial.print("PIN2: ");
117 Serial.print(chValue2);
118 Serial.print(" -base: ");
119 Serial.print(mid_point2);
121 Serial.print(" |-| PIN3:");
122 Serial.print(chValue3);
123 Serial.print(" -base: ");
124 Serial.println(mid_point3);
127 } else { // Interruttore off
136 attachInterrupt(0, chFall2, FALLING);
141 attachInterrupt(0, chRise2, RISING);
142 chValue2 = micros() - chStart2;
146 attachInterrupt(1, chFall3, FALLING);
151 attachInterrupt(1, chRise3, RISING);
152 chValue3 = micros() - chStart3;