
PCCWDPLUSREV2
nunogbento/HOMEKIT-DOMOTICS
Personal collection of home-automation hardware and firmware around Apple HomeKit, spanning multiple generations of boards and HomeKit integration techniques.

A single-channel PWM LED dimmer controlled via a rotary encoder. Powered by the CH32V003 microcontroller with a self-contained firmware based on ch32fun.
LightBox is an open-source printed circuit board by ghostinkoma, from the ghostinkoma/Ch32LightBox repository on GitHub. It is a 2-layer board with 9 parts on 12 nets, routed with 103 tracks and 6 vias.
It is built around the FDS5680 and SK6812. Its parts include 3 resistors, 2 diodes, 1 IC, 1 transistor and 1 connector. It belongs with the RISC-V boards of this library.
English · 日本語
Status: ✅ Hardware Verified & Operational (as of 2026-09, no issues) — All functions confirmed on both custom PCB (KiCad) and universal breadboard/perfboard. Verified nightlight, brightness control, soft start/off, 12-hour endurance test, and virtually zero heat generation with a ~1A LED. Enclosed and currently in actual use inside a 3D-printed case designed in Fusion 360.
License: Non-Commercial (CC BY-NC 4.0 compliant / Attribution required, modification allowed for non-commercial use, provided AS-IS without warranty) → LICENSE
A single-channel PWM LED dimmer controlled via a rotary encoder. Powered by the CH32V003 microcontroller with a self-contained firmware based on ch32fun.
To prioritize reproducing brightness as perceived by the human eye, the PWM duty cycle is generated using the CIE 1931 L* (lightness) curve. One click produces a "perceptually equal" shift in brightness—slower changes at low levels and sharper changes at high levels—achieving a balanced response for human vision.
| Feature | Description |
|---|---|
| CIE L* Dimming | Perceptually uniform brightness. 64 total steps, LUT generated at startup, runtime lookup via integer table. |
| 16-bit PWM | TIM2, default 4095 steps / ~12 kHz. Adjustable resolution and frequency in config.h. |
| Debouncing | Full-step state machine (Ben Buxton) + direction reversal lockout (default 5 ms). No simple delays used. |
| Fast-turn Snap | Immediately sets duty to 100% or 0% if turned in the same direction $j$ times within $n$ ms. |
| CW/CCW Support | Swap rotation direction with a single line in config.h. |
| Brightness Memory | Flash wear leveling (dedicated 2 KB area, saved after 5 sec, ~1024x lifespan extension, saves ON/OFF state). |
| Overheat Failsafe (Default OFF) | Forcefully shuts off main PWM (MOSFET) when overheated → resumes when cooled down. Thermal throttles to $j$% after $n$ cycles. Die estimation disabled due to false triggers (TEMP_PROTECT_ENABLE 0); enable only when using an external NTC sensor. |
| Watchdog | IWDG. Automatically resets on system freeze for self-recovery. |
| EMI Mitigation | Configurable PWM slew rate (GPIO speed) + spread spectrum (period dithering, brightness invariant). |
| Nightlight (WS2812 or single LED) | When completely dark: ①WS2812/SK6812 breathes light↔dark on the CIE curve (RGB/RGBW, color order, max color), or ②a single-color LED blinks x ms every n s. |
| Deep Low-Power (experimental) | Optional battery mode (LOW_POWER_MODE): single-LED nightlight with the MCU in Standby between blinks (AWU periodic wake, push-switch EXTI wake). Default off; see CONFIG_REFERENCE. |
| Soft Start | Smoothly fades in/out to target brightness on power ON/OFF based on CIE curve (duration set in config, disabled if 0, max 65535 ms). |
| Push Switch | Short press toggles ON/OFF (time-based debouncing; smoothly tracks re-triggering during active fades). |
All configuration options are centralized in source/config.h (see CONFIG_REFERENCE.md for details).
Detailed specifications are in SPEC.md, design decisions are in DESIGN.md, and battery / low-power and LED-driver notes are in POWER_AND_DRIVER.md.
| Pin | Signal | Function |
|---|---|---|
| PA1 | ENC_A | Encoder Phase A (Internal pull-up, Common=GND) |
| PC1 | ENC_B | Encoder Phase B (Internal pull-up, Common=GND) |
| PA2 | ENC_SW | Push Switch (Internal pull-up, Active Low) |
| PC2 | PWM | Main LED Output (default PWM_PIN=PC2 → TIM2_CH2 remap1) |
| PC4 | (Selectable) | WS2812 Nightlight / External Temp Sensor / Warning LED (Mutually exclusive, choose one) |
| PD1 | SWIO | Programming / debugprintf (Reserved) |
Feature ↔ pin assignment is done entirely in
config.h(one pin macro per feature:PWM_PIN,ENC_*_PIN,WS_DIN_PIN,TEMP_SENSE_PIN,WARN_LED_PIN).source/pins.hvalidates capabilities (PWM-/ADC-capable pins) and pin conflicts at compile time, and the LightBox Studio config editor mirrors the same checks. See the “Feature ↔ Pin Assignment” section of CONFIG_REFERENCE.md.
Temperature protection is OFF by default (die estimation rejected due to false shutdowns). Watchdog and EMI mitigations require no external pins, allowing PC4—the only remaining free pin on SOP8—to be used for the nightlight. If an external physical temperature sensor or warning LED is needed, allocate PC4 accordingly (mutually exclusive with the nightlight). To use more features simultaneously, switch to TSSOP20/QFN (F4P6) and assign individual pins in
config.h.
PC2 → [Resistor] → LED → GND (Strictly respect $I_{\max} \approx 8\text{ mA}$ per pin).TEMP_PROTECT_ENABLE 0). If physical thermal protection is strictly required, attach a thermal-coupled NTC on the MOSFET to an ADC pin and run with TEMP_PROTECT_ENABLE=1 + TEMP_SOURCE=EXTERNAL. See SPEC.md for details.Dependencies: ch32fun, RISC-V GCC (xpack riscv-none-elf recommended for rv32ec libgcc), WCH-LinkE.
cd source
make lightbox.bin CH32FUN=/path/to/ch32fun/ch32fun # Build only
make CH32FUN=/path/to/ch32fun/ch32fun # Build -> FlashBuild memory footprints (Default config, all features ON, DEBUG_LOG=0): Flash 8200 B / 16 KB (50%), RAM 184 B (9%).
Stripped footprint: Core only ~3 KB, + Nightlight ~3.6 KB. DEBUG_LOG=1 adds ~1 KB.
Set
DEBUG_LOGto 1 only during development.printfis blocking and can stall if an SWD host is disconnected, causing dropped inputs in hot loops. Defaults to 0, which unlinks the printf infrastructure entirely.
See PLATFORMIO.md (platformio.ini included).
Note: The PlatformIO build has not been verified in this environment. The verified build method is the Makefile above.
For a GUI-only workflow (config.h editing → compile → flash from a single menu), use the Java toolset in tools/LightBoxStudio/. It downloads a self-contained toolchain on first run, so no command line or VS Code is required. See the LightBox Studio README for details.
LightBox/
├─ source/ Firmware source files
│ ├─ lightbox.c Main application (main / encoder / PWM)
│ ├─ config.h Centralized configuration (edit parameters here)
│ ├─ cie.h CIE L* curve library (shared by main PWM & nightlight)
│ ├─ store.h Non-volatile brightness storage (wear leveling)
│ ├─ temp.h Temperature reading (external NTC, default OFF)
│ ├─ wdt.h Watchdog timer (IWDG)
│ ├─ nightlight.h WS2812/SK6812 nightlight driver
│ ├─ funconfig.h ch32fun environment configuration
│ └─ Makefile
├─ documents/ SPEC.md / CONFIG_REFERENCE.md / HARDWARE.md / DESIGN.md / POWER_AND_DRIVER.md (+ *_JP.md)
├─ tools/ LightBoxStudio/ = GUI toolset (config edit → build → flash, no VS Code)
├─ ldscript/ Linker script for PlatformIO (lightbox_ch32v003.ld)
├─ PCB/ KiCad board files (LightBox/ = Schematic/PCB; AertWork.png; KiCad/ = FDS5680 lib)
├─ platformio.ini / PLATFORMIO.md
├─ 3D_Models/ Enclosure (Fusion 360 design / STL files, 3D printed)
└─ LICENSE Non-commercial license (CC BY-NC 4.0 compliant)Designed in Fusion 360 → 3D printed. The board is assembled inside and currently in operational use (STL files available in 3D_Models/).
PCB layout, schematic, and artwork (with pin headers) completed → PCB/LightBox/ (KiCad).
Pin routing matches firmware exactly. Details, BOM, and J1 pinout are in HARDWARE.md.
This project (original parts of firmware, PCB, enclosure, and documentation created by ghostinkoma) is licensed under a Non-Commercial License (Creative Commons Attribution-NonCommercial 4.0 International / CC BY-NC 4.0 compliant). See LICENSE for full details.
Note: Bundled/dependent third-party code (e.g., ch32fun) remains under its respective original licenses (MIT-x11 / NewBSD).
| Qty | Value | Footprint | References |
|---|---|---|---|
| 2 | 100 | Resistor_SMD:R_0201_0603Metric | R1, R3 |
| 1 | 10K | Resistor_SMD:R_0201_0603Metric | R2 |
| 1 | CH32V003JxMx | Package_SO:SOP-8_3.9x4.9mm_P1.27mm | U1 |
| 1 | Conn_01x09_Pin | Connector_PinHeader_2.54mm:PinHeader_1x09_P2.54mm_Vertical | J1 |
| 1 | FDS5680 | Package_SO:SOIC-8-1EP_3.9x4.9mm_P1.27mm_EP2.29x3mm | Q1 |
| 1 | LED | LED_THT:LED_D3.0mm | D2 |
| 1 | RotaryEncoder_Switch | Rotary_Encoder:RotaryEncoder_Alps_EC11E-Switch_Vertical_H20mm | SW2 |
| 1 | SK6812 | LED_SMD:LED_SK6812_PLCC4_5.0x5.0mm_P3.2mm | D1 |
9 parts, built around the FDS5680 and SK6812. The full list of its parts is on this page, with links to each part's symbol and footprint where PCBKit's library has them.
From the ghostinkoma/Ch32LightBox repository on GitHub, at the commit this page was made from: the board is PCB/LightBox/LightBox.kicad_pcb and its schematic PCB/LightBox/LightBox.kicad_sch. PCBKit opens the board in the browser, with nothing to install.
Its repository states no licence, so its author keeps all rights: ask ghostinkoma before reusing the design.

nunogbento/HOMEKIT-DOMOTICS
Personal collection of home-automation hardware and firmware around Apple HomeKit, spanning multiple generations of boards and HomeKit integration techniques.
hackclub/OnBoard
💡 Join 1,000 teenagers and make your first PCB with a $100 grant!

conol-ai/openmicrokbd
Open-source recreation of OpenAI's Codex Micro macropad — PCB written in CoHDL, an AI-native hardware description language. Rust firmware (embassy) + companion app (makepad). MIT licensed. https://openmicrokbd.org



cormoran/dya-dash-keyboard
DYA Dash portable wireless split keyboard with 25mm trackball

w4ilun/neofighter
A MIDI controller using arcade buttons with RGB lighting effects

miliar/saiboard
An open-source, wooden electronic Go board that integrates with KataGo.