![]() More complicated functions take and return pieces of information from the program (we call these pieces of information parameters). When you want to run that code, you can “call” the function by typing its name, instead of writing out all of the code. The simplest functions are just chunks of code that you give a name to. When programmers want to use a piece of code over and over again, they write a function. That's a lot of color! Creating Your Own Simple Functions By varying the voltage that gets sent to the red, green, and blue pins that are connected to the legs of the RGB LED, you can create 16,777,216 different colors. That means each 50 steps corresponds to an increase of about 1 volt. The function breaks the range between 0 and 5V into 255 little steps. The analogWrite function outputs a voltage between 0 and 5V to a pin. Here is the circuit diagram we will use for our lab: Remember, you can only use analogWrite() on these pins. Each PWM pin is marked with a ~ on the board. Only a few of the digital pins on the Uno and RedBoard have the circuitry needed to turn on and off fast enough for PWM. By using PWM, you can create many different colors with the RGB LED. This is what is known as pulse-width modulation (or PWM). By changing the percent of time that a pin is on, from 0 percent (always off) to 100 percent (always on), analogWrite() can output any voltage between 0 and 5V. analogWrite() can output 2.5 volts by quickly switching a pin on and off so that the pin is only on 50 percent of the time (50% of 5V is 2.5V). You can use the digitalWrite() command to turn pins on the Arduino on (5V) or off (0V), but what if you want to output 2.5V? The Arduino doesn't have an analog output, but it is really good at switching some digital pins on and off fast enough to simulate an analog output. Now you are going to apply this knowledge to creating different colors of varying brightness. ![]() In Circuit 3, you learned about analog output versus digital output. Varying Color and Brightness Using Analog Output (Pulse-Width Modulation) Here is a picture of an RGB LED with the legs labeled: Both are indicators to help orient the LED correctly. Pay close attention to the flat edge and to the different length legs. Just like a regular LED, an RGB LED is polarized and only allows electricity to flow in one direction. If you turn on more than one color at a time, you will see the colors start to blend together to form a new color. To turn one color on, ensure ground is connected, then power one of the legs just as you would a regular LED. The RGB LED included in this kit has all the internal LEDs share the same ground wire, so there are four legs in total. Concepts RGB LEDĪn RGB LED is actually three small LEDs - one red, one green and one blue - inside a normal LED housing. In this lab, we will learn how to make an RGB (Red-Green-Blue) LED display different colors by mixing red, green, and blue light.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |