Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example of GPS Sync feature #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions examples/TimeGPSSync/TimeGPSSync.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <Time.h>
#include <TinyGPS++.h>
#include <SoftwareSerial.h>

SoftwareSerial gps(3, 4); // RX, TX
TinyGPSPlus gpsEncoder;

void setup() {
Serial.begin(9600);
gps.begin(9600);

setSyncProvider(&gpsTimeSync);
setSyncInterval(5); // Seconds between re-sync
}

void loop() {
while (gps.available() > 0) {
gpsEncoder.encode(gps.read());
}
Serial.print("Now: ");
Serial.println(now());
delay(1000);
}

/**
* This is the magic, we get the date/time from the GPS unit
* and use it to convert to a time_t
*/
time_t gpsTimeSync(void) {
tmElements_t tm;

tm.Second = gpsEncoder.time.second();
tm.Minute = gpsEncoder.time.minute();
tm.Hour = gpsEncoder.time.hour();
tm.Day = gpsEncoder.date.day();
tm.Month = gpsEncoder.date.month();
tm.Year = CalendarYrToTm(gpsEncoder.date.year());

return makeTime(tm);
}