Created
February 28, 2018 15:26
-
-
Save proffalken/5dafd9f93206da5e823b517e55e678be to your computer and use it in GitHub Desktop.
Exen Mini Serial GPS Connection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <TinyGPS.h> | |
// Create our GPS Object | |
TinyGPS tracker; | |
// Hold the speed somewhere | |
float mph; | |
// How many satelites do we have in view? | |
int satelites; | |
// Variables will change: | |
int ledState = LOW; // ledState used to set the LED | |
// Generally, you should use "unsigned long" for variables that hold time | |
// The value will quickly become too large for an int to store | |
unsigned long previousMillis = 0; // will store last time LED was updated | |
// constants won't change: | |
const long interval = 1000; // interval at which to blink (milliseconds) | |
void setup() { | |
SerialUSB.begin(9600); | |
Serial.begin(9600); | |
SerialUSB.println("Starting up..."); | |
} | |
void loop() { | |
// Read the Values from the GPS unit | |
if (Serial.available() > 0) { | |
SerialUSB.println("Reading Serial"); | |
int c = Serial.read(); | |
if (tracker.encode(c)) | |
{ | |
satelites = tracker.satellites(); | |
// Process what we've just found | |
mph = tracker.f_speed_mph(); | |
SerialUSB.print("Current speed in MPH is "); | |
SerialUSB.println(mph); | |
SerialUSB.print("Current number of visible satelites is "); | |
SerialUSB.println(tracker.satellites()); | |
} else { | |
SerialUSB.println("Could not encode message"); | |
} | |
} | |
if (satelites > 0) { | |
digitalWrite(8, HIGH); | |
} | |
else | |
{ | |
unsigned long currentMillis = millis(); | |
if (currentMillis - previousMillis >= interval) { | |
// save the last time you blinked the LED | |
previousMillis = currentMillis; | |
// if the LED is off turn it on and vice-versa: | |
if (ledState == LOW) { | |
ledState = HIGH; | |
} else { | |
ledState = LOW; | |
} | |
// set the LED with the ledState of the variable: | |
digitalWrite(8, ledState); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment