3 Nota: rovedere i PWM per come calcolano le pause:
4 non possono schendere sotto a 1ms
8 enum states_available { // Stati della FMS
9 idle, // Throttle a zero
13 states_available state ;
15 // Due LED con lampeggio alternato:
16 Lampeggiatore right = 3;
17 Lampeggiatore left = 5;
20 const byte thrPin = A3;
30 RGBLed rgb(7,8,4,255);
33 left.Invert() ; // Parte da stato invertito rispetto al default
34 pinMode(rtail, OUTPUT);
35 pinMode(ltail, OUTPUT);
36 pinMode(thrPin, INPUT);
37 // Warning: serial breaks PWM
38 // Serial.begin(9600);
40 randomSeed(analogRead(0));
41 // Test iniziale dei LED per verifica contatti:
53 thrIn = pulseIn(thrPin, HIGH, 25000);
54 thr = constrain(map(thrIn, 983, 2000, 0, 255), 0, 255) ;
55 // Inserire necro delay
56 delay(10); // Se si abilita il serial debug
62 } else if ( thr > 245 ) {
72 rwhite.UD(2000); // Utilizza il coseno
73 lwhite.UD(2000); // Bisognerebbe evitare di calcolarlo 4 volte uguale
81 // Due LED con lampeggio alternato:
82 right.Blink(1120 - 4 * thr );
83 left.Blink(1120 - 4 * thr );
84 analogWrite(rtail, lum(thr));
85 analogWrite(ltail, lum(thr));
90 pausa = random(30, 125);
91 // Due LED con lampeggio alternato:
92 right.Blink(1120 - 4 * thr );
93 digitalWrite(ltail, !digitalRead(ltail));
94 digitalWrite(3, !digitalRead(3));
97 left.Blink(1120 - 4 * thr );
98 digitalWrite(rtail, !digitalRead(rtail));
99 digitalWrite(5, !digitalRead(5));
105 // Serial.println(thrIn);
106 // Serial.print("\t thr:");
107 // Serial.print(thr);
108 // Serial.print("\t state:");
109 // Serial.println(state);