]> git.piffa.net Git - aerei/blob - aerei/antonino/bugatti/bugatti.ino
Common: aggiunto ritardo per Blink e Pwm, manca per Sequenza
[aerei] / aerei / antonino / bugatti / bugatti.ino
1 /* Bugatti di Antonino
2
3    2 LED / Strisce laterali che lampeggiano alternativamente
4    1 LED in PWM per il motore 
5    1 Striscia RGB sotto per tutta la lunghezza delle ali
6
7    Lettura del canale Throttle (3) con la funzione Pulsein
8 */
9
10 #include <common.h>
11
12 // LED disponibili
13 Lampeggiatore left = 7;
14 Lampeggiatore right = 8;
15 RGBLed sotto(6,5,9);
16 Pwm motore = 3;
17
18 // RGB
19 Pwm rsotto = 6;
20 Pwm gsotto = 5;
21 Pwm bsotto = 3;
22
23
24 // Variabili
25 const byte thrPin = A3; // PIN collegato al CH3
26 byte thr ;  // Throttle a 8bit
27 int thrIn ; // Valore del th in ingresso dal servo
28 byte caso ; // Valore random 
29
30 void setup() {
31   // I PINs vengono impostati dal constructor al momento
32   // della dichiarazione dell'ogetto.
33   pinMode(A3,INPUT);
34   right.Invert() ;  // Opzionale: inverte l'ordine del lampeggio da
35   // HI -> LOW --> LOW -> HI
36   // per avere 2 LED che lampeggiano alternativamente
37
38   randomSeed(analogRead(0));
39
40   // Test iniziale dei LED per verifica contatti:
41   left.High();
42   right.High();
43   sotto.White();
44   motore.Set(255);
45   delay(4000);
46 }
47
48 void loop() {
49   // Lettura CH3
50   thrIn = pulseIn(thrPin, HIGH, 25000);
51   // Hint: thrIn andrebbe calibrato son un Serial.write
52   thr = map(thrIn, 983, 2000, 0, 255);
53     
54 // Gestione throttle
55   if (thr >= 0 && thr < 15) {
56     // IDLE
57
58     right.Blink();
59     left.Blink();
60     gsotto.UD(2000);
61     motore.UD(2000);
62   } else if (thr < 245) {
63     // Throttle medio
64       
65     right.Blink(1120 - 4 * thr );
66     left.Blink(1120 - 4 * thr );
67     bsotto.UD(500 + thr * 4);
68     motore.lSet(thr);   // Luminosita' proporzionale al throttle
69   } else {
70     // Throttle al massimo: LED laterali lampeggiano a caso,
71     // Sotto luminosita' a caso
72
73     caso = random(20, 240) ;
74     right.Swap();
75     left.Swap();
76     motore.lSet(caso);
77     sotto.SetColor(caso,caso,caso);    
78     delay(caso);
79   }
80 }