Moving Rainbow MicroPython Generator
Overview
The moving-rainbow skill generates MicroPython programs for the Moving Rainbow educational project using Raspberry Pi Pico with NeoPixel LED strips and button controls. It creates programs for LED animations that are both educational and visually engaging.
Purpose
This skill helps educators and students create MicroPython programs for LED strip animations on Raspberry Pi Pico microcontrollers, focusing on educational patterns and interactive control through physical buttons.
Hardware Configuration
Default hardware setup: - Microcontroller: Raspberry Pi Pico (RP2040) - LED Strip: 30-pixel NeoPixel/WS2812B addressable LED strip connected to GPIO pin 0 - Input Controls: Two momentary push buttons - Button 1: GPIO pin 14 - Button 2: GPIO pin 15 - Built-in LED: GPIO pin 25 (status indication)
Configuration values stored in config.py module.
Key Features
- Educational Code Patterns: Clear, well-commented code for learning
- Interactive Controls: Button-based mode switching and parameter adjustment
- Animation Library: Pre-built patterns (rainbow, comet, sparkle, etc.)
- Color Management: Standard color wheel function for smooth transitions
- Modular Design: Reusable functions for common operations
When to Use
Use this skill when users ask to: - Create LED animations for Raspberry Pi Pico - Work with NeoPixel/WS2812B addressable LED strips - Build educational examples for Moving Rainbow project - Implement button-controlled LED effects - Generate MicroPython code for LED strip projects
Common Animation Patterns
Moving Dot
Single LED moving along the strip with configurable color and speed
Rainbow Cycle
Full rainbow pattern that rotates through the strip
Comet Tail
LED with fading tail effect simulating a comet
Color Wipe
Progressive fill of strip with a color
Random Effects
Random pixel positions and colors with sparkle effects
Candle Flicker
Simulates flickering candle flame effect
Code Structure
Basic Program Template
1 2 3 4 5 6 7 8 9 10 11 12 13 | |
Essential Components
- Imports: machine, neopixel, utime, config
- Strip Initialization: NeoPixel object creation
- Main Loop: while True loop for continuous animations
- Color Format: RGB tuples (red, green, blue) with values 0-255
Color Wheel Function
Standard function for smooth rainbow transitions:
1 2 3 4 5 6 7 8 9 10 | |
Button Integration
Interactive programs with button controls:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | |
Multi-Mode Programs
Programs with multiple animation modes switchable via buttons:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | |
Standard Color Definitions
Pre-defined color constants:
1 2 3 4 5 6 7 8 9 10 | |
Educational Principles
When generating programs:
- Progressive Complexity: Start simple, add features incrementally
- Clear Comments: Explain what each section does
- Consistent Naming: Use descriptive variable names
- Visible Feedback: Use print statements to show what's happening
- Adjustable Parameters: Use constants for easy experimentation
Best Practices
- Always call
strip.write()after modifying pixels - Use modulo for wrapping:
counter % config.NUMBER_PIXELSto loop animations - Debounce buttons: Check 200ms has passed between button presses
- Import config: Always use
import configand reference configuration constants - Add delays: Include
sleep()calls to control animation speed - Clear pixels: Turn off pixels when moving animations to prevent trails
- Test boundary conditions: Ensure animations work at pixel 0 and last pixel
Common Functions
Erase Strip
1 2 3 4 | |
Setting Pixels
1 2 | |
Using Counter with Modulo
1 2 3 4 5 6 7 8 | |
Educational Applications
- Physical Computing: Understanding microcontroller I/O
- Color Theory: RGB color mixing and perception
- Animation Basics: Frame-by-frame updates and timing
- Event Handling: Button interrupts and debouncing
- State Machines: Mode switching and program flow
- Arrays and Iteration: Working with pixel arrays
- Modular Programming: Breaking code into functions
Output Format
Generated programs: - Are complete, runnable MicroPython code - Include necessary imports - Use config module for hardware settings - Include helpful comments - Follow established code patterns - Are educational and easy to understand
Integration
Works well for: - STEM Education: Hands-on electronics and programming - Maker Projects: Interactive LED displays - Computer Science: Teaching loops, arrays, and functions - Art/Design: Creating visual effects and patterns - Project-Based Learning: Complete working projects
Technical Requirements
- Raspberry Pi Pico or compatible RP2040 board
- MicroPython firmware installed
- 30-pixel WS2812B/NeoPixel LED strip (5V)
- Two momentary push buttons
- Adequate power supply for LED strip (typically 2-5A)
References
- MicroPython Documentation: https://docs.micropython.org/
- Raspberry Pi Pico: https://www.raspberrypi.com/documentation/microcontrollers/
- NeoPixel Guide: https://learn.adafruit.com/adafruit-neopixel-uberguide
- WS2812B Datasheet: Standard addressable RGB LED specifications