-
Notifications
You must be signed in to change notification settings - Fork 2
/
led.ino
133 lines (122 loc) · 2.92 KB
/
led.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
unsigned long NextLEDs=0;
uint8_t last_status = 0;
uint8_t last_light = 0;
void SetupLEDs(void)
{
#ifdef LED_WARN
pinMode(LED_WARN, OUTPUT);
digitalWrite(LED_WARN, 0);
digitalWrite(LED_WARN,1);
delay(500);
digitalWrite(LED_WARN,0);
#endif
#ifdef LED_TX
pinMode(LED_TX, OUTPUT);
digitalWrite(LED_TX, 0);
digitalWrite(LED_TX,1);
delay(500);
digitalWrite(LED_TX,0);
#endif
#ifdef LED_OK
pinMode(LED_OK, OUTPUT);
digitalWrite(LED_OK, 0);
digitalWrite(LED_OK,1);
delay(500);
digitalWrite(LED_OK,0);
#endif
}
void stepLights(){
if(last_light==0 || last_light==3){
digitalWrite(LED_WARN,1);
digitalWrite(LED_TX,0);
digitalWrite(LED_OK,0);
last_light = 1;
}else if(last_light==1){
digitalWrite(LED_TX,1);
digitalWrite(LED_WARN,0);
digitalWrite(LED_OK,0);
last_light = 2;
}else if(last_light==2){
digitalWrite(LED_OK,1);
digitalWrite(LED_WARN,0);
digitalWrite(LED_TX,0);
last_light = 3;
}
}
void ControlLEDs(int LEDOK, int LEDTX, int LEDWarn)
{
#ifdef LED_OK
digitalWrite(LED_OK, LEDOK);
#endif
#ifdef LED_WARN
digitalWrite(LED_WARN, LEDWarn);
#endif
#ifdef LED_TX
digitalWrite(LED_TX, LEDTX);
#endif
}
void allLEDoff(){
#ifdef LED_WARN
digitalWrite(LED_WARN,0);
#endif
#ifdef LED_TX
digitalWrite(LED_TX,0);
#endif
#ifdef LED_OK
digitalWrite(LED_OK,0);
#endif
}
void CheckLEDs(void){
if (millis() >= NextLEDs){
static byte Flash=0;
if (GPS.AltitudeF > 1500){
// All off
if(last_status!=5){
#ifdef DEBUG_SERIAL
DEBUG_SERIAL.print(F("Soaring high..."));
DEBUG_SERIAL.println(GPS.AltitudeF);
#endif
last_status = 5;
}
ControlLEDs(0,0,0);
}else if ((GPS.Lock > 0) && GPS.Satellites >= 6){
if(last_status!=4){
#ifdef DEBUG_SERIAL
DEBUG_SERIAL.print(F("Good GPS..."));
DEBUG_SERIAL.println(GPS.Satellites);
#endif
last_status = 4;
}
ControlLEDs(1, 0, 0);
}else if ((GPS.Lock > 0) && GPS.Satellites >= 4 && GPS.Satellites <6){
if(last_status!=3){
#ifdef DEBUG_SERIAL
DEBUG_SERIAL.print(F("Waiting for better GPS..."));
DEBUG_SERIAL.println(GPS.Satellites);
#endif
last_status = 3;
}
ControlLEDs(Flash, 0, 0);
}else if(GPS.Satellites >0 && (GPS.Satellites<4 || GPS.Lock<1)){
if(last_status!=2){
#ifdef DEBUG_SERIAL
DEBUG_SERIAL.print(F("Weak GPS..."));
DEBUG_SERIAL.println(GPS.Satellites);
#endif
last_status = 2;
}
ControlLEDs(Flash,Flash,0);
}else{
if(last_status!=1){
#ifdef DEBUG_SERIAL
DEBUG_SERIAL.print(F("No GPS..."));
DEBUG_SERIAL.println(GPS.Satellites);
#endif
last_status = 1;
}
ControlLEDs(Flash, Flash, Flash);
}
NextLEDs = millis() + 500L;
Flash = 1-Flash;
}
}