ST7789-ESP32C3 — Dfrobot Firebeetle2 Esp32S3 simulation

An interactive Dfrobot Firebeetle2 Esp32S3 circuit simulation you can run free in your browser on Velxio, by wsss.

Components

Sketch code

// ============================================================================
// DFRobot FireBeetle 2 ESP32-S3 + ILI9341 SPI LCD (LovyanGFX)
// 280×240 横屏灰阶夜景恐龙游戏
// ============================================================================
#include <WiFi.h>
#include <time.h>

#include "config.h"
#include "lgfx_config.h"
#include "state.h"
#include "game.h"
#include "ui.h"
#include "graphics.h"

// ============================================================================
// 全局对象
// ============================================================================
LGFX  tft;
uint16_t screenBuf[SCREEN_W * SCREEN_H];

// ============================================================================
// 全局状态
// ============================================================================
float moonXf = MOON_INIT_X;
int   moonX  = MOON_INIT_X;
int   moonY  = MOON_INIT_Y;
int   g_moonPhase = 4;

float    pay = 0.0f;
uint32_t coinCount = 0;
uint32_t lastCoinIndex = 0;
bool     g_timeValid = false;

bool coinActive = false;
int  coinX = SCREEN_W;
int  coinY = COIN_Y_LOW;
bool coinLifted = false;
bool coinJumpTriggered = false;

int      g_cactusPos = SCREEN_W;
int8_t   g_cactusNum = 1;
int      g_cactusX = SCREEN_W;
int      g_cactusW = 0;
int      g_cactusLen = 0;
const uint8_t* g_cactusBmp = nullptr;
bool     g_cactusJumped = false;
bool     g_cactusSmashed = false;
uint8_t  g_cactusSmashStep = 0;

uint8_t jump_flag = 0;
uint8_t g_jumpH = 0;
int8_t  g_jumpDir = 1;
int8_t  g_jumpBmp = -1;
int8_t  g_jumpFallIdx = 0;
bool    g_canDoubleJump = false;

CloudState g_clouds[CLOUD_MAX];
int        g_cloudSpawnTimer = 0;

const int8_t CACTUS_SMASH_TRAJ[CACTUS_SMASH_STEPS] = {
  3, 10, 18, 24, 28, 28, 24, 18, 10, 3, 0, -10, -24, -42, -64
};

// ============================================================================
// 月相计算
// ============================================================================
static int calcMoonPhase() {
  time_t now = time(nullptr);
  if (now < 1000000000) return 4;
  double jd = (double)now / 86400.0 + 2440587.5;
  double phase = fmod((jd - 2451550.1) / 29.530588853, 1.0);
  if (phase < 0) phase += 1.0;
  return (int)(phase * 8.0 + 0.5) % 8;
}

// ============================================================================
// setup
// ============================================================================
void setup() {
  Serial.begin(115200);
  delay(200);

  Serial.println("=== Dino Game Start ===");
  Serial.printf("Free heap: %d\n", ESP.getFreeHeap());
  Serial.printf("Screen: %dx%d, buf size: %d bytes\n",
                SCREEN_W, SCREEN_H, sizeof(screenBuf));

  Serial.printf("[WiFi] Connecting to %s\n", WIFI_SSID);
  WiFi.begin(WIFI_SSID, WIFI_PASS);

  unsigned long tStart = millis();
  while (WiFi.status() != WL_CONNECTED &&
         millis() - tStart < WIFI_TIMEOUT_MS) {
    delay(200);
    Serial.print(".");
  }
  Serial.println();

  if (WiFi.status() == WL_CONNECTED) {
    Serial.println("[WiFi] Connected");
    Se

More projects by wsss