-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClockGPSforVAS2.3homeTest.ino
223 lines (186 loc) · 5.58 KB
/
ClockGPSforVAS2.3homeTest.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
// Visual Alert System - using GPS for Clock
//
// Must have the Adafruit GPS library installed too! See:
// https://github.com/adafruit/Adafruit-GPS-Library
//
// Designed specifically to work with the Adafruit ultimate GPS returnout/shield
//
// Written by Jesse Ragsdale, cited some lines from Tony DiCola and Adafruit
//
// Version 2.3 updates:
// - Change "It is now / XXXX hours" on LCD to "It is XXXX Hours"
// - Add date to second line - print("Today is " + month3Ltr + " " + dayNbr);
// - changed from if loop to switch statement.
//
// Version 2.2 updates:
// - Useing GPS to get time
// - Change LCD output to LCD shield
#include <SoftwareSerial.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_GPS.h>
#include <LiquidCrystal.h>
#include <Adafruit_NeoPixel.h>
// Set to false to display time in 12 hour format, or true to use 24 hour:
#define TIME_24_HOUR true
// Offset the hours from UTC (universal time) to your local time by changing
// this value.
#define HOUR_OFFSET -5
SoftwareSerial gpsSerial(3, 2); // TX = pin 3 and RX = pin 2.
Adafruit_GPS gps(&gpsSerial);
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
#define PIN 11 // define which pin has the led strip
Adafruit_NeoPixel strip = Adafruit_NeoPixel(29, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
while (!Serial);
// Setup led strip
strip.begin();
strip.show();
strip.setBrightness(10);
// Setup Serial port to print debug output.
Serial.begin(115200);
Serial.println("Clock starting!");
// Setup LCD's # of column/rows
lcd.begin(16, 2);
// Setup the GPS using a 9600 baud connection
gps.begin(9600);
// Configure GPS to onlu output minimum data (location, time, fix).
gps.sendCommand(PMTK_SET_NMEA_OUTPUT_ALLDATA);
// Use a 1 hz, once a second, update rate.
gps.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
gps.sendCommand(PMTK_API_SET_FIX_CTL_1HZ);
// Enable the interrupt to parse GPS data.
enableGPSInterrupt();
}
void loop() {
// set the LCD cursor to column 0
lcd.setCursor(0, 0);
// Check if GPS has new data and parse it.
if (gps.newNMEAreceived()) {
gps.parse(gps.lastNMEA());
}
// Grab the current hours, minutes, seconds from the GPS.
int hours = gps.hour + HOUR_OFFSET;
// Handle when UTC + offset wraps around to a negative or > 23 value.
if (hours < 0) {
hours = 24+hours;
}
if (hours > 23) {
hours = 24-hours;
}
int minutes = gps.minute;
int seconds = gps.seconds;
// Show the time on the display by turning it into a numeric value
int displayValue = hours*100 + minutes;
// Do 24 hour to 12 hour format conversion when required.
if (!TIME_24_HOUR) {
// Handle when hours are past 12 by subtracting 12 hours (1200 value).
if (hours > 12) {
displayValue -= 1200;
}
// Handle hour 0 (midnight) being shown as 12.
else if (hours == 0) {
displayValue += 1200;
}
}
// Now print the time value to the display.
lcd.print("It is ");
lcd.print(displayValue);
lcd.print(" hours");
lcd.setCursor(0, 1);
lcd.print("on ");
lcd.print(gps.month);
lcd.print("/");
lcd.print(gps.day);
lcd.print("/20");
lcd.print(gps.year);
Serial.println(displayValue);
// this is home test - customize time for testing needs
switch (displayValue) {
case 2208:
rainbowCycleslow(1);
colorWipe(strip.Color(0,0,0), 50);
Serial.print(displayValue);
break;
case 2210:
rainbowCycle(1);
colorWipe(strip.Color(0,0,0), 50);
Serial.print(displayValue);
break;
case 2212:
rainbowCycleslow(1);
colorWipe(strip.Color(0,0,0), 50);
Serial.print(displayValue);
break;
case 2215:
rainbowCycle(1);
colorWipe(strip.Color(0,0,0), 50);
Serial.print(displayValue);
break;
default:
colorWipe(strip.Color(0,0,0), 50);
Serial.print(displayValue);
}
}
SIGNAL(TIMER0_COMPA_vect) {
// Use a timer interrupt once a millisecond to check for new GPS data.
gps.read();
}
void enableGPSInterrupt() {
// Function to enable the timer interrupt that will parse GPS data.
OCR0A = 0xAF;
TIMSK0 |= _BV(OCIE0A);
}
void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
}
void rainbowCycle(uint8_t wait) {
uint16_t i, j;
for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
for(i=0; i< strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
}
strip.show();
delay(wait);
}
}
void theaterChaseRainbow(uint8_t wait) {
for (int j=0; j < 256; j++) { // cycle all 256 colors in the wheel
for (int q=0; q < 3; q++) {
for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, Wheel( (i+j) % 255)); //turn every third pixel on
}
strip.show();
delay(wait);
for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, 0); //turn every third pixel off
}
}
}
}
void rainbowCycleslow(uint8_t wait) {
uint16_t r, j;
for(j=0; j<256*3; j++) { // 3 cycles of all colors on wheel
for(r=0; r< strip.numPixels(); r++) {
strip.setPixelColor(r, Wheel(((r * 256 / strip.numPixels()) + j) & 255));
}
strip.show();
delay(wait);
}
}
uint32_t Wheel(byte WheelPos) {
WheelPos = 255 - WheelPos;
if(WheelPos < 85) {
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
}
if(WheelPos < 170) {
WheelPos -= 85;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
WheelPos -= 170;
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}