]> git.piffa.net Git - aerei/blob - aerei/palla/prototipo/prototipo.ino
061b081363d9753e7713d5c97ae0ee5b16c4f63d
[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
9 Input:
10     2 interrupts per throttle 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
26 RGBLed sotto(5,6,9);
27 Pwm motore(10);
28
29 // Variabili per interrupt 0 si PIN 2: Throttle
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: Ailerons
34 volatile unsigned int chValue3 = 1500; // Valore computato
35 volatile unsigned int chStart3 = 1500; // Inizio rilevamento
36
37
38 // Variabili per autocalibrazione 0
39 const byte chPin2 = 2; // PIN per la calibrazione
40 int mid_point2 = 1000;
41
42 // Variabili per autocalibrazione 1
43 const byte chPin3 = 3; // PIN per la calibrazione
44 int mid_point3 = 1560;
45
46
47 void setup() {
48
49   // HI -> LOW --> LOW -> HI
50   // per avere 2 LED che lampeggiano alternativamente
51     // Funzione relativa a calibrazione con pulsein:
52     //mid_point2 =  calibraTrim(chPin2) ; // Calibrazione del TRIM attivo sul canale
53     //mid_point3 =  calibraTrim(chPin3) ; // Calibrazione del TRIM attivo sul canale
54     attachInterrupt(0, chRise2, RISING); // PIN 2 su 328p / 168
55     attachInterrupt(1, chRise3, RISING); // PIN 3 su 328p / 168
56 #ifdef DEBUG
57 Serial.begin(9600); 
58 #endif
59 }
60
61 void loop() {
62     sotto.Red();
63     motore.set(0);
64 delay(500);
65 sotto.Off();
66     sotto.Green();
67     motore.set(150);
68 delay(500);
69 sotto.Off();
70     sotto.Blue();
71     motore.set(250);
72 delay(500);
73 sotto.Off();
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 }