Skip to main content

Overview

AutoLight V3 is the current generation of the AutoLight ecosystem, providing comprehensive LED matrix control with dynamic PCF8574 I2C expander management, multi-modal button systems, integrated REST API web server, and CLI interface. Platform: ESP32 (primary), ESP8266 (limited support)
Architecture: Modular component design with singleton configuration management
Key Features: 16 LED sequence modes, dynamic PCF distribution, hardware I2C expansion, FreeRTOS task management

Core Architecture

Component Organization

Firmware/
├── Core/                          # Core system components
│   ├── Channel/                   # LED control system
│   │   ├── BaseChannel/           # Main LED controller
│   │   │   ├── BaseChannel.h/.cpp      # LED management (33KB)
│   │   │   └── BaseChannelSequence.cpp # 16 sequences (107KB)
│   │   └── Indicator.h/.cpp       # Status indicators
│   ├── Config/                    # Configuration management
│   │   ├── BaseConfig.h/.cpp      # Dynamic PCF distribution
│   │   ├── ConfigManager.h/.cpp   # Singleton manager
│   │   └── ConfigData.h           # Data structures
│   ├── Interaction/               # User interaction
│   │   ├── ButtonInterrupt.h/.cpp # Multi-modal buttons
│   │   └── SerialCommander.h/.cpp # CLI interface
│   ├── Cores/                     # System services
│   │   └── Task.h/.cpp            # FreeRTOS wrapper
│   └── Common/
│       └── Constants.h            # System constants
└── API/                           # REST API server
    └── APIServerManager.h/.cpp    # Web server (port 8000)

Key Manager Classes

BaseChannel - LED Controller

Main LED controller with 16+ sequence modes, PCF8574 dynamic distribution support, and multi-modal button integration. Location: Core/Channel/BaseChannel/BaseChannel.h
#define ENABLE_ADDONS_AUTOLIGHT_V3
#include "Kinematrix.h"
using namespace AutoLight;

BaseChannel led;
BaseConfig config;

void setup() {
    Serial.begin(115200);

    // Dynamic PCF configuration
    config.setDynamicConfig(12, 2);  // 12 channels, 2 PCF8574s
    led.attachConfig(config.getConfigData());
    led.initialize();

    // Enable integrated systems
    led.enableWebServer(true);       // REST API on port 8000
    led.setButtonMode(BUTTON_MODE_1BUTTON);
}

void loop() {
    led.runAutoLight();
    delay(10);
}

ConfigManager - Singleton Configuration

Thread-safe configuration manager with EEPROM persistence. Location: Core/Config/ConfigManager.h
BaseConfig config;

// Dynamic PCF configuration
config.setDynamicConfig(24, 3);  // 24 channels, 3 PCF8574s

// Distribution strategies
config.setDynamicConfig(24, 3, DISTRIBUTE_BALANCED);
config.setDynamicConfig(24, 3, DISTRIBUTE_SEQUENTIAL);
config.setDynamicConfig(24, 3, DISTRIBUTE_OPTIMIZED);

// Attach to LED controller
led.attachConfig(config.getConfigData());

APIServerManager - Web Server

Integrated AsyncWebServer on port 8000 with RESTful API endpoints. Location: API/APIServerManager.h
void setup() {
    // Enable web server with automatic FreeRTOS task
    led.enableWebServer(true);
    
    // Or manual mode
    led.enableWebServerManual();
}
Server automatically handles:
  • WiFi AP/STA mode switching
  • mDNS service (als.local)
  • SD card static file serving
  • REST API endpoints
  • CORS headers

SerialCommander - CLI Interface

Full CLI interface at 115200 baud with multi-level access control. Location: Core/Interaction/SerialCommander.h
SerialCommander cmd;

void setup() {
    Serial.begin(115200);
    cmd.init(led, config, button);
}

void loop() {
    cmd.process();  // Handle serial commands
    led.runAutoLight();
    delay(10);
}

Core Data Structures

PCF Distribution System

