Location stamp with LCD — ESP32 simulation

An interactive ESP32 circuit simulation you can run free in your browser on Velxio, by lakshmikeerthimeesala.

Components

Sketch code

#include <TinyGPS++.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <math.h>

// ==================================================
// GPS
// ==================================================

TinyGPSPlus gps;

#define GPS_RX 16
#define GPS_TX 17

// ==================================================
// TFT ILI9341
// ==================================================

#define TFT_CS  5
#define TFT_DC  2
#define TFT_RST 4

Adafruit_ILI9341 tft(TFT_CS, TFT_DC, TFT_RST);

// ==================================================
// SOURCE LOCATION
// ==================================================

double sourceLatitude = 0.0;
double sourceLongitude = 0.0;
bool sourceSaved = false;

// ==================================================
// DESTINATION LOCATION
// ==================================================

double destinationLatitude = 0.0;
double destinationLongitude = 0.0;
bool destinationSaved = false;

// ==================================================
// DISTANCE AND FARE
// ==================================================

double distanceKm = 0.0;
double fare = 0.0;

const double FARE_PER_KM = 10.0;
const double EARTH_RADIUS_KM = 6371.0;

// ==================================================
// HAVERSINE DISTANCE
// ==================================================

double calculateDistance(double lat1, double lon1,
                         double lat2, double lon2) {

  double dLat = radians(lat2 - lat1);
  double dLon = radians(lon2 - lon1);

  double a = sin(dLat / 2) * sin(dLat / 2) +
             cos(radians(lat1)) *
             cos(radians(lat2)) *
             sin(dLon / 2) * sin(dLon / 2);

  double c = 2 * atan2(sqrt(a), sqrt(1 - a));

  return EARTH_RADIUS_KM * c;
}

// ==================================================
// DISPLAY LOCATION STAMP ON TFT
// ==================================================

void displayLocationStamp() {
  tft.fillScreen(ILI9341_BLACK);

  // -------------------------------
  // TITLE
  // -------------------------------
  tft.setTextColor(ILI9341_WHITE);
  tft.setTextSize(2);

  tft.setCursor(55, 5);
  tft.println("LOCATION STAMP");

  tft.drawLine(0, 28, 320, 28, ILI9341_WHITE);

  // -------------------------------
  // SOURCE
  // -------------------------------
  tft.setTextSize(1);

  tft.setCursor(5, 38);
  tft.println("SOURCE LOCATION");

  tft.setCursor(5, 52);
  tft.print("Lat: ");
  tft.println(sourceLatitude, 6);

  tft.setCursor(5, 66);
  tft.print("Lon: ");
  tft.println(sourceLongitude, 6);

  // -------------------------------
  // DESTINATION
  // -------------------------------
  tft.setCursor(5, 88);
  tft.println("DESTINATION LOCATION");

  tft.setCursor(5, 102);
  tft.print("Lat: ");
  tft.println(destinationLatitude, 6);

  tft.setCursor(5, 116);
  tft.print("Lon: ");
  tft.println(destinationLongitude, 6);

  // -------------------------------
  // DISTANCE
  // -------------------------------
  tft.setTextSize(2);

  tft.setCursor(5, 145);
  tft

More projects by lakshmikeerthimeesala