7 2 LED ai lati con lampeggio alternato
8 1 LED in coda lampeggio a freq doppia
9 3 Sequenza di LED da 3 unita' ripetuta 3 volte
16 Notes: abbondante usi di map().
24 // Variabili per interrupt 0 si PIN 2
25 volatile unsigned int chValue2 = 1500; // Valore computato
26 volatile unsigned int chStart2 = 1500; // Inizio rilevamento
28 // Variabili per interrupt 1 su PIN 3
29 volatile unsigned int chValue3 = 1500; // Valore computato
30 volatile unsigned int chStart3 = 1500; // Inizio rilevamento
32 // Variabili per autocalibrazione 0
33 const byte chPin2 = 2; // PIN per la calibrazione
36 // Variabili per autocalibrazione 1
37 const byte chPin3 = 3; // PIN per la calibrazione
38 int mid_point3 = 1500;
40 // Instanziamo un LED fuori dal loop
41 Lampeggiatore left = 4;
42 Lampeggiatore right = 11;
43 Lampeggiatore coda = 6;
45 Lampeggiatore stato = 13;
46 byte pins[] = { // PIN dei LED che compongono la sequenza
49 Sequenza seq = Sequenza(pins,3);
53 // Funzione relativa a calibrazione con pulsein:
54 mid_point3 = calibraTrim(chPin3) + 8; // La calibrazione in genere non serve
55 // su throttle, il valore minimo e' costante e non c'e' TRIM
57 attachInterrupt(0, chRise2, RISING); // PIN 2 su 328p / 168
58 attachInterrupt(1, chRise3, RISING); // PIN 3 su 328p / 168
64 stato.Blink(); // Onboard LED per vedere se la scheda e' accesa
66 right.Blink(map(chValue3,980,2020,800,200));
67 left.Blink(map(chValue3,980,2020,200,800));
68 coda.Blink(chValue2 /4);
69 motore.lSet((chValue2 -980) / 4);
70 seq.Update(map(chValue2,980,2000,300,40));
76 attachInterrupt(0, chFall2, FALLING);
81 attachInterrupt(0, chRise2, RISING);
82 chValue2 = micros() - chStart2;
86 attachInterrupt(1, chFall3, FALLING);
91 attachInterrupt(1, chRise3, RISING);
92 chValue3 = micros() - chStart3;