/** * @file LEDController.h * @brief WS2812 LED Controller for lighting effects * * Controls WS2812 addressable LEDs for headlights, taillights, and other effects. * Supports direction-based lighting and function-controlled effects. */ #ifndef LED_CONTROLLER_H #define LED_CONTROLLER_H #include #include #define MAX_LEDS 16 #define DEFAULT_BRIGHTNESS 128 enum LightMode { LIGHT_OFF = 0, LIGHT_ON = 1, LIGHT_BLINK = 2, LIGHT_PULSE = 3, LIGHT_DIRECTION_FRONT = 4, // On when moving forward LIGHT_DIRECTION_REAR = 5 // On when moving backward }; class LEDController { public: LEDController(); /** * @brief Initialize LED controller * @param ledPin GPIO pin for WS2812 data * @param numLeds Number of LEDs in the strip * @return true if successful */ bool begin(uint8_t ledPin, uint8_t numLeds); /** * @brief Update LED states (call regularly from loop) */ void update(); /** * @brief Set LED mode for a specific LED * @param ledIndex LED index (0-based) * @param mode Light mode */ void setLEDMode(uint8_t ledIndex, LightMode mode); /** * @brief Set LED color * @param ledIndex LED index * @param r Red (0-255) * @param g Green (0-255) * @param b Blue (0-255) */ void setLEDColor(uint8_t ledIndex, uint8_t r, uint8_t g, uint8_t b); /** * @brief Set global brightness * @param brightness Brightness (0-255) */ void setBrightness(uint8_t brightness); /** * @brief Set direction for directional lights * @param forward true = forward, false = reverse */ void setDirection(bool forward); /** * @brief Map function to LED * @param functionNum Function number (0-28) * @param ledIndex LED index * @param mode Light mode when function is active */ void mapFunctionToLED(uint8_t functionNum, uint8_t ledIndex, LightMode mode); /** * @brief Update function state * @param functionNum Function number * @param state Function state (true = on) */ void setFunctionState(uint8_t functionNum, bool state); private: CRGB leds[MAX_LEDS]; uint8_t numLEDs; uint8_t dataPin; bool direction; struct LEDConfig { LightMode mode; CRGB color; uint8_t mappedFunction; // 255 = no function mapping }; LEDConfig ledConfig[MAX_LEDS]; bool functionStates[29]; // F0-F28 unsigned long lastUpdate; uint16_t effectCounter; void updateLED(uint8_t ledIndex); }; #endif // LED_CONTROLLER_H