speedometer-keren — ESP32 simulation

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

Components

Sketch code

#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <Adafruit_SSD1306.h>
#include <math.h>
#include "RTClib.h"
#include <Wire.h>
// #include <OneWire.h>
// #include <DallasTemperature.h>
#include "digital_720pt7b.h"
#include "digital_77pt7b.h"

RTC_DS3231 rtc;

char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

#define TFT_SCK  18
#define TFT_MOSI 23
#define TFT_MISO 19
#define TFT_DC    2
#define TFT_CS    15
#define TFT_RST   4

SPIClass tftSPI(VSPI);
Adafruit_ILI9341 tft = Adafruit_ILI9341(&tftSPI, TFT_DC, TFT_CS, TFT_RST);


#define I2C_SDA_2 32
#define I2C_SCL_2 33

TwoWire I2C_Kedua = TwoWire(1);

#define SCREEN_WIDTH 128
#define SCREEN_HIGHT 64
#define OLED_RESET   -1

Adafruit_SSD1306 oled1(SCREEN_WIDTH,SCREEN_HIGHT,&Wire,OLED_RESET);

Adafruit_SSD1306 oled2(SCREEN_WIDTH,SCREEN_HIGHT,&I2C_Kedua,OLED_RESET);

/*/====== vaiabel senso DS18B20====//
const int oneWireBus = 26;     

OneWire oneWire(oneWireBus);

DallasTemperature sensors(&oneWire);

// --- Konstanta Tachometer ---
#define TACHO_CX      64
#define TACHO_CY      60
#define TACHO_RADIUS  55
#define MAX_RPM       12000
#define PI            3.14159265

// --- Bitmap Ikon Bensin ---
const unsigned char PROGMEM gasIcon[] = {
  0x00, 0x00, 0x07, 0xf0, 0x0c, 0x18, 0x08, 0x18, 0x08, 0x38, 0x08, 0x68, 0x08, 0xc8, 0x08, 0x88,
  0x0b, 0x88, 0x0c, 0x88, 0x0b, 0x88, 0x08, 0x88, 0x08, 0x88, 0x08, 0x88, 0x0f, 0xf8, 0x00, 0x00
};

// --- Variabel State (Simulasi Sensor) ---
int speedDummy = 75;
int batteryLevel = 80;
bool seinKiri = false;
bool seinKanan = false;
bool engineWarning = false;
bool overheatWarning = false;
int rpmDummy = 0;
int rpmArah = 1; 
bool lowFuel = false;

// ==========================================
// MANAJEMEN WAKTU (Non-Blocking dengan millis)
// ==========================================
unsigned long previousMillisTFT = 0;
unsigned long previousMillisOLED1 = 0;
unsigned long previousMillisOLED2 = 0;
unsigned long previousMillisSein = 0;
unsigned long previousMillisSensor = 0;

// Interval Pembaruan (dalam milidetik)
const long intervalTFT    = 500;  // Jam, Kecepatan, Baterai di TFT diperbarui tiap 500ms
const long intervalOLED1  = 50;   // Tachometer butuh refresh cepat agar jarum mulus (50ms)
const long intervalOLED2  = 1000; // Info lingkungan cukup 1 detik sekali
const long intervalSein   = 500;  // Kedipan sein tiap 500ms (jika aktif)
const long intervalSensor = 100;  // Kecepatan baca sensor simulasi (100ms)
*/

// --- Warna Kustom (RGB565) ---
// Membuat warna biru gelap khas LCD Grand Filano
#define FILANO_BG     0x018D  // Biru Gelap
#define FILANO_TEXT   0x4A69  // Biru Keabu-abuan (Warna angka mati / redup)
#define FILANO_ACTIVE 0xFFFF  // Putih (Warna angka menyala) atau bisa pakai Cyan pekat
#define FILANO_CYAN   0x07FF  // Cyan terang untuk aksen garis

// --- Variabel State Dummy ---
int speedDummy = 0;
unsigned long previousMillisTFT = 0;


void setup() {
  Seria

More projects by fisyamska