First half of thecode: (sorry it's long....)
//GPS
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
//WaveShield
#include <FatReader.h>
#include <SdReader.h>
#include <avr/pgmspace.h>
#include "WaveUtil.h"
#include "WaveHC.h"
//WaveShield
SdReader card; // This object holds the information for the card
FatVolume vol; // This holds the information for the partition on the card
FatReader root; // This holds the information for the filesystem on the card
FatReader f; // This holds the information for the file we're play
WaveHC wave; // This is the only wave (audio) object, since we will only play one at a time
/*
This sample code demonstrates the normal use of a TinyGPS++ (TinyGPSPlus) object.
It requires the use of SoftwareSerial, and assumes that you have a
9600-baud serial GPS device hooked up on pins 9(rx) and 8(tx).
*/
static const int RXPin = 8, TXPin = 9;
static const uint32_t GPSBaud = 9600;
// The TinyGPS++ object
TinyGPSPlus gps;
// The serial connection to the GPS device
SoftwareSerial ss(RXPin, TXPin);
//WayPoint info
int reachedWP1=false;
int reachedWP2=false;
int reachedWP3=false;
int radius=10; //Radius to point zero of the coordinate.
//WayPoint Coordinates
static const double WP1_LAT = 51.933397, WP1_LON = 5.147241;
static const double WP2_LAT = 51.933159, WP2_LON = 5.147750;
static const double WP3_LAT = 51.933543, WP3_LON = 5.147471;
void setup()
{
Serial.begin(9600);
ss.begin(GPSBaud);
//WaveShield Pinouts:
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
//WaveShield Setup:
if (!card.init(true)) { //play with 4 MHz spi if 8MHz isn't working for you
//if (!card.init()) { //play with 8 MHz spi (default faster!)
putstring_nl("Card init. failed!"); // Something went wrong, lets print out why
sdErrorCheck();
while(1); // then 'halt' - do nothing!
}
// enable optimize read - some cards may timeout. Disable if you're having problems
card.partialBlockRead(true);
// Now we will look for a FAT partition!
uint8_t part;
for (part = 0; part < 5; part++) { // we have up to 5 slots to look in
if (vol.init(card, part))
break; // we found one, lets bail
}
if (part == 5) { // if we ended up not finding one :(
putstring_nl("No valid FAT partition!");
sdErrorCheck(); // Something went wrong, lets print out why
while(1); // then 'halt' - do nothing!
}
// Lets tell the user about what we found
putstring("Using partition ");
Serial.print(part, DEC);
putstring(", type is FAT");
Serial.println(vol.fatType(),DEC); // FAT16 or FAT32?
// Try to open the root directory
if (!root.openRoot(vol)) {
putstring_nl("Can't open root dir!"); // Something went wrong,
while(1); // then 'halt' - do nothing!
}
playcomplete("8.WAV");
// Whew! We got past the tough parts.
putstring_nl("Ready!");
Serial.println(F("SpiderWick Geocache"));
Serial.println(F("Davy Uittenbogerd 2014"));
Serial.print(F("TinyGPS++ library v. ")); Serial.println(TinyGPSPlus::libraryVersion());
Serial.println();
Serial.println(F("Latitude Longitude Course Speed Card Distance Course Card Distance Course Card Distance Course Card Reached WP? "));
Serial.println(F("(deg) (deg) --- from GPS ---- ------ to WP1 ------ ------ to WP2 ------ ------ to WP3 ------ -WP1--WP2--WP--"));
Serial.println(F("---------------------------------------------------------------------------------------------------------------------------------------"));
}
void loop(){
// printInt(gps.satellites.value(), gps.satellites.isValid(), 5);
//printInt(gps.hdop.value(), gps.hdop.isValid(), 5);
printFloat(gps.location.lat(), gps.location.isValid(), 11, 6);
printFloat(gps.location.lng(), gps.location.isValid(), 12, 6);
//printInt(gps.location.age(), gps.location.isValid(), 5);
//printDateTime(gps.date, gps.time);
//printFloat(gps.altitude.meters(), gps.altitude.isValid(), 7, 2);
printFloat(gps.course.deg(), gps.course.isValid(), 7, 2);
printFloat(gps.speed.kmph(), gps.speed.isValid(), 6, 2);
printStr(gps.course.isValid() ? TinyGPSPlus::cardinal(gps.course.value()) : "*** ", 6);
//WayPoint1----------------------------------
unsigned long distanceToWP1 =
(unsigned long)TinyGPSPlus::distanceBetween(
gps.location.lat(),
gps.location.lng(),
WP1_LAT,
WP1_LON);
printInt(distanceToWP1, gps.location.isValid(), 9);
double courseToWP1 =
TinyGPSPlus::courseTo(
gps.location.lat(),
gps.location.lng(),
WP1_LAT,
WP1_LON);
printFloat(courseToWP1, gps.location.isValid(), 7, 2);
const char *cardinalToWP1 = TinyGPSPlus::cardinal(courseToWP1);
printStr(gps.location.isValid() ? cardinalToWP1 : "*** ", 6);
//WayPoint2------------------------------------
unsigned long distanceToWP2 =
(unsigned long)TinyGPSPlus::distanceBetween(
gps.location.lat(),
gps.location.lng(),
WP2_LAT,
WP2_LON);
printInt(distanceToWP2, gps.location.isValid(), 9);
double courseToWP2 =
TinyGPSPlus::courseTo(
gps.location.lat(),
gps.location.lng(),
WP2_LAT,
WP2_LON);
printFloat(courseToWP2, gps.location.isValid(), 7, 2);
const char *cardinalToWP2 = TinyGPSPlus::cardinal(courseToWP2);
printStr(gps.location.isValid() ? cardinalToWP2 : "*** ", 6);
//WayPoint3------------------------------------
unsigned long distanceToWP3 =
(unsigned long)TinyGPSPlus::distanceBetween(
gps.location.lat(),
gps.location.lng(),
WP3_LAT,
WP3_LON);
printInt(distanceToWP3, gps.location.isValid(), 9);
double courseToWP3 =
TinyGPSPlus::courseTo(
gps.location.lat(),
gps.location.lng(),
WP3_LAT,
WP3_LON);
printFloat(courseToWP3, gps.location.isValid(), 7, 2);
const char *cardinalToWP3 = TinyGPSPlus::cardinal(courseToWP3);
printStr(gps.location.isValid() ? cardinalToWP3 : "*** ", 6);
// Serial.println();