1 /* Throttle state machine
3 Idle, throttle e averburner effect basati sono sul canale throttle.
5 FSM con dispatcher esterno.
12 enum { // Stati della FMS
13 idle, // Throttle a zero
18 // Due LED con lampeggio alternato:
19 Lampeggiatore right = 3;
20 Lampeggiatore left = 5;
23 const byte thrPin = A3;
24 byte thr ; // Valore a 8bit per il throttle
25 int thrIn ; // Valore rilevato del 3 Ch della RX
26 const int thMin = 983; // In genere il valore minimo del TH resta costante,
30 left.Invert() ; // Parte da stato invertito rispetto al default
31 randomSeed(analogRead(0));
36 // Lettura Throttle channel: FAKE con un potenziometro
37 //thrIn = analogRead(3);
38 //thr = constrain(thrIn / 4 , 0, 255) ;
40 // Lettura Throttle channel
41 thrIn = pulseIn(thrPin, HIGH, 25000);
42 if (thrIn >= thMin && thrIn < 2000) { // clean up
43 thr = map(thrIn, thMin, 2000, 0, 255); // mappato su 8bit per PWM
49 } else if ( thr > 245 ) {
57 // Lampeggia i lati fissi e fa un PWD Up/Down col motore
64 // right e left lampeggiano alternativamente in base al th,
65 // il motore e' acceso con correzione di luminosita' in proporzione al th
66 right.Blink(1120 - 4 * thr ); // lampeggio piu' rapido in base al Th
67 left.Blink(1120 - 4 * thr );
72 // lampeggi e PWM a caso
75 motore.lSet(random(0,255));
76 delay(random(20, 100));