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