#include <LiquidCrystal.h> // For LCD
#include <TinyGPSPlus.h> // For GPS
#include <SoftwareSerial.h> // For GPS
// Make sure wiring is correct!!
SoftwareSerial gpsSerial(5, 6); // (Rx, Tx)
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
TinyGPSPlus gps;
volatile float degMinutes, degSeconds;
volatile int degDegrees, degMins, degSecs;
const double maxLatitude = 90.0;
const double maxLongitude = 180.0;
double userLatitude = 0.0;
double userLongitude = 0.0;
void setup() {
Serial.begin(9600);
gpsSerial.begin(9600);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter Lat & Lon");
}
void loop() {
if (Serial.available() > 0) {
getUserInput();
lcd.clear();
if (userLatitude > maxLatitude || userLongitude > maxLongitude || userLatitude < -maxLatitude || userLongitude < -maxLongitude) {
lcd.setCursor(0, 0);
lcd.print("Out of area");
} else {
lcd.setCursor(0, 0);
lcd.print("In area");
lcd.setCursor(0, 1);
lcd.print("Lat: ");
lcd.print(userLatitude, 6);
lcd.print(" Lon: ");
lcd.print(userLongitude, 6);
}
}
}
void getUserInput() {
Serial.print("Enter Latitude: ");
while (Serial.available() == 0) {}
userLatitude = Serial.parseFloat();
Serial.println(userLatitude);
Serial.print("Enter Longitude: ");
while (Serial.available() == 0) {}
userLongitude = Serial.parseFloat();
Serial.println(userLongitude);
}
void convertToDegMinSec(double totalDegrees) {
degDegrees = (int)totalDegrees;
degMinutes = totalDegrees - degDegrees;
degSeconds = 60 * degMinutes;
degMinutes = (int)degSeconds;
degMins = (int)degMinutes;
degSeconds = degSeconds - degMinutes;
degSeconds = 60 * degSeconds;
degSecs = (int)degSeconds;
}