struct PCFDistribution {
    uint8_t address;         // I2C address (0x20-0x27)
    uint8_t used_pins;       // Allocated pins (1-8)
    uint8_t start_channel;   // Starting channel number
    uint8_t pin_offset;      // Pin offset within PCF
    bool is_active;          // PCF status
};

typedef enum {
    DISTRIBUTE_BALANCED = 0,    // Even distribution across PCFs
    DISTRIBUTE_SEQUENTIAL = 1,  // Fill PCFs sequentially
    DISTRIBUTE_OPTIMIZED = 2,   // Minimize PCF usage
    DISTRIBUTE_CUSTOM = 3       // Manual configuration
} distribution_strategy_t;

Multi-Modal Button System

typedef enum {
    BUTTON_MODE_4BUTTON = 0,  // ON/OFF/NEXT/PREV (legacy)
    BUTTON_MODE_1BUTTON = 1,  // Single cycle: OFF→ON→Mode2-15→OFF
    BUTTON_MODE_2BUTTON = 2,  // Toggle + Next
    BUTTON_MODE_3BUTTON = 3,  // Separate ON/OFF/Next
    BUTTON_MODE_CUSTOM = 99   // User-defined handlers
} button_mode_t;

Configuration Container

typedef struct {
    ConfigHeader header;     // Channel count, pin pointers, I2C addresses
    ConfigTable table;       // Address and version tables
} ConfigData;

Dynamic PCF Distribution

Distribution Strategies

Even distribution across all PCFs
config.setDynamicConfig(24, 3, DISTRIBUTE_BALANCED);
// Result: 8 channels per PCF
// PCF1: channels 0-7
// PCF2: channels 8-15
// PCF3: channels 16-23
Best for: Uniform load distribution, balanced power consumption

Multi-Modal Button System

Flexible button interaction supporting 1-4 buttons with 5 different modes:
Traditional 4-button control
led.setButtonMode(BUTTON_MODE_4BUTTON);
  • Button 0: Turn ON
  • Button 1: Turn OFF
  • Button 2: Next sequence
  • Button 3: Previous sequence
Single button cycles through all modes
led.setButtonMode(BUTTON_MODE_1BUTTON);
Cycle: OFF → ON → Mode 2 → Mode 3 → … → Mode 15 → OFF
Toggle + Next pattern
led.setButtonMode(BUTTON_MODE_2BUTTON);
  • Button 0: Toggle ON/OFF
  • Button 1: Next sequence
Separate ON/OFF/Next controls
led.setButtonMode(BUTTON_MODE_3BUTTON);
  • Button 0: Turn ON
  • Button 1: Turn OFF
  • Button 2: Next sequence
User-defined button handlers
led.setButtonMode(BUTTON_MODE_CUSTOM);

// Define custom handlers
void customButton0() {
    // Your custom logic
}

LED Sequence System

Sequence Modes (0-15)

All sequence implementations are in BaseChannelSequence.cpp (107KB).
void BaseChannel::taskSequence0Off() {
    off();  // All channels LOW
}

Sequence Mapping Feature

Filter available sequences to a subset:
// Enable sequence mapping
led.enableSequenceMapping(true);

// Set active sequences (only modes 2, 5, 7, 10, 12 accessible)
led.setActiveSequences(5, 2, 5, 7, 10, 12);

// Reorder active sequences
uint8_t new_order[] = {12, 10, 7, 5, 2};
led.reorderActiveSequences(new_order, 5);

// Debug output
led.printSequenceMapping();

SerialCommander CLI

Available at 115200 baud via serial monitor.

WiFi Management

wifi ap <ssid> <password>     # Start access point mode
wifi sta <ssid> <password>    # Connect to WiFi network
wifi scan                     # Scan available networks
wifi status                   # Show connection status
wifi restart                  # Restart WiFi AP
wifi reset                    # Reset to default credentials
wifi clients                  # Show connected clients

LED Control

led on                        # Turn all LEDs on
led off                       # Turn all LEDs off
led test <channel>            # Test specific channel
led status                    # Show all channel states
led next                      # Next sequence mode
led prev                      # Previous sequence mode

Sequence Management

