Skip to main content

Overview

BaseChannel is the main LED controller for AutoLight V3, providing 16+ lighting sequence modes, PCF8574 I2C expander management, multi-modal button systems, and integrated web server control.

Quick Start

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

BaseChannel led;
BaseConfig config;

void setup() {
  config.setDynamicConfig(12, 2);  // 12 channels, 2 PCF8574s
  led.attachConfig(config.getConfigData());
  led.initialize();
  led.setButtonMode(BUTTON_MODE_1BUTTON);
}

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

Constructor

BaseChannel
constructor
Create BaseChannel instance

Initialization

initialize
bool
Initialize LED control system
attachConfig
void
Attach configuration data
attachInterrupt
void
Attach button interrupt handler
enableI2CConfig
void
Enable I2C configuration mode

Sequence Control

runAutoLight
void
Main execution loop for LED sequences
changeMode
void
Change to next sequence mode
changeModeApp
void
Change to specific sequence mode (for web API)
nextMode
void
Go to next sequence mode
previousMode
void
Go to previous sequence mode
onMode
void
Turn system on (mode 1)
offMode
void
Turn system off (mode 0)

Sequence Mapping

Filter and reorder available sequences:
led.enableSequenceMapping(true);
led.setActiveSequences(5, 2, 5, 7, 10, 12);  // Only these modes
led.printSequenceMapping();  // Debug output
enableSequenceMapping
void
Enable sequence filtering
setActiveSequences
void
Set active sequence list
reorderActiveSequences
void
Reorder active sequences
printSequenceMapping
void
Print current sequence mapping to Serial
getActiveMappingString
String
Get mapping as formatted string

Button Control

setButtonMode
void
Set button interaction mode
setButtonConfig
void
Set button configuration
singleButtonCycle
void
Handle single button cycle (1-button mode)
toggleOnOff
void
Toggle between on and off states
smartButtonPress
void
Execute smart button action

Web Server Integration

enableWebServer
void
Enable REST API web server
enableWebServerManual
void
Enable web server without auto task (manual control)
getAPIManager
APIServerManager*
Get API server manager instance

State Management

isChangeMode
volatile bool
Check if mode changed
isOn
volatile bool
Check if system is on
getSequenceIndex
volatile uint32_t
Get current sequence index
getDelayTime
volatile uint32_t
Get current timing delay
getChannelData
ChannelData
Get complete channel state data

LED Control

on
void
Turn all LEDs on
off
void
Turn all LEDs off
forceOff
void
Force all LEDs off immediately
set
void
Set specific LED state
getLEDState
bool
Get LED state
getTotalLEDs
uint8_t
Get total number of LED channels

Configuration

setInitDelay
void
Set initial delay time
setInitSequence
void
Set initial sequence
setTotalSequence
void
Set total number of sequences
reverse
void
Set reverse mode
setParamCallback
void
Set parameter change callback

Utility Functions

sleep
void
Non-blocking delay
isReady
bool
Check if system is ready
debug
void
Print debug information to Serial

Built-in Sequence Modes

BaseChannel includes 16 pre-programmed lighting sequences:
ModeNameDescription
0OFFAll LEDs off
1ONAll LEDs on
2Blink AllSimultaneous blink
3Fill Two PointFill from center outward
4Fill RightFill from right to left
5Fill InFill from both ends inward
6Blink One by OneSequential blink
7Blink Two FillTwo LEDs blink while filling
8Snake and ReverseSnake pattern with reverse
9RandomRandom LED activation
10WaveWave propagation effect
11ComplexMulti-pattern coordination
12Pattern MatrixAdvanced matrix patterns
13Blink PatternCustom blink patterns
14Advanced PatternComplex combinations
15All SequencesRotation through all modes

ChannelData Structure

class ChannelData {
public:
    volatile uint32_t delay_time_;           // Current timing delay
    volatile uint32_t sequence_index_;       // Current sequence
    volatile uint32_t sequence_index_apps_;  // API sequence index
    volatile uint32_t last_active_sequence_; // Last active sequence
    volatile bool is_reverse_;               // Reverse mode flag
    volatile bool is_mode_changed_;          // Mode changed flag
    volatile bool is_mode_changed_apps_;     // API mode change flag
    volatile bool is_on_;                    // System on/off state
};

Button Modes

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

Example: Complete Setup

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

BaseChannel led;
BaseConfig config;
ButtonInterrupt button;

void sequenceCallback(uint32_t seq) {
  Serial.printf("Running sequence: %d\n", seq);
}

void setup() {
  Serial.begin(115200);
  
  // Dynamic PCF configuration
  config.setDynamicConfig(24, 3);  // 24 channels, 3 PCFs
  led.attachConfig(config.getConfigData());
  
  // Button setup
  led.setButtonMode(BUTTON_MODE_1BUTTON);
  
  // Sequence filtering
  led.enableSequenceMapping(true);
  led.setActiveSequences(5, 2, 5, 7, 10, 12);
  
  // Initialize
  led.initialize();
  led.setInitDelay(50);
  
  // Enable web server
  led.enableWebServer(true);
  
  Serial.println("AutoLight V3 ready!");
}

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

Platform Support

BaseChannel requires ESP32 due to FreeRTOS task requirements and memory needs. ESP8266 support is limited.

ESP32

Full support - recommended platform

Build docs developers (and LLMs) love