-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGPS_Clock_Software.ino
139 lines (117 loc) · 2.95 KB
/
GPS_Clock_Software.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
#include "LedControl_modified.h"
#include "GPS_Clock_Software.h"
#include "DateTime.h"
#include "RTClib.h"
#include "Adafruit_GPS_modified.h"
#include <SoftwareSerial.h>
#include "LedDisplay.h"
#define DEBUG
bool usingInterrupt = false;
DateTime PreviousDateTime;
DateTime DateTime;
TimeSpan TimeOffset;
//GPS recieves on D2, sends on D3
SoftwareSerial GPSSerial(3, 2);
Adafruit_GPS GPS(&GPSSerial);
bool readGPS();
void setTime();
void displayTime();
void useInterrupt(boolean); // Func prototype keeps Arduino 0023 happy
void setup() {
Serial.begin(115200);
Serial.println("Serial Initialised");
GPS.begin(9600);
delay(100);
//Set Sentences to Use
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY);
//GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
//Set update Rate
// GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_10HZ);
delay(100);
useInterrupt(false);
Display.setIntensity(8);
}
void loop() {
bool gps_parsed = readGPS();
if(gps_parsed)
{
//Serial.println("Display");
setTime();
if(!(PreviousDateTime == DateTime))
{
displayTime();
}
PreviousDateTime = DateTime;
}
}
bool readGPS()
{
bool parsed = false;
char c = GPS.read();
// if a sentence is received, we can check the checksum, parse it...
if (GPS.newNMEAreceived())
{
if (!GPS.parse(GPS.lastNMEA() ) )// this also sets the newNMEAreceived() flag to false
{
return false; // we can fail to parse a sentence in which case we should just wait for another
}//end if
parsed = true;
}//end if
return parsed;
}
void setTime()
{
DateTime.set(GPS.year, GPS.month, GPS.day, GPS.hour, GPS.minute, GPS.seconds);
if(!USEUTC)
{
if(DateTime.isInDST() && USETAUTODST)
{
TimeOffset = TIMEZONE + DST;
}
else
{
TimeOffset = TIMEZONE;
}
DateTime = DateTime + TimeOffset;
if(_12HOURCLOCK)
{
DateTime.hh %= 12;
if(DateTime.hh == 0) DateTime.hh = 12;
}
}
}
void displayTime()
{
#ifdef DEBUG
Serial.print("Quality:"); Serial.print(GPS.fixquality);
Serial.print("\nTime: ");
Serial.print(DateTime.hour(), DEC); Serial.print(':');
Serial.print(DateTime.minute(), DEC); Serial.print(':');
Serial.println(DateTime.second(), DEC);
Serial.print("Date: ");
Serial.print(DateTime.day(), DEC); Serial.print('/');
Serial.print(DateTime.month(), DEC); Serial.print("/");
Serial.println(DateTime.year(), DEC);
Serial.println("");
#endif
Display.write(DateTime);
}
//Interrupt Funcions
SIGNAL(TIMER0_COMPA_vect) {
char c = GPS.read();
Serial.print(c);
}
void useInterrupt(boolean v) {
if (v) {
// Timer0 is already used for millis() - we'll just interrupt somewhere
// in the middle and call the "Compare A" function above
OCR0A = 0xAF;
TIMSK0 |= _BV(OCIE0A);
usingInterrupt = true;
} else {
// do not call the interrupt function COMPA anymore
TIMSK0 &= ~_BV(OCIE0A);
usingInterrupt = false;
}
}