7 2 LED ai lati con lampeggio alternato
8 1 LED in coda lampeggio a freq doppia
15 Notes: abbondante usi di map().
23 // Variabili per interrupt 0 si PIN 2
24 volatile unsigned int chValue2 = 1500; // Valore computato
25 volatile unsigned int chStart2 = 1500; // Inizio rilevamento
27 // Variabili per interrupt 1 su PIN 3
28 volatile unsigned int chValue3 = 1500; // Valore computato
29 volatile unsigned int chStart3 = 1500; // Inizio rilevamento
31 // Variabili per autocalibrazione 0
32 const byte chPin2 = 2; // PIN per la calibrazione
35 // Variabili per autocalibrazione 1
36 const byte chPin3 = 3; // PIN per la calibrazione
37 int mid_point3 = 1500;
39 // Instanziamo un LED fuori dal loop
40 Lampeggiatore left = 4;
41 Lampeggiatore right = 11;
42 Lampeggiatore coda = 6;
44 Lampeggiatore stato = 13;
45 byte pins[] = { // PIN dei LED che compongono la sequenza
48 Sequenza seq = Sequenza(pins,3);
52 // Funzione relativa a calibrazione con pulsein:
53 mid_point3 = calibraTrim(chPin3) + 8; // La calibrazione in genere non serve
54 // su throttle, il valore minimo e' costante e non c'e' TRIM
56 attachInterrupt(0, chRise2, RISING); // PIN 2 su 328p / 168
57 attachInterrupt(1, chRise3, RISING); // PIN 3 su 328p / 168
63 stato.Blink(); // Onboard LED per vedere se la scheda e' accesa
65 right.Blink(map(chValue3,980,2020,800,200));
66 left.Blink(map(chValue3,980,2020,200,800));
67 coda.Blink(chValue2 /4);
68 motore.lSet((chValue2 -980) / 4);
69 seq.Update(map(chValue2,980,2000,300,40));
75 attachInterrupt(0, chFall2, FALLING);
80 attachInterrupt(0, chRise2, RISING);
81 chValue2 = micros() - chStart2;
85 attachInterrupt(1, chFall3, FALLING);
90 attachInterrupt(1, chRise3, RISING);
91 chValue3 = micros() - chStart3;