ESP32 LED Board Design
Block Diagram
Project Specification
Firmware Getting Started
platformio.ini:src/main.cpp)
Startup SequenceDepending on Arduino-ESP32 release, include `` and omitbtStop()if it conflicts with NimBLE startup. The hardware shutdown/charge inhibit must not depend on this firmware.
Board Bring-Up Plan
platformio.ini:Ini
[env:esp32-c3-devkitm-1] platform = espressif32 board = esp32-c3-devkitm-1 framework = arduino monitor_speed = 115200 lib_deps = fastled/FastLED@^3.7.0 build_flags = -DARDUINO_USB_CDC_ON_BOOT=1
Table
| GPIO | Function | Notes |
|---|---|---|
| 0 | Button 1 | Active low, external 10 kΩ pull-up + 100 Ω series |
| 1 | Button 2 | Active low |
| 3 | Button 3 | Active low |
| 4 | Button 4 | Active low |
| 5 | Button 5 | Active low |
| 6 | Button 6 | Active low |
| 7 | Battery ADC | Reserved for divided protected-pack voltage |
| 10 | LED data | Through AHCT buffer and 33 Ω output damping |
| 18/19 | USB Serial/JTAG | Reserved; not used for buttons/LED |
| 2/8/9 | Strapping | Reserved; not used for buttons/LED |
| EN | Reset/enable | External pull-up/RC and reset switch required |
src/main.cpp)Cpp
#include <Arduino.h> #include <FastLED.h> #include <NimBLEDevice.h> constexpr uint8_t LED_PIN=10, NUM_LEDS=100; constexpr uint8_t BTN[6]={0,1,3,4,5,6}; constexpr uint8_t BRIGHTNESS_CAP=85; // 85/255 * 100 * 60mA ≈ 2.0A worst-case RGB white; conservative below 4A electrical limit constexpr uint32_t DEBOUNCE_MS=25; CRGB leds[NUM_LEDS]; bool stable[6]={1,1,1,1,1,1}, lastRaw[6]={1,1,1,1,1,1}; uint32_t changedAt[6]={0}; void setup(){ Serial.begin(115200); WiFi.mode(WIFI_OFF); // include WiFi.h if Wi-Fi API is enabled in selected Arduino core btStop(); // reset radio state before NimBLE init if supported by core for(uint8_t p:BTN) pinMode(p,INPUT); // external pull-ups fitted FastLED.addLeds<WS2812B,LED_PIN,GRB>(leds,NUM_LEDS); FastLED.setBrightness(BRIGHTNESS_CAP); FastLED.setMaxPowerInVoltsAndMilliamps(5,4000); // aggregate 20 W cap NimBLEDevice::init("LED-Tube-C3"); auto *server=NimBLEDevice::createServer(); auto *svc=server->createService("12345678-1234-1234-1234-1234567890ab"); svc->createCharacteristic("12345678-1234-1234-1234-1234567890ac",NIMBLE_PROPERTY::READ|NIMBLE_PROPERTY::WRITE)->setValue("ready"); svc->start(); NimBLEDevice::getAdvertising()->addServiceUUID(svc->getUUID()); NimBLEDevice::startAdvertising(); fill_solid(leds,NUM_LEDS,CRGB::Black); FastLED.show(); } void loop(){ uint32_t now=millis(); for(int i=0;i<6;i++){ bool r=digitalRead(BTN[i]); if(r!=lastRaw[i]){lastRaw[i]=r;changedAt[i]=now;} if((now-changedAt[i])>=DEBOUNCE_MS && stable[i]!=r){stable[i]=r;if(!r){leds[i]=CRGB::White;FastLED.show();}} } delay(1); }
Depending on Arduino-ESP32 release, include `` and omitbtStop()if it conflicts with NimBLE startup. The hardware shutdown/charge inhibit must not depend on this firmware.
Toolchain
Final MCU Pin Mapping
Compilable Starter (`src/main.cpp`)
Startup Sequence