]> git.piffa.net Git - aerei/blob - aerei/zeta/zeta_prot/zeta_prot.ino
Cleanup, esempi
[aerei] / aerei / zeta / zeta_prot / zeta_prot.ino
1 /* Zeta prototipo
2
3    Sketch da breadboard, il throttle e' simulato con un potenziometro.
4
5 */
6
7 #include <common.h>
8 enum  { // Stati della FMS
9   idle,    // Throttle a zero
10   normal,  // Th normale
11   full,    // Th massimo
12 } state  ;
13
14 // Due LED con lampeggio alternato:
15 Lampeggiatore right = 3;
16 Pwm rpwm = 3;
17 const byte thrPin = A3;
18 byte thr ;
19 int thrIn ;
20
21
22
23 void setup() {
24  // Serial.begin(9600);
25   pinMode(A3, INPUT);
26   randomSeed(analogRead(0));
27 }
28
29 void loop() {
30
31   thrIn = analogRead(3);
32   thr = constrain(thrIn / 4 , 0, 255) ;
33
34   // FMS dispatcher
35   if ( thr < 10 ) {
36     state = idle ;
37   } else if ( thr > 245 ) {
38     state = full ;
39   } else {
40     state = normal ;
41   }
42
43   switch (state) {
44     case idle:
45      // digitalWrite(3,LOW);
46 rpwm.Up(1000);
47       break;
48
49     case normal:
50       // Due LED con lampeggio alternato:
51       right.Blink(1120 - 4 * thr );
52       break;
53
54     case full:
55       digitalWrite(3, HIGH);
56
57       break;
58   }
59
60
61 //  Serial.print(thrIn);
62 //  Serial.print("\t thr:");
63 //  Serial.print(thr);
64 //  Serial.print("\t state:");
65 //  Serial.println(state);
66 //  delay(200);
67 }