]> git.piffa.net Git - aerei/blob - aerei/daniele/prototipo/prototipo.ino
7e4b2941a4a50e40b30a4e8271baff4399e9a2f1
[aerei] / aerei / daniele / prototipo / prototipo.ino
1 /* Aereo di Daniele
2
3 Prototipo:
4
5 Output:
6    2 LED ai lati con lampeggio alternato
7    1 LED PWM per motore
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 = 5;
26 Lampeggiatore right = 6;
27 Lampeggiatore coda = 9;
28
29 // Variabili per interrupt 0 si PIN 2
30 volatile unsigned int chValue2 = 1500; // Valore computato
31 volatile unsigned int chStart2 = 1500; // Inizio rilevamento
32
33 // Variabili per interrupt 1 su PIN 3
34 volatile unsigned int chValue3 = 1500; // Valore computato
35 volatile unsigned int chStart3 = 1500; // Inizio rilevamento
36
37 // Variabili per autocalibrazione 0
38 const byte chPin2 = 2; // PIN per la calibrazione alettone
39 int mid_point2 = 1500;
40
41 // Variabili per autocalibrazione 1
42 const byte chPin3 = 3; // PIN per la calibrazione
43 int mid_point3 = 1000;
44
45
46 void setup() {
47   // I PINs vengono impostati dal constructor al momento
48   // della dichiarazione dell'ogetto.
49
50   // HI -> LOW --> LOW -> HI
51   // per avere 2 LED che lampeggiano alternativamente
52     // Funzione relativa a calibrazione con pulsein:
53     //mid_point2 =  calibraTrim(chPin2) ; // Calibrazione del TRIM attivo sul canale
54     //mid_point3 =  calibraTrim(chPin3) ; // Calibrazione del TRIM attivo sul canale
55     attachInterrupt(0, chRise2, RISING); // PIN 2 su 328p / 168
56     attachInterrupt(1, chRise3, RISING); // PIN 3 su 328p / 168
57 #ifdef DEBUG
58 Serial.begin(9600); 
59 #endif
60 }
61
62 void loop() {
63
64 #ifdef DEBUG
65     Serial.print("PIN2: ");
66     Serial.print(chValue2);
67     Serial.print(" -base: ");
68     Serial.print(mid_point2);
69
70     Serial.print(" |-| PIN3:");
71     Serial.print(chValue3);
72     Serial.print(" -base: ");
73     Serial.println(mid_point3);
74     delay(200);
75 #endif
76 }
77 // Functions
78 void chRise2() {
79     attachInterrupt(0, chFall2, FALLING);
80     chStart2 = micros();
81 }
82
83 void chFall2() {
84     attachInterrupt(0, chRise2, RISING);
85     chValue2 = micros() - chStart2;
86 }
87 // Seconod iterrupt
88 void chRise3() {
89     attachInterrupt(1, chFall3, FALLING);
90     chStart3 = micros();
91 }
92
93 void chFall3() {
94     attachInterrupt(1, chRise3, RISING);
95     chValue3 = micros() - chStart3;
96 }