1. Purpose of the Case
Learn to use the NeoPixel RGB LED panel module and further understand loops and other logic.
The NeoPixel RGB LED panel is driven by the WS2812 chip, which allows independent control of the color and brightness of each LED. Each LED module has a built-in driver circuit and can be daisy-chained via digital signals, simplifying wiring. The WS2812 is commonly used in creative lighting, displays, decorative lighting effects, stage lighting, billboards, home decor, and more.
2. Materials Used
3. Software Platform
MicroBlocks——CoCube & CoCube Module
4. Quick Experience
Connect Device: Connect the MicroBlocks IDE to the CoCube robot via a wired or wireless connection, and attach the NeoPixel RGB LED panel module to the CoCube robot.
Add Block Library: Under the "Robot" directory, add the "CoCube Module Library" — this library includes the three most commonly used functions for the NeoPixel panel: connect, light up, and turn off.
- Connect NeoPixels: In the "CoCube Module" block library, find the "attach NeoPixels" block, drag it into the workspace, and click to run.
- Light Up All NeoPixels: Drag out the "Set all NeoPixels color" block, click to run, and all 48 LEDs on the NeoPixel panel will light up. You can try adjusting the LED colors.
- Clear Display: To turn off the NeoPixels, drag out the "clear NeoPixels" block and click to run.
- Note: The WS2812 is a power-hungry component, so the CoCube robot's battery will drain faster. Be sure to monitor the battery level and recharge it promptly.
5. Advanced Features
The NeoPixel RGB LED panel is driven by the WS2812 chip, and the LEDs are arranged from left to right and top to bottom. The color and brightness of each LED can be independently controlled. After adding the "CoCube Module" library, you'll notice that the NeoPixel library it depends on is also loaded into the MicroBlocks IDE. Based on this, we can achieve richer effects.
5.1 Running Lights
Recall [01 LCD Screen Programming], where we implemented a running light program for a 5x5 LCD screen. Now let's re-implement it on the NeoPixel RGB LED panel.
Reference Program — Think First!
5.2 Multi-Color Running Lights
Think about how you could implement running lights with different colors on each row.
Reference Code — Think First!
5.3 Rotation
The "Rotate NeoPixel Spacing" block shifts the current LED colors as a whole.
5.4 Color Flow
How can you make the LED panel display a smooth gradient effect?
Taking it a step further, can you create a rainbow gradient?
Reference Code — Think First!
6. Challenge Yourself
Working with the CoCube robot's positioning map, what more interesting creations can you come up with?
7. Reference Code Examples
All case code examples above: