This tutorial is part of: SunFounder Raspberry Pi Pico Pico 4WD Akıllı Araba Kiti
Bu gruba ait dosyalar birlikte görüntülenecektir. Diğer videolara ait bağlantılar bu makalenin altında yer almaktadır.
Course Lesson 5 of 10: Controlling RGB LED WS2812B Using Raspberry Pi Pico
This lesson, part of the Robojax Raspberry Pi Pico Smart Car course, focuses on controlling the RGB LED strip (WS2812B) on the SunFounder 4-wheel drive car kit. You'll move beyond simple on/off control and learn how to mix red, green, and blue values to create any color, control individual LEDs, and create dynamic light sequences like a "walking" light effect. This skill is fundamental for adding visual feedback and personality to your robotics projects.
Controlling RGB LEDs is a core skill for any robotics or electronics project. Here are a few practical things you can build with this knowledge:
- Custom Status Indicators: Use different colors to show your robot's state, such as green for "ready," blue for "working," and red for "error."
- Interactive Lighting Effects: Create "chase" or "knight rider" style light patterns for a more dynamic and engaging robot.
- Visual Feedback for Sensors: Program the LEDs to change color based on sensor data, like turning red when an obstacle is near or blue when it's following a line.
- Ambient Lighting: Set the LEDs to a random color or a specific hue to create a custom atmosphere for your car or other projects.
Hardware/Components
This project uses the components that come with the SunFounder Raspberry Pi Pico 4-wheel drive car kit. The key component is the RGB LED strip itself, which is controlled by the Raspberry Pi Pico.
- Raspberry Pi Pico
- SunFounder 4-wheel drive car kit (which includes the WS2812B RGB LED strip)
- Battery pack for the car (to power the LEDs, as mentioned in the video)
Wiring Guide
The video lesson doesn't detail the wiring process, as it's part of the car kit's pre-assembled design. The LEDs are already connected to the Raspberry Pi Pico. For a custom setup, you would typically connect the data pin of the WS2812B strip to a GPIO pin on the Pico, along with power (5V) and ground (GND). Since this lesson uses the car kit, no additional wiring is needed.
If you are building this on a breadboard, you would connect your LED strip's data line to a GPIO pin (e.g., GP0) and power it with an external 5V supply.
Code Explanation
The lesson focuses on using the pre-written functions from the car kit's library. The core function for controlling the lights is set_light_color(). This method is called on the car object and takes two main arguments: the light's ID number and a list of three values representing the Red, Green, and Blue (RGB) intensity.
Here is a breakdown of how to use the key functions demonstrated in the video:
car.set_light_color(LED_ID, [R, G, B]): This is the most direct way to control an individual LED. TheLED_IDis an integer from 0 to 23, and the color is a list like[255, 0, 0]for red.- Library Helper Functions: The kit's library provides higher-level functions like
set_all_light_color(),set_bottom_left_color(), andset_bottom_right_color()to control groups of LEDs more easily.
To create a custom color, you can adjust the three values in the list. For example, [255, 255, 0] makes yellow, [0, 255, 255] makes cyan, and [255, 0, 255] makes pink or magenta. The video demonstrates creating these colors by mixing the primary RGB values.
For random colors, you can use the random.randint(0, 255) function to generate random values for R, G, and B, as shown in the "random" example. This assigns a unique, random color to each of the 24 LEDs.
Live Project/Demonstration
In the video, the instructor demonstrates the concepts live. He first shows how to turn on all the bottom lights to a solid green by setting the RGB values to [0, 255, 0]. Then, he changes the color to red by setting [255, 0, 0]. The demonstration continues by showing how to control individual LEDs by their ID number (0-23) and setting their colors independently.
A significant portion of the video is dedicated to creating a "walking light" effect. This is done with a for loop that iterates from 1 to 24. In each iteration, it turns on the current LED for a set time (e.g., 300 milliseconds) and then turns it off for a very short time (e.g., 10 milliseconds) before moving to the next one. This creates the illusion of a light moving along the strip. The instructor also shows how to adjust the speed of this effect by changing the delay values.
Finally, he demonstrates the "random color" program, which uses the random library to generate a unique color for each of the 24 LEDs every time the code runs, creating a vibrant, multi-colored display.
Chapters
- [00:00] Introduction to RGB LEDs and the Smart Car Course
- [02:36] Understanding the RGB Color Model
- [05:00] Controlling Lights with Library Functions
- [09:01] How to Control Individual LEDs (0-23)
- [13:08] Creating a Walking Light Effect
- [15:32] Generating Random Colors for Each LED
This tutorial is part of: SunFounder Raspberry Pi Pico Pico 4WD Akıllı Araba Kiti
- Course Lesson 1 of 10: Raspberry Pi Pico 4WD Smart Car Kit from SunFounder by Robojax
- Course Lesson 2 of 10: Basic Python to drive Raspberry Pi Pico 4WD Smart Car Kit
- Course Lesson 3 of 10: Assembling Raspberry Pi Pico 4WD Smart Car Kit from SunFounder by Robojax
- Course Lesson 4 of 10: Raspberry Pi Pico Expansion board for 4WD Smart Car Kit
- Course Lesson 6 of 10: Controlling DC Motors using Raspberry Pi Pico 4WD Smart Car Kit
- Lesson 7 of 10: Line Tracking, Cliff Detection Calibrate Greyscale Sensor Raspberry Pi Pico Car
- Course Lesson 8 of 10: Raspberry Pi Pico Smart Car – Lesson 8: Servo Motor and Object Following
- Course Lesson 9 of 10: Obstacle Avoidance using Raspberry Pi Pico 4WD Smart Car
- Course Lesson 10 of 10: Controlling Raspberry Pi Pico 4WD Smart Car Kit with mobile App
Common Course Links
- Purchase SunFounder Pico 4WD Smart Car Kit from AliExpress
- Purchase SunFounder Pico 4WD Smart Car Kit from eBay
- Amazon Canada: Purchase Pico 4WD Smart Car Kit by SunFounder
- Amazon France: Purchase Pico 4WD Smart Car Kit by SunFounder
- Amazon Germany: Purchase Pico 4WD Smart Car Kit by SunFounder
- Amazon Italy: Purchase Pico 4WD Smart Car Kit by SunFounder
- Amazon Japan: Purchase Pico 4WD Smart Car Kit by SunFounder
- Amazon Spain: Purchase Pico 4WD Smart Car Kit by SunFounder
- Amazon UK: Purchase Pico 4WD Smart Car Kit by SunFounder
- Amazon USA: Purchase Pico 4WD Smart Car Kit buy SunFounder
- Purchase Pico 4WD Smart Car Kit from SunFounder.com
- SunFounder Pico-4wd Car Kit Documentation
- Video Play List of 10 lesson on SunFounder Pico 4WD Smart Car Kit
Kaynaklar ve referanslar
Henüz kaynak yok.
Dosyalar📁
Dosya mevcut değil.