Note
Hello, welcome to the SunFounder Raspberry Pi & Arduino & ESP32 Enthusiasts Community on Facebook! Dive deeper into Raspberry Pi, Arduino, and ESP32 with fellow enthusiasts.
Why Join?
Expert Support: Solve post-sale issues and technical challenges with help from our community and team.
Learn & Share: Exchange tips and tutorials to enhance your skills.
Exclusive Previews: Get early access to new product announcements and sneak peeks.
Special Discounts: Enjoy exclusive discounts on our newest products.
Festive Promotions and Giveaways: Take part in giveaways and holiday promotions.
👉 Ready to explore and create with us? Click [here] and join today!
Lesson 10: Lighting the Way with RGB LED Strips
Our Mars Rover has become a skilled explorer, but now it’s time to add some colorful personality! In this lesson, we’ll transform our rover with RGB LED strips that can glow in any color imaginable.
Imagine your GalaxyRVR lighting up its path like a spaceship from a sci-fi movie:
Green glow when moving forward
Red light when stopping
Yellow flashes when turning
Beautiful color shows just for fun!
We’ll learn how to program these amazing lights and sync them with your rover’s movements. Get ready to create your own light-up Mars explorer!
Learning Objectives
Discover how RGB LED strips work and how to program them
Learn to control colors and create lighting effects using Mammoth Coding
Design light signals and colors for your Mars exploration missions
Explore the Magic of Light with RGB LED Strips
Have you ever wanted to create your own rainbow? Now you can! With RGB LED strips, you can make your Mars rover glow with any color you can imagine. Let’s discover the magic of colorful lights!
Meet the four important pins on your LED strip:
+5V - The power pin that gives energy to all the lights (needs 5V electricity)
B - Controls the blue lights
R - Controls the red lights
G - Controls the green lights
Remember learning about primary colors in art class? Just like mixing paint, each LED can blend red, blue, and green light to create amazing colors! Each “5050” LED is like a tiny color factory containing all three colors.
All these color factories are connected together on a flexible circuit - like a colorful electric highway! The power pins connect together, while the color pins each have their own special path.
The most exciting part? You can program ALL the LEDs to change colors at the same time! Imagine creating your own light show with just a few code blocks. Get ready to light up your Mars rover adventure!
Light Up the Show
First, Connecting the APP to GalaxyRVR.
Now, let’s make your GalaxyRVR glow! Drag out a “display color” block to start.
Choose any color you like from the color menu.
Click the block and watch your GalaxyRVR light up with your chosen color!
Create a Color Controller
Now let’s build an interactive color controller! We’ll create colorful buttons on the stage that change your GalaxyRVR’s lights when you tap them.
First, delete any existing sprites to start fresh.
Add a Ball sprite from the library. This sprite is perfect because it comes with multiple color costumes.
Add a “when this sprite clicked” block - this will make things happen when you tap the ball.
Connect a “display color” block to light up your GalaxyRVR.
On small screens, make sure you can see the stage by clicking the eye button.
Click the color box in the display block, then click the color picker button at the bottom.
Press and hold on the stage area - a magnifying glass will appear! Release it over the ball sprite to copy its color.
Make more color buttons by long-pressing the ball sprite to duplicate it.
Change each duplicate to a different color by switching its costume.
For each new color, use the color picker to match the display block to the sprite’s current color.
Repeat until you have five different color buttons!
Now tap any colored ball on the stage and watch your GalaxyRVR glow with that color! Create your own light show with just a tap.
GalaxyRVR Signal Lights in Action
Directional Indicator Lights
Let’s combine light colors with movement to create signal lights for your GalaxyRVR! Just like a car has turn signals, your rover will light up in different colors when it moves.
First, Connecting the APP to GalaxyRVR.
Now, set up direction keys with movement blocks for all four directions.
Add color displays to each direction:
Green light for moving forward
Yellow lights for turning left and right
Red light for moving backward
Now when you press the direction keys, your GalaxyRVR will move and glow with the matching color!
Breathing Light Effect
Let’s create a cool breathing light that slowly brightens and dims when your rover is resting, just like it’s breathing!
Create a new broadcast message called “stop” to signal when the rover isn’t moving.
Note
Broadcast messages help organize your code by triggering specific actions at the right time, making your programs cleaner and easier to understand.
Add this broadcast after each movement command.
Create a “when I receive [stop]” block to start the breathing light.
Set brightness to 0% to start from completely dark.
Use a repeat loop to gradually increase blue light brightness by 10% every 0.2 seconds.
Then gradually decrease the brightness to complete one breathing cycle.
Broadcast “stop” again to keep the breathing effect continuous.
Add “stop other scripts” at the end of each key event to prevent color conflicts.
Reset the light brightness in each direction key event.
Now your GalaxyRVR will light up with colored signals when moving, and gently pulse with a breathing blue light when resting!