Mixing Custom Colors with RGB LEDs | Task 4

Now it’s time to explore how to create your own colors using the RGB LED! You already know how to turn the red, green, and blue pins on and off. But what if you want to mix them together to make custom colors?

We can use different brightness levels with analogWrite() on each color pin. Here’s an example for yellow:


          if (colorInput == "yellow") {
            analogWrite(redPin, 255);
            analogWrite(greenPin, 150);
            analogWrite(bluePin, 0);
          }        
        

The numbers represent the intensity of each color (0–255). Try changing the values to see what new colors you can create!

Use this color mixing tool to find the perfect combination: RGB Color Mixer Tool

Tip: The more light you mix, the brighter the color becomes. Try low numbers for dimmer colors and high numbers for bright or white!


"While" and "if" loops

A “while” loop is like waiting for something to happen before you can do something else. It’s a bit like standing in front of a vending machine, and you keep checking if the machine has your favorite snack. You won’t leave until you see it. In programming, it works similarly. The loop keeps running as long as a certain condition is true. It’s like saying, “Keep doing this until I tell you to stop.”

An “if” statement is like making decisions in your daily life. For example, imagine you’re deciding whether to go outside to play or stay inside to read a book. You might say, “If it’s sunny, I’ll go outside. Otherwise, I’ll stay inside.” In programming, it’s the same idea. You use “if” to check a condition, and if it’s true, you do something; if it’s not true, you might do something else. It’s like giving instructions based on a condition.

So, “while” loops help you wait for a specific condition to be met, and “if” statements help you make choices or take actions based on conditions. These tools are handy for the computer to respond to different situations and make your programs do what you want them to do.