sequence set <mode>           # Set LED sequence (0-15)
sequence map enable           # Enable sequence filtering
sequence map set 2,5,7,10     # Set active sequences
sequence map show             # Display current mapping
sequence delay <ms>           # Set timing delay (30-300ms)

PCF8574 I2C Management

pcf scan                      # Scan I2C bus for devices
pcf test <address>            # Test PCF at hex address (e.g., 0x27)
pcf status                    # Show all PCF states
pcf reset <address>           # Reset specific PCF
pcf write <address> <data>    # Write byte to PCF
pcf read <address>            # Read byte from PCF

Button Configuration

button mode <0-3>             # Set button mode
button test <index>           # Test button action
button config                 # Show current config

Hardware Configuration

PCF8574 I2C Expanders

  • Supported: Up to 8 PCF8574 units (addresses 0x20-0x27)
  • Channels: 1-64 total LED channels with dynamic distribution
  • I2C Bus: Hardware I2C (ESP32 default SDA/SCL pins)

Status Indicators

Defined in Constants.h:
const int RGB_LED_RED = 14;
const int RGB_LED_GREEN = 12;
const int RGB_LED_BLUE = 13;
const int BUZZER_PIN = 15;

System Limits

const int MAXNUM_CHANNEL = 64;              // Maximum LED channels
const int MAXNUM_IO_EXPANDER = 8;           // Maximum PCF8574 units
const int MAXNUM_TOTAL_TASK_SEQUENCE = 16;  // Total sequence modes
const int DEFAULT_DELAY_TIME = 50;          // Default timing (ms)

Development Mode Example

#define ENABLE_ADDONS_AUTOLIGHT_V3
#include "Kinematrix.h"
using namespace AutoLight;

BaseChannel led;
BaseConfig config;
SerialCommander cmd;

void setup() {
    Serial.begin(115200);

    // SerialCommander for CLI debugging
    cmd.init(led, config, button);

    // Advanced PCF configuration
    config.setDistributionStrategy(DISTRIBUTE_OPTIMIZED);
    config.setDynamicConfig(24, 3);  // 24 channels across 3 PCFs

    // Sequence mapping (filter available modes)
    led.enableSequenceMapping(true);
    led.setActiveSequences(5, 2, 5, 7, 10, 12);  // Only modes 2,5,7,10,12

    // Multi-modal button
    led.setButtonMode(BUTTON_MODE_1BUTTON);

    led.initialize();
    led.enableWebServer(true);
}

void loop() {
    led.runAutoLight();
    cmd.process();  // Handle serial commands
    delay(10);
}

Memory Footprint

  • Minimal Configuration: ~100KB flash, ~20KB RAM (basic LED control)
  • Full Configuration: ~300KB flash, ~50KB RAM (all features enabled)
  • BaseChannelSequence.cpp: ~107KB (16 sequence implementations)

Troubleshooting

# Use SerialCommander to scan I2C bus
pcf scan

# Test specific PCF address
pcf test 0x27
Verify:
  • Physical I2C connections (SDA/SCL)
  • Pullup resistors (4.7kΩ recommended)
  • PCF8574 addresses (check A0/A1/A2 pins)
Check Serial output for WiFi initialization:
✓ AP Started: 'AutoLight-XXXX'
  IP: 192.168.4.1
  Security: WPA2
  Web Interface: http://192.168.4.1
  mDNS: http://als.local
Default:
  • AP IP: 192.168.4.1
  • Web Port: 80
  • API Port: 8000
  • mDNS: als.local
# Test button configuration
button config

# Test specific button
button test 0
Verify:
  • GPIO pin configuration
  • Button wiring (pullup/pulldown)
  • Button mode setting
Ensure AutoLight V3 is enabled:
#define ENABLE_ADDONS_AUTOLIGHT_V3
#include "Kinematrix.h"
Check platformio.ini includes:
  • AsyncTCP library
  • ESPAsyncWebServer
  • PCF8574 library

Next Steps

Web Client

Explore the Next.js web interface for device control

Pattern Builder

Create custom LED sequences visually

REST API

Complete API reference for integration

Back to Overview

Return to AutoLight overview

Build docs developers (and LLMs) love