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
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 thr = constrain(map(thrIn, 983, 2000, 0, 255), 0, 255) ; // 983 potrebbe cambiare
43 // con un altra ricevente, fare una calibrazione nel caso.
48 } else if ( thr > 245 ) {
56 // Lampeggia i lati fissi e fa un PWD Up/Down col motore
63 // right e left lampeggiano alternativamente in base al th,
64 // il motore e' acceso con correzione di luminosita' in proporzione al th
65 right.Blink(1120 - 4 * thr ); // lampeggio piu' rapido in base al Th
66 left.Blink(1120 - 4 * thr );
71 // lampeggi e PWM a caso
74 motore.lSet(random(0,255);
75 delay(random(20, 100));