ORbBi — ESP32-C3 simulation

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

Components

Sketch code

#include <Arduino.h>
#include <Wire.h>
#include <WiFi.h>
#include <WebServer.h>
#include <Preferences.h>
#include <U8g2lib.h>
#include <time.h>

// =====================================================
// ORBI by HR Innovexa
// ESP32-C3 + SH1107 128x128 OLED
// =====================================================

// ---------- PIN CONFIGURATION ----------
const int POWER_PIN = 3;
const int UP_PIN = 4;
const int DOWN_PIN = 5;
const int SET_PIN = 6;
const int TOUCH_PIN = 7;
const int BUZZER_PIN = 2;
const int SDA_PIN = 8;
const int SCL_PIN = 9;

// Keep these values calibrated for your OLED
const int X_OFFSET = -20;
const int SAFE_W = 120;

const bool TOUCH_ACTIVE_HIGH = true;

const unsigned long DEBOUNCE_MS = 50;
const unsigned long DOUBLE_TAP_MS = 450;
const unsigned long LONG_PRESS_MS = 1000;

// ---------- DISPLAY ----------
U8G2_SH1107_128X128_F_HW_I2C oled(
  U8G2_R2,
  U8X8_PIN_NONE
);

WebServer server(80);
Preferences prefs;

// ---------- WIFI ----------
String wifiSSID = "";
String wifiPASS = "";
bool wifiConnected = false;
bool setupAP = false;

// ---------- DEVICE STATE ----------
bool deviceEnabled = true;

enum ScreenMode {
  SCREEN_HOME,
  SCREEN_TIMER,
  SCREEN_WATER,
  SCREEN_ROUTINE,
  SCREEN_MESSAGE
};

ScreenMode screenMode = SCREEN_HOME;

String messageText = "";
String routineText = "";

unsigned long screenStartedMs = 0;
unsigned long messageDurationMs = 6500;
unsigned long lastDisplayMs = 0;

// ---------- FOCUS TIMER ----------
bool timerRunning = false;
bool timerPaused = false;

unsigned long focusTimerStartMs = 0;
unsigned long focusTimerDurationMs = 0;
unsigned long focusTimerRemainingMs = 0;

unsigned long focusSessionCount = 0;
unsigned long focusMinutesTotal = 0;

// ---------- TOUCH ----------
bool touchWasPressed = false;
bool longPressHandled = false;

unsigned long touchStartMs = 0;
unsigned long lastTapMs = 0;
int touchTapCount = 0;

// ---------- POWER BUTTON ----------
int lastPowerReading = HIGH;
int stablePowerState = HIGH;
unsigned long lastPowerChangeMs = 0;

// ---------- REMINDERS ----------
unsigned long lastWaterReminderMs = 0;
unsigned long lastAutoMessageMs = 0;

const unsigned long WATER_INTERVAL_MS =
  2UL * 60UL * 60UL * 1000UL;

const unsigned long MESSAGE_INTERVAL_MS =
  90UL * 60UL * 1000UL;

// ---------- CONTENT ----------
const char* MESSAGES[] = {
  "Amake ki bhule geso?",
  "Kajer mood koi? Cholo focus kori!",
  "Error 404: Focus khuje pawa jacche na!",
  "Darun! Ajke bhalo focus korteso!",
  "Tumi ar ORBI ekhon powerful team!",
  "Brain: kaj kori. Ami: aro 5 min scroll!",
  "Facebook scroll komao, kajta shesh koro!",
  "Ami lazy na, energy save kortesi!",
  "Bhai, ektu cha-nasta kheye nao!",
  "Exam shamne! Phone rekhe pora shuru koro!",
  "Choto choto focus session-e boro result ashe!",
  "Break nao, tarpor abar focus!"
};

const int MESSAGE_COUNT =
  sizeof(MESSAGES) / sizeof(MESSAGES[0]);

const char* HEALTH_MESSAGES[] = {
  "Onekkhon pani khao ni! Ekhon ek glass pani kheye nao.",