#include <Arduino.h>
Adafruit_GPS GPS(&Serial);
#define GPSECHO true
#define LOOP_PERIOD 35 // Display updates every 35 ms
uint32_t timer = millis();
float speedValue = 0.0;
float mapValue(float ip, float ipmin, float ipmax, float tomin, float tomax)
{
return tomin + (((tomax - tomin) * (ip - ipmin))/ (ipmax - ipmin));
}
void setup(void)
{
Serial.begin(4800);
String initText = "Initializing GPS...";
GPS.begin(4800);
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
}
void loop()
{
static uint32_t updateTime = 0;
char c = GPS.read();
if (GPS.newNMEAreceived()) {
// a tricky thing here is if we print the NMEA sentence, or data
// we end up not listening and catching other sentences!
// so be very wary if using OUTPUT_ALLDATA and trytng to print out data
if (!GPS.parse(GPS.lastNMEA())) // this also sets the newNMEAreceived() flag to false
return; // we can fail to parse a sentence in which case we should just wait for another
}
if (millis() - updateTime >= LOOP_PERIOD){
updateTime = millis();
speedValue = GPS.speed;
speedValue = speedValue * 1.15; //knots to mph
float current;
current = mapValue(speedValue, (float)0.0, (float)100.0, (float)0.0, (float)60.0);
String compassText = "Compass: " + (String)GPS.angle;
String latlonText = (String)GPS.latitudeDegrees + ", " + (String)GPS.longitudeDegrees;
String satellitesText = "Satellites: " + (String)GPS.satellites;
}
}