bus project 2 — ESP32 simulation

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

Components

Sketch code

#include <Arduino.h>
#include <SPI.h>
#include <Wire.h>
#include <SD.h>

#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <Adafruit_SSD1306.h>

#include <RTClib.h>
#include <TinyGPS++.h>
#include <math.h>


// =====================================================
//                    PIN DEFINITIONS
// =====================================================

// ---------- GPS ----------
#define GPS_RX 16
#define GPS_TX 17


// ---------- I2C ----------
#define I2C_SDA 21
#define I2C_SCL 22


// ---------- SPI ----------
#define SPI_SCK  18
#define SPI_MISO 19
#define SPI_MOSI 23


// ---------- MICRO SD ----------
#define SD_CS 13


// ---------- TFT ----------
#define TFT_CS  5
#define TFT_DC  26
#define TFT_RST 27


// ---------- BUTTONS ----------
#define START_BUTTON 32
#define END_BUTTON   33


// ---------- BUZZER ----------
#define BUZZER 25


// =====================================================
//                    OLED SETTINGS
// =====================================================

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64

#define OLED_ADDRESS 0x3C


// =====================================================
//                    FARE SETTINGS
// =====================================================

const float RATE_PER_KM = 2.0;

const float MINIMUM_FARE = 10.0;


// =====================================================
//                    DEMO MODE
// =====================================================

// TRUE = Velxio simulation
// FALSE = actual GPS

const bool DEMO_MODE = true;


// Demo starting location
const double DEMO_START_LAT = 16.9891;
const double DEMO_START_LON = 82.2475;


// Demo destination
const double DEMO_END_LAT = 17.0050;
const double DEMO_END_LON = 82.2600;


// =====================================================
//                    OBJECTS
// =====================================================

HardwareSerial GPS_Serial(2);

TinyGPSPlus gps;

RTC_DS3231 rtc;

Adafruit_ILI9341 tft(
  TFT_CS,
  TFT_DC,
  TFT_RST
);

Adafruit_SSD1306 oled(
  SCREEN_WIDTH,
  SCREEN_HEIGHT,
  &Wire,
  -1
);


// =====================================================
//                    VARIABLES
// =====================================================

unsigned long passengerID = 1001;

bool journeyStarted = false;

bool sdOK = false;

bool rtcOK = false;

bool oledOK = false;

bool tftOK = false;


// GPS coordinates

double startLatitude = 0.0;
double startLongitude = 0.0;

double destinationLatitude = 0.0;
double destinationLongitude = 0.0;


// Trip data

double distanceKm = 0.0;

double totalFare = 0.0;


// =====================================================
//                    BUZZER
// =====================================================

void beep(int duration)
{
  digitalWrite(BUZZER, HIGH);

  delay(duration);

  digitalWrite(BUZZER, LOW);
}


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

More projects by lavanyaavala1729