]> git.piffa.net Git - aerei/blob - aerei/zeta/zeta_5_no_state/zeta_5_no_state.ino
RGB LED per alettoni
[aerei] / aerei / zeta / zeta_5_no_state / zeta_5_no_state.ino
1 /* Zeta senza state machine
2  
3 Gestione del Throttle con ciclo condizionale.
4
5 */
6
7 #include <common.h>
8
9
10 // Due LED con lampeggio alternato:
11 Lampeggiatore right = 3;
12 Lampeggiatore left = 5;
13 const byte rtail = 6;
14 const byte ltail = 9;
15 const byte thrPin = A3;
16 byte thr ;
17 int thrIn ;
18
19 void setup() {
20   left.Invert() ; // Parte da stato invertito rispetto al default
21   pinMode(rtail, OUTPUT);
22   pinMode(ltail, OUTPUT);
23   pinMode(thrPin, INPUT);
24   // Serial.begin(9600);
25
26   randomSeed(analogRead(0));
27 }
28
29 void loop() {
30   thrIn = pulseIn(thrPin, HIGH, 25000);
31   thr = constrain(map(thrIn, 983, 2000, 0, 255), 0, 255) ;
32
33   if (thr >0 && thr < 15) {
34     digitalWrite(rtail, 1);
35 digitalWrite(ltail, 1);
36     digitalWrite(3, 1);
37 digitalWrite(5, 1);
38
39   } else if (thr < 245) {
40         // Due LED con lampeggio alternato:
41     right.Blink(1120 - 4 * thr );
42     left.Blink(1120 - 4 * thr );
43     analogWrite(rtail, thr);
44     analogWrite(ltail, thr);
45   } else {
46     digitalWrite(rtail, !digitalRead(rtail));
47     digitalWrite(ltail, !digitalRead(ltail));
48     delay(random(20, 100));
49
50     //lampA;
51     //lampB;
52
53   }
54   Serial.println(thrIn);
55   Serial.print("\t thr:");
56   Serial.println(thr);
57
58 }