bus ticket — ESP32 simulation

genaration

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
// ======================================================

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


// ---------- TFT ILI9341 ----------
#define TFT_CS    15
#define TFT_DC    2
#define TFT_RST   4


// ---------- SPI OLED ----------
#define OLED_CS   14
#define OLED_DC   27
#define OLED_RST  26


// ---------- MICRO SD ----------
#define SD_CS     5


// ---------- BUTTONS ----------
#define BUTTON_ENTRY  32
#define BUTTON_EXIT   33


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


// ---------- I2C ----------
#define SDA_PIN 21
#define SCL_PIN 22


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


// ======================================================
//                    DISPLAY OBJECTS
// ======================================================

Adafruit_ILI9341 tft(TFT_CS, TFT_DC, TFT_RST);

// IMPORTANT:
// OLED is SPI, NOT I2C
Adafruit_SSD1306 oled(
  128,
  64,
  &SPI,
  OLED_DC,
  OLED_RST,
  OLED_CS
);


// ======================================================
//                    RTC / GPS
// ======================================================

RTC_DS3231 rtc;

HardwareSerial GPS_Serial(1);
TinyGPSPlus gps;


// ======================================================
//                    SYSTEM SETTINGS
// ======================================================

const float FARE_PER_KM = 7.0;
const float MINIMUM_FARE = 10.0;

const float INITIAL_WALLET = 150.0;

// For demonstration
const float DEMO_DISTANCE = 5.00;


// ======================================================
//                SIMULATED BUS LOCATION
// ======================================================

// Starting point for software simulation
double busLatitude  = 16.9891;
double busLongitude = 82.2475;


// ======================================================
//                    PASSENGER DATA
// ======================================================

struct Passenger
{
  int id;

  bool inside;

  DateTime entryTime;
  DateTime exitTime;

  double entryLat;
  double entryLon;

  double exitLat;
  double exitLon;

  float distanceKm;
  float fare;

  float wallet;
};


const int MAX_PASSENGERS = 20;

Passenger passengers[MAX_PASSENGERS];

int passengerCount = 0;

int totalIn = 0;
int totalOut = 0;


// ======================================================
//                    FUNCTION DECLARATIONS
// ======================================================

void initializeDisplays();

void updateOLED();

void showWelcome();

void processEntry();

void processExit();

int findInsidePassenger();

String formatDateTime(DateTime dt);

void showEntryScreen(Passenger &p

More projects by lavanyaavala1729