# NeoPattern Service for Spore Framework This example demonstrates how to integrate a NeoPixel pattern service with the Spore framework. It provides a comprehensive LED strip control system with multiple animation patterns and REST API endpoints. ## Features - **Multiple Animation Patterns**: Rainbow cycle, theater chase, color wipe, scanner, fade, and fire effects - **REST API Control**: Full HTTP API for pattern control and configuration - **Real-time Updates**: Smooth pattern transitions and real-time parameter changes - **State Management**: Persistent state with JSON serialization - **Spore Integration**: Built on the Spore framework for networking and task management ## Hardware Requirements - ESP32 or compatible microcontroller - NeoPixel LED strip (WS2812B or compatible) - Appropriate power supply for your LED strip ## Configuration Edit `NeoPixelConfig.h` to configure your setup: ```cpp static constexpr int DEFAULT_PIN = 2; static constexpr int DEFAULT_LENGTH = 8; static constexpr int DEFAULT_BRIGHTNESS = 100; static constexpr int DEFAULT_UPDATE_INTERVAL = 100; static constexpr int DEFAULT_COLOR = 0xFF0000; // Red ``` ## API Endpoints ### Status Information - `GET /api/neopattern/status` - Get current status and configuration - `GET /api/neopattern/patterns` - List available patterns ### Pattern Control - `POST /api/neopattern` - Control pattern parameters - `pattern`: Pattern name (none, rainbow_cycle, theater_chase, color_wipe, scanner, fade, fire) - `color`: Primary color (hex string like "#FF0000" or "0xFF0000") - `color2`: Secondary color for two-color patterns - `brightness`: Brightness level (0-255) - `total_steps`: Number of steps for patterns - `direction`: Pattern direction (forward, reverse) - `interval`: Update interval in milliseconds ### State Management - `POST /api/neopattern/state` - Set complete state via JSON ## Example API Usage ### Set a rainbow cycle pattern ```bash curl -X POST http://esp32-ip/api/neopattern \ -H "Content-Type: application/x-www-form-urlencoded" \ -d "pattern=rainbow_cycle&interval=50" ``` ### Set custom colors for theater chase ```bash curl -X POST http://esp32-ip/api/neopattern \ -H "Content-Type: application/x-www-form-urlencoded" \ -d "pattern=theater_chase&color=0xFF0000&color2=0x0000FF&brightness=150" ``` ### Set complete state via JSON ```bash curl -X POST http://esp32-ip/api/neopattern/state \ -H "Content-Type: application/json" \ -d '{ "pattern": 3, "color": 16711680, "color2": 255, "totalSteps": 32, "brightness": 128 }' ``` ## Available Patterns 1. **none** - Static color display 2. **rainbow_cycle** - Smooth rainbow cycling 3. **theater_chase** - Moving dots with two colors 4. **color_wipe** - Progressive color filling 5. **scanner** - Scanning light effect 6. **fade** - Smooth color transition 7. **fire** - Fire simulation effect ## Building and Flashing 1. Install PlatformIO 2. Configure your `platformio.ini` to include the Spore framework 3. Build and upload: ```bash pio run -t upload ``` ## Integration with Spore Framework This service integrates with the Spore framework by: - Extending the `Service` base class - Using `TaskManager` for pattern updates - Registering REST API endpoints with `ApiServer` - Following Spore's logging and configuration patterns The service automatically registers itself with the Spore framework and provides all functionality through the standard Spore API infrastructure. ## Customization To add new patterns: 1. Add the pattern enum to `NeoPatternService.h` 2. Implement the pattern logic in `NeoPattern.cpp` 3. Add the pattern updater to `registerPatterns()` in `NeoPatternService.cpp` 4. Update the pattern mapping in `nameToPatternMap` ## Troubleshooting - **LEDs not lighting**: Check wiring and power supply - **Patterns not updating**: Verify the update interval and task registration - **API not responding**: Check network configuration and Spore framework setup - **Memory issues**: Reduce LED count or pattern complexity ## Dependencies - Spore Framework - Adafruit NeoPixel library - ArduinoJson - ESP32 Arduino Core