]> git.piffa.net Git - aerei/blob - aerei/daniele/prototipo/prototipo.ino
Daniele
[aerei] / aerei / daniele / prototipo / prototipo.ino
1 /* Aereo di Daniele
2
3 Prototipo: F8 Bearcat
4
5 Output:
6    2 LED PWM ai lati con lampeggio alternato
7    2 LED PWM alle estremita ali
8
9 Input:
10     2 interrupts per th e alettone
11     PIN 2:  alettone
12     PIN 3:  throttle
13
14
15     TODO
16 * Vedere la calibrazione automatica
17 * Min e max a 1000 - 2000 per alettone
18
19 */
20
21 #include <common.h>
22 # define DEBUG
23
24 // Instanziamo un LED fuori dal loop
25 Lampeggiatore left = 6;
26 Lampeggiatore right = 9;
27 Lampeggiatore codasx = 5;
28 Lampeggiatore codadx = 10;
29
30 //Pwm pleft = 6;
31 //Pwm pright = 9;
32 //Pwm pcodasx = 5;
33 //Pwm pcodadx = 10;
34
35 // Variabili per interrupt 0 si PIN 2
36 volatile unsigned int chValue2 = 1500; // Valore computato
37 volatile unsigned int chStart2 = 1500; // Inizio rilevamento
38
39 // Variabili per interrupt 1 su PIN 3
40 volatile unsigned int chValue3 = 1500; // Valore computato
41 volatile unsigned int chStart3 = 1500; // Inizio rilevamento
42
43 // Variabili per autocalibrazione 0
44 const byte chPin2 = 2; // PIN per la calibrazione alettone
45 int mid_point2 = 1500;
46
47 // Variabili per autocalibrazione 1
48 const byte chPin3 = 3; // PIN per la calibrazione
49 int mid_point3 = 1000;
50
51
52 void setup() {
53   // I PINs vengono impostati dal constructor al momento
54   // della dichiarazione dell'ogetto.
55 right.Invert();
56 codadx.Invert();
57
58   // HI -> LOW --> LOW -> HI
59   // per avere 2 LED che lampeggiano alternativamente
60     // Funzione relativa a calibrazione con pulsein:
61     //mid_point2 =  calibraTrim(chPin2) ; // Calibrazione del TRIM attivo sul canale
62     //mid_point3 =  calibraTrim(chPin3) ; // Calibrazione del TRIM attivo sul canale
63     attachInterrupt(0, chRise2, RISING); // PIN 2 su 328p / 168
64     attachInterrupt(1, chRise3, RISING); // PIN 3 su 328p / 168
65 #ifdef DEBUG
66 Serial.begin(9600); 
67 #endif
68 }
69
70 void loop() {
71 left.Blink(300);
72 right.Blink(300);
73 codasx.Blink();
74 codadx.Blink();
75
76 #ifdef DEBUG
77     Serial.print("PIN2: ");
78     Serial.print(chValue2);
79     Serial.print(" -base: ");
80     Serial.print(mid_point2);
81
82     Serial.print(" |-| PIN3:");
83     Serial.print(chValue3);
84     Serial.print(" -base: ");
85     Serial.println(mid_point3);
86     delay(200);
87 #endif
88 }
89 // Functions
90 void chRise2() {
91     attachInterrupt(0, chFall2, FALLING);
92     chStart2 = micros();
93 }
94
95 void chFall2() {
96     attachInterrupt(0, chRise2, RISING);
97     chValue2 = micros() - chStart2;
98 }
99 // Seconod iterrupt
100 void chRise3() {
101     attachInterrupt(1, chFall3, FALLING);
102     chStart3 = micros();
103 }
104
105 void chFall3() {
106     attachInterrupt(1, chRise3, RISING);
107     chValue3 = micros() - chStart3;
108 }