![]() ![]() We'll connect an RGB LED to the Arduino Uno and compose a simple program to change its color. You should see your LED turn on, but this time in new, crazy colors! If it isn't, make sure you have assembled the circuit correctly and verified and uploaded the code to your board or see the troubleshooting section.Let's learn how to control multi color LEDs using Arduino’s analog outputs. Now that the brightness values have been set, command the LEDĪ for() loop is used to repeat an action a set number of times across a range, and repeatedly runs code within the brackets will run. GreenIntensity = 0 // green is always offīlueIntensity = 255 - (color - 512) // blue on to off RedIntensity = (color - 512) // red off to on For the for() loop below, these are the three statements: Every for() loop has three statements separated by semicolons: For() loops are a very handy way to get numbers from one value to another, and perform a set of instructions In this function, we're using a "for() loop" to step a variable number of colors), and repeatedly calling showRGB() to display It does this by stepping a variable from 0 to 768 (the total This function steps through all the colors of the RGB LED. you have a handy function, you can reuse it in your other this, which makes your sketches easier to follow, and once We'll often break tasks down into individual functions like showSpectrum() steps through all the colors of the RGB LED, You call showRGB() with the number of a color you want showRGB() displays a single color on the RGB LED. Below are two more functions we've written, own sketch, you cancopy and paste that section into your code. If you'd like to use one of these colors in your This function displays the eight "main" colors that the RGB LED Here's the mainColors() function we've written. here the actual code is further down in this sketch. We've written a function called showSpectrum() that smoothly lets you dim a LED from full-off to full-on over 255 steps. The analogWrite() function lets us do this. you can do so by varying the brightness of the individual If you want to generate more than eight colors, The above function turns the individual LEDs full-on and We've written a function called mainColors() that steps a total of eight colors (if you count "black" as a color). and green) on and off in various combinations. The first way is to turn the individual LEDs (red, blue, We'll show you two ways to run the RGB LED. the sketch into sections, and not having everything in This makes the sketch easier to follow by dividing up In this sketch, we'll start writing our own functions. Here we'll configure the Arduino pins we're using to (Try changing this to make the fading faster or slower.) This variable controls how fast we loop through the colors. try to change the value, so it's considered good form.) Arduino will give you a friendly warning if you accidentally (You don't have to do this, but if you do, the variable indicates that this is a "constant" value that will Here's a new trick: putting the word "const" in front of a First we'll define the pins by name to make the sketch With lots of help from the Arduino community. This sketch was written by SparkFun Electronics, Of the resistor to Arduino digital pin 11. Of the resistor to Arduino digital pin 10.Ĭonnect BLUE to a 330 ohm resistor. Of the resistor to Arduino digital pin 9.Ĭonnect GREEN to a 330 ohm resistor. The pins are ordered RED, COMMON, GREEN, BLUE.Ĭonnect RED to a 330 ohm resistor. Starting at the flattened edge of the flange on the LED, The red, green and blue mix to form new colors. When you run them at different brightnesses, ![]() Make an RGB LED display a rainbow of colors!Īn RGB LED is actually three LEDs (red, green, and blue) in Hit upload, and see what happens! language:cpp You can also copy and paste the following code into the Arduino IDE. To open the code go to: File > examples > SIK Guide Code > Circuit_03 Open the code for Circuit 3 by accessing the “SIK Guide Code” you downloaded and placed into your “Examples” folder earlier. Coding in the Arduino language will control your circuit. ![]() Open Up the Arduino IDE software on your computer. ![]() Having a hard time seeing the circuit? Click on the Fritzing diagram to see a bigger image. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |