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