coba_layar_tft — ESP32-S3 simulation

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

Components

Sketch code

#include <SPI.h>
#include <XPT2046_Touchscreen.h>
#include <Keypad.h>
#include <WiFi.h> 
#include <time.h>      
#include <sys/time.h>  

// --- KONFIGURASI LAYAR TFT ILI9488 ---
#define TFT_CS   5
#define TFT_DC   2
#define TFT_RST  4
#define TFT_W    480   
#define TFT_H    320
#define TFT_BL   13  

// --- KONFIGURASI TOUCH SCREEN XPT2046 ---
#define TOUCH_CS  40
#define TOUCH_IRQ 41
XPT2046_Touchscreen ts(TOUCH_CS, TOUCH_IRQ);

// --- KONFIGURASI KEYPAD 4x4 ---
const byte ROWS = 4; 
const byte COLS = 4; 
char keys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
byte rowPins[ROWS] = {36, 35, 21, 20}; 
byte colPins[COLS] = {19, 48, 47, 18}; 
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);

// --- STATE MACHINE & VARIABEL GLOBAL ---
enum ScreenState { DASHBOARD, AIR_DETAIL, ROOM_LIST, SETTING_MENU, SECURITY_MENU, SOUND_MENU, SCREEN_MENU, VERIFY_PIN, PIN_INPUT_MAIN, PIN_INPUT_GUEST, CONFIRM_PIN, LOG_MENU, INFO_MENU, DATETIME_MENU, NETWORK_MENU, WIFI_LIST_MENU, THRESHOLD_MENU };
ScreenState currentState = DASHBOARD;
ScreenState nextPinState; 

int lastSecond = -1; 
int currentBrightness = 255; 
unsigned long timeoutOptions[3] = {60000, 300000, 0}; 
int currentTimeoutIndex = 1; 

unsigned long lastTouchTime = 0;
bool isScreenOn = true;

String mainPin = "1234";
String guestPin = "1234";
String pinBuffer = "";
String tempNewPin = ""; 
String pinMessage = "";

bool isAlarmEnabled = true;
int alarmVolumeLevel = 1; 

// Variabel Jaringan & Sortir WiFi
bool isWifiEnabled = true;
bool isBluetoothEnabled = false;
int wifiScanCount = 0;
int currentWifiPage = 0;
const int WIFI_PER_PAGE = 4;
int sortedWifi[50]; 

// ==========================================
// VARIABEL SENSOR & THRESHOLD BARU
// ==========================================
bool isAman = true;

const int NUM_THRESHOLDS = 12;
String thresholdNames[NUM_THRESHOLDS] = {
  "Suhu (*C)", "Kelembapan(%)", "Tekanan(kPa)", "PM 1.0", 
  "PM 2.5", "PM 4.0", "PM 10", "Gas Dapur", 
  "CO2 (ppm)", "CO (ppm)", "VOC", "NOx"
};

// Nilai Normal Batas Atas (Real-world Default)
float thresholds[NUM_THRESHOLDS] = {
  35.0,   // Suhu
  70.0,   // Kelembapan
  105.0,  // Tekanan
  10.0,   // PM 1.0
  25.0,   // PM 2.5
  40.0,   // PM 4.0
  50.0,   // PM 10
  1000.0, // Gas Dapur
  1000.0, // CO2
  9.0,    // CO
  200.0,  // VOC
  40.0    // NOx
};

float thresholdsBackup[NUM_THRESHOLDS]; // Untuk fungsi "Batal"
int currentThresholdPage = 0;
int selectedThresholdIndex = -1;
String thresholdInputBuffer = "";

String accessLogs[5] = {
  "20 Sep 08:00 - Utama (Sukses)",
  "20 Sep 10:15 - Tamu  (Sukses)",
  "20 Sep 12:30 - Utama (Gagal) ",
  "20 Sep 15:45 - Utama (Sukses)",
  "20 Sep 18:20 - Tamu  (Sukses)"
};

// ==========================================
// PENGGERAK TFT & DRAWING TOOLS
// ==========================================
static void cmd(uint8_t c) {
  SPI.beginTransaction(SPISettings(40000000, MSBFIRST, SPI_MODE0));
  digitalWrite(

More projects by itsmebenn