








{"id":99,"date":"2020-10-12T21:17:24","date_gmt":"2020-10-12T21:17:24","guid":{"rendered":"https:\/\/osoyoo.info\/?p=99"},"modified":"2020-10-13T22:09:53","modified_gmt":"2020-10-13T22:09:53","slug":"arduino-basic-lesson-16-rgb-led","status":"publish","type":"post","link":"https:\/\/osoyoo.info\/index.php\/2020\/10\/12\/arduino-basic-lesson-16-rgb-led\/","title":{"rendered":"Hardware Programming with Arduino IDE &#8211; Lesson 16: RGB LED"},"content":{"rendered":"<p><a href=\"https:\/\/osoyoo.info\/index.php\/2020\/10\/12\/arduino-basic-lesson-15-i2c-lcd1602-display\/\"><img loading=\"lazy\" class=\"alignnone\" src=\"https:\/\/osoyoo.com\/picture\/Arduino_Graphical_Programming_Kit\/Previous.png\" alt=\"\" width=\"206\" height=\"59\" \/><\/a>\u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0<a href=\"https:\/\/osoyoo.info\/index.php\/2020\/10\/11\/arduino-basic-tutorial-directory\/\"><img loading=\"lazy\" class=\"alignnone\" src=\"https:\/\/osoyoo.com\/picture\/Arduino_Graphical_Programming_Kit\/Tutorial.png\" alt=\"\" width=\"206\" height=\"59\" \/><\/a>\u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0<a href=\"https:\/\/osoyoo.info\/index.php\/2020\/10\/12\/lesson-17-dht11-sensor\/\"><img loading=\"lazy\" class=\"alignright\" src=\"https:\/\/osoyoo.com\/picture\/Arduino_Graphical_Programming_Kit\/Next.png\" alt=\"\" width=\"206\" height=\"59\" \/><\/a><\/p>\n<div align=\"center\">\n<div align=\"center\"><img class=\"aligncenter\" src=\"https:\/\/osoyoo.com\/picture\/icon\/authorized_retailers.png\" \/><\/div>\n<div align=\"center\"><\/div>\n<table>\n<tbody>\n<tr>\n<td>Buy from US<\/td>\n<td>Buy from UK<\/td>\n<td>Buy from DE<\/td>\n<td>Buy from IT<\/td>\n<td>Buy from FR<\/td>\n<td>Buy from ES<\/td>\n<td>Buy from JP<\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/www.amazon.com\/dp\/B08J7DKJK9?ref=myi_title_dp\"><img loading=\"lazy\" class=\"alignnone size-large\" src=\"https:\/\/osoyoo.com\/picture\/icon\/us_buy_now.png\" width=\"150\" height=\"30\" \/><\/a><\/td>\n<td><a href=\"https:\/\/www.amazon.co.uk\/dp\/B08J6BL2P7\"><img loading=\"lazy\" class=\"alignnone\" src=\"https:\/\/osoyoo.com\/picture\/icon\/uk_buy_now.png\" alt=\"\" width=\"150\" height=\"30\" \/><\/a><\/td>\n<td><a href=\"https:\/\/www.amazon.de\/dp\/B08J6BL2P7\"><img loading=\"lazy\" class=\"alignnone size-large\" src=\"https:\/\/osoyoo.com\/picture\/icon\/de_buy_now.png\" width=\"150\" height=\"30\" \/><\/a><\/td>\n<td><a href=\"https:\/\/www.amazon.it\/dp\/B08J6BL2P7\"><img loading=\"lazy\" class=\"alignnone size-large\" src=\"https:\/\/osoyoo.com\/picture\/icon\/it_buy_now.png\" width=\"150\" height=\"30\" \/><\/a><\/td>\n<td><a href=\"https:\/\/www.amazon.fr\/dp\/B08J6BL2P7\"><img loading=\"lazy\" class=\"alignnone size-large\" src=\"https:\/\/osoyoo.com\/picture\/icon\/fr_buy_now.png\" width=\"150\" height=\"30\" \/><\/a><\/td>\n<td><a href=\"https:\/\/www.amazon.es\/dp\/B08J6BL2P7\"><img loading=\"lazy\" class=\"alignnone size-large\" src=\"https:\/\/osoyoo.com\/picture\/icon\/es_buy_now.png\" width=\"150\" height=\"30\" \/><\/a><\/td>\n<td><a href=\"https:\/\/www.amazon.co.jp\/dp\/B08J7TLP48\"><img loading=\"lazy\" class=\"alignnone size-large\" src=\"https:\/\/osoyoo.com\/picture\/icon\/jp_buy_now.png\" width=\"150\" height=\"30\" \/><\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<h2><strong>Content<\/strong><\/h2>\n<ol>\n<li><a href=\"#1\">Introduction<\/a><\/li>\n<li><a href=\"#2\">Preparations<\/a>\n<ul>\n<li><a href=\"#2.1\">Hardware<\/a><\/li>\n<li><a href=\"#2.2\">Software<\/a><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"#3\">About the RGB LED<\/a>\n<ul>\n<li><a href=\"#3.1\">How do RGB LEDs work?<\/a><\/li>\n<li><a href=\"#3.2\">Two types of RGB LEDs<\/a><\/li>\n<li><a href=\"#3.3\">How to create different colors?<\/a><\/li>\n<li><a href=\"#3.4\">Pulse-width Modulation(PWM)<\/a><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"#4\">Connection<\/a><\/li>\n<li><a href=\"#5\">Code Program<\/a><\/li>\n<li><a href=\"#6\">Running Result<\/a><\/li>\n<\/ol>\n<h1 id=\"1\">Introduction<\/h1>\n<p>The RGB color model is an additive color model in which red, green and blue light are added together in various ways to reproduce a broad array of colors. The name of the model comes from the initials of the three additive primary colors, red, green and blue. In this lesson, we will show how to use a RGB (Red Green Blue) LED with an Arduino.<\/p>\n<h1 id=\"2\">Preparations<\/h1>\n<h2 id=\"2.1\">Hardware<\/h2>\n<ul>\n<li>Osoyoo UNO Board (Fully compatible with Arduino UNO rev.3) x 1<\/li>\n<li>OSOYOO Magic I\/O Shield for Arduino x1<\/li>\n<li>RGB Module x 1<\/li>\n<li>OSOYOO 4-Pin PNP Cable x 1<\/li>\n<li>USB Cable x 1<\/li>\n<li>PC x 1<\/li>\n<\/ul>\n<h2 id=\"2.2\">Software<\/h2>\n<ul>\n<li>Arduino IDE (version 1.6.4+)<\/li>\n<\/ul>\n<h1 id=\"3\">About RGB LED<\/h1>\n<h2><span id=\"Specification\" class=\"mw-headline\">RGB MODULE SPECIFICATION<\/span><\/h2>\n<ul>\n<li>Color: red, green and blue<\/li>\n<li>Brightness: High<\/li>\n<li>Voltage: 3.3V~5V<\/li>\n<li>Input: digital level<\/li>\n<\/ul>\n<h2 id=\"3.1\">How do RGB LEDs work?<\/h2>\n<p>At first glance, RGB (Red, Green, Blue) LEDs look just like regular LEDs, however, inside the usual LED package, there are actually three LEDs, one red, one green and yes, one blue. By controlling the brightness of each of the individual LEDs you can mix pretty much any color you want.<\/p>\n<h2 id=\"3.2\">Two types of RGB LEDs<\/h2>\n<p>There are common anode RGB LEDs and common cathode RGB LEDs. See figure below:<\/p>\n<p><a href=\"https:\/\/osoyoo.com\/wp-content\/uploads\/2017\/08\/types-1.jpg\"><img loading=\"lazy\" class=\"size-full wp-image-10463 aligncenter\" src=\"https:\/\/osoyoo.com\/wp-content\/uploads\/2017\/08\/types-1.jpg\" alt=\"\" width=\"480\" height=\"226\" \/><\/a><\/p>\n<p>As you can see, the 3 LEDs can share the cathode or the anode. This results in an RGB LED that has 4 pins, one for each LED, and one common cathode or one common anode.<\/p>\n<p>The 4 pins which can be distinguished by their length. The longest one is the ground (-) or voltage (+) depending if it is a common cathode or common anode LED, respectively.<\/p>\n<p>The common anode RGB LED is the most popular type. We also use it here.<\/p>\n<p><span style=\"color: #ff0000;\"><strong>Note:<\/strong> <span style=\"color: #000000;\">If you are using a common ANODE LED instead of common CATHODE, connect the long pin to +5V instead of ground<\/span><\/span><\/p>\n<div class=\"page-title-wrapper\">\n<h2 id=\"3.3\">How to create different colors?<\/h2>\n<\/div>\n<div class=\"page-content all-page-view-content\">\n<div class=\"row-fluid build-text\">\n<p>The reason that you can mix any color you like by varying the quantities of red, green and blue light is that your eye has three types of light receptor in it (red, green and blue). Your eye and brain process the amounts of red, green and blue and convert it into a color of the spectrum.<\/p>\n<p>In a way, by using the three LEDs we are playing a trick on the eye. This same idea is used in TVs, where the LCD has red, green and blue color dots next to each other making up each pixel.<\/p>\n<\/div>\n<\/div>\n<h2><a href=\"https:\/\/osoyoo.com\/wp-content\/uploads\/2017\/08\/color-mixing.png\"><img loading=\"lazy\" class=\"size-full wp-image-10489 aligncenter\" src=\"https:\/\/osoyoo.com\/wp-content\/uploads\/2017\/08\/color-mixing.png\" alt=\"\" width=\"300\" height=\"300\" \/><\/a><\/h2>\n<p>You can create one of those three colors \u2013 red, green or blue \u2013 by activating just one LED.<\/p>\n<p>For example, if you want to produce blue, you activate the blue LED and turn off the other two.<\/p>\n<p><a href=\"https:\/\/osoyoo.com\/wp-content\/uploads\/2017\/08\/5-1.gif\"><img loading=\"lazy\" class=\"size-full wp-image-21902 aligncenter\" src=\"https:\/\/osoyoo.com\/wp-content\/uploads\/2017\/08\/5-1.gif\" alt=\"\" width=\"527\" height=\"200\" \/><\/a><\/p>\n<p>If we set the brightness of all three LEDs to be the same, then the overall color of the light will be white. If we turn off the blue LED, so that just the red and green LEDs are the same brightness, then the light will appear yellow.<\/p>\n<p>We can control the brightness of each of the red, green and blue parts of the LED separately, making it possible to mix any color we like.<\/p>\n<p>Black is not so much a color as an absense of light. So the closest we can come to black with our LED is to turn off all three colors.<\/p>\n<h2 id=\"3.4\"><strong>Pulse-width Modulation(PWM)<\/strong><\/h2>\n<p>The brightness of an LED is proportional to the current going through it, but it would be rather difficult to use a microcontroller to accurately control the current flowing through an LED. Fortunately, human vision has a nice phenomenon called <a href=\"http:\/\/en.wikipedia.org\/wiki\/Persistence_of_vision\">persistence of vision<\/a>. Persistence of vision is the phenomenon where an image that is seen for only a fraction of a second will continue to be &#8220;seen&#8221; by your brain even after the original image has vanished or moved. This this the same principle behind film and television, where a rapidly changing image tricks your brain into seeing continuous motion. By turning our LED on and off rapidly, we can trick the brain into seeing an &#8220;average&#8221; value of brightness based on the <a href=\"http:\/\/en.wikipedia.org\/wiki\/Duty_cycle\">duty cycle<\/a> of the driving PWM signal.<\/p>\n<p><a href=\"http:\/\/en.wikipedia.org\/wiki\/Pulse-width_modulation\">Pulse-width modulation<\/a> (PWM) is the practice of modulating the duty cycle of a signal, used in this application to control the average power sent to each LED. In the following figure, we show three different duty cycles, first with 50% duty cycle, then 10% and 90% duty cycle. During the 10% duty cycle, the signal is at the logic high level for only a brief time each cycle, but with 90% duty cycle, most of the signal&#8217;s period is spent at logic high level. If the frequency of the signal is fast enough, then there will be no visible flicker, and the LED&#8217;s brightness will be proportional to the signal&#8217;s duty cycle.<\/p>\n<p><a href=\"https:\/\/osoyoo.com\/wp-content\/uploads\/2017\/08\/pwm.png\"><img loading=\"lazy\" class=\"size-full wp- image-10501 aligncenter\" src=\"https:\/\/osoyoo.com\/wp-content\/uploads\/2017\/08\/pwm.png\" alt=\"\" width=\"700\" height=\"283\" \/><\/a><\/p>\n<h2 id=\"4.3\">RGB LED COLOR CONTROL<\/h2>\n<p>RGB stands for the red, green, and blue color channels and is an industry color standard. RGB displays various new colors by changing the three channels and superimposing them, which, according to statistics, can create 16,777,216 different colors. If you say the color displayed doesn\u2019t completely match a natural color, then it almost certainly cannot be differentiated with the naked eyes.<\/p>\n<p>Each of the three color channels of red, green, and blue has 255 stages of brightness. When the three primary colors are all 0, \u201cLED light\u201d is the darkest, that is, it turns off. When the three primary colors are all 255, \u201cLED light\u201d is the brightest. When superimposing the light emitted by the three primary colors, the colors will be mixed. However, the brightness is equal to the sum of all brightness, and the more you mix, the brighter the LED is. This process is known as additive mixing.<\/p>\n<h1 id=\"4\">Connection<\/h1>\n<p>First, please plug Osoyoo Magic I\/O shield into UNO board:<\/p>\n<p><img class=\"aligncenter\" src=\"https:\/\/osoyoo.com\/picture\/Arduino_Graphical_Programming_Kit\/lesson4\/UNO%2BBase-min.png\" \/><\/p>\n<p>Then connect the RGB module to the RGB port of the Magic I\/O shield with a 4-pin PNP cable as below:<\/p>\n<p><img class=\"aligncenter\" src=\"https:\/\/osoyoo.com\/picture\/Arduino_Graphical_Programming_Kit\/lesson10\/Base-RGB-min.png\" \/><\/p>\n<h1 id=\"5\">Code Program<\/h1>\n<p>After above operations are completed, connect the Arduino board to your computer using the USB cable. The green power LED (labelled\u00a0<strong>PWR<\/strong>) should go on.<\/p>\n<p><img class=\"aligncenter\" src=\"https:\/\/osoyoo.com\/picture\/Arduino_Graphical_Programming_Kit\/lesson1\/uno-pc.png\" \/><\/p>\n<p>Open the Arduino IDE and choose corresponding board type and port type for you project. Then load up the following sketch onto your Arduino.<\/p>\n<p>Or you can directly download from <a href=\"https:\/\/osoyoo.com\/picture\/OSOYOO_PnP_Kit_for_Arduino\/code\/Lesson17_RGB_LED_color_control.rar\">here<\/a>.<\/p>\n<pre><span style=\"color: #00979c;\">const<\/span> <span style=\"color: #00979c;\">int<\/span> <span style=\"color: #000000;\">redPin<\/span> <span style=\"color: #434f54;\">=<\/span> <span style=\"color: #000000;\">11<\/span><span style=\"color: #000000;\">;<\/span> <span style=\"color: #434f54;\">\/\/ R connected to digital pin 11 <\/span> \r\n<span style=\"color: #00979c;\">const<\/span> <span style=\"color: #00979c;\">int<\/span> <span style=\"color: #000000;\">greenPin<\/span> <span style=\"color: #434f54;\">=<\/span> <span style=\"color: #000000;\">12<\/span><span style=\"color: #000000;\">;<\/span> <span style=\"color: #434f54;\">\/\/ G to digital pin 10 <\/span> \r\n<span style=\"color: #00979c;\">const<\/span> <span style=\"color: #00979c;\">int<\/span> <span style=\"color: #000000;\">bluePin<\/span> <span style=\"color: #434f54;\">=<\/span> <span style=\"color: #000000;\">13<\/span><span style=\"color: #000000;\">;<\/span> <span style=\"color: #434f54;\">\/\/ B connected to digital pin 9 <\/span> \r\n<span style=\"color: #00979c;\">void<\/span> <span style=\"color: #5e6d03;\">setup<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">)<\/span> <span style=\"color: #000000;\">{<\/span> \r\n<span style=\"color: #d35400;\">pinMode<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">redPin<\/span><span style=\"color: #434f54;\">,<\/span> <span style=\"color: #00979c;\">OUTPUT<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> <span style=\"color: #434f54;\">\/\/ set the redPin to be an output <\/span> \r\n<span style=\"color: #d35400;\">pinMode<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">greenPin<\/span><span style=\"color: #434f54;\">,<\/span> <span style=\"color: #00979c;\">OUTPUT<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> <span style=\"color: #434f54;\">\/\/ set the greenPin to be an output <\/span> \r\n<span style=\"color: #d35400;\">pinMode<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">bluePin<\/span><span style=\"color: #434f54;\">,<\/span> <span style=\"color: #00979c;\">OUTPUT<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> <span style=\"color: #434f54;\">\/\/ set the bluePin to be an output <\/span> \r\n<span style=\"color: #000000;\">}<\/span> \r\n<span style=\"color: #00979c;\">void<\/span> <span style=\"color: #5e6d03;\">loop<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">)<\/span> <span style=\"color: #434f54;\">\/\/ run over and over again <\/span> \r\n<span style=\"color: #000000;\">{<\/span> \r\n<span style=\"color: #434f54;\">\/\/ Basic colors: <\/span> \r\n<span style=\"color: #000000;\">color<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">255<\/span><span style=\"color: #434f54;\">,<\/span> <span style=\"color: #000000;\">0<\/span><span style=\"color: #434f54;\">,<\/span> <span style=\"color: #000000;\">0<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> <span style=\"color: #434f54;\">\/\/ turn the RGB LED red <\/span> \r\n<span style=\"color: #d35400;\">delay<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">1000<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> \r\n<span style=\"color: #000000;\">color<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">0<\/span><span style=\"color: #434f54;\">,<\/span><span style=\"color: #000000;\">255<\/span><span style=\"color: #434f54;\">,<\/span> <span style=\"color: #000000;\">0<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> <span style=\"color: #434f54;\">\/\/ turn the RGB LED green <\/span> \r\n<span style=\"color: #d35400;\">delay<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">1000<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> \r\n<span style=\"color: #000000;\">color<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">0<\/span><span style=\"color: #434f54;\">,<\/span> <span style=\"color: #000000;\">0<\/span><span style=\"color: #434f54;\">,<\/span> <span style=\"color: #000000;\">255<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> <span style=\"color: #434f54;\">\/\/ turn the RGB LED blue <\/span> \r\n<span style=\"color: #d35400;\">delay<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">1000<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> \r\n<span style=\"color: #434f54;\">\/\/ Example blended colors: <\/span> \r\n<span style=\"color: #000000;\">color<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">255<\/span><span style=\"color: #434f54;\">,<\/span><span style=\"color: #000000;\">0<\/span><span style=\"color: #434f54;\">,<\/span><span style=\"color: #000000;\">252<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> <span style=\"color: #434f54;\">\/\/ turn the RGB LED red <\/span> \r\n<span style=\"color: #d35400;\">delay<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">1000<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> \r\n<span style=\"color: #000000;\">color<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">237<\/span><span style=\"color: #434f54;\">,<\/span><span style=\"color: #000000;\">109<\/span><span style=\"color: #434f54;\">,<\/span><span style=\"color: #000000;\">0<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> <span style=\"color: #434f54;\">\/\/ turn the RGB LED orange <\/span> \r\n<span style=\"color: #d35400;\">delay<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">1000<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> \r\n<span style=\"color: #000000;\">color<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">255<\/span><span style=\"color: #434f54;\">,<\/span><span style=\"color: #000000;\">215<\/span><span style=\"color: #434f54;\">,<\/span><span style=\"color: #000000;\">0<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> <span style=\"color: #434f54;\">\/\/ turn the RGB LED yellow <\/span> \r\n<span style=\"color: #d35400;\">delay<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">1000<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> \r\n<span style=\"color: #000000;\">color<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">34<\/span><span style=\"color: #434f54;\">,<\/span><span style=\"color: #000000;\">139<\/span><span style=\"color: #434f54;\">,<\/span><span style=\"color: #000000;\">34<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> <span style=\"color: #434f54;\">\/\/ turn the RGB LED green <\/span> \r\n<span style=\"color: #d35400;\">delay<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">1000<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> \r\n<span style=\"color: #000000;\">color<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">0<\/span><span style=\"color: #434f54;\">,<\/span><span style=\"color: #000000;\">112<\/span><span style=\"color: #434f54;\">,<\/span><span style=\"color: #000000;\">255<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> <span style=\"color: #434f54;\">\/\/ turn the RGB LED blue <\/span> \r\n<span style=\"color: #d35400;\">delay<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">1000<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> \r\n<span style=\"color: #000000;\">color<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">0<\/span><span style=\"color: #434f54;\">,<\/span><span style=\"color: #000000;\">46<\/span><span style=\"color: #434f54;\">,<\/span><span style=\"color: #000000;\">90<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> <span style=\"color: #434f54;\">\/\/ turn the RGB LED indigo <\/span> \r\n<span style=\"color: #d35400;\">delay<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">1000<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> \r\n<span style=\"color: #000000;\">color<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">128<\/span><span style=\"color: #434f54;\">,<\/span><span style=\"color: #000000;\">0<\/span><span style=\"color: #434f54;\">,<\/span><span style=\"color: #000000;\">128<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> <span style=\"color: #434f54;\">\/\/ turn the RGB LED purple <\/span> \r\n<span style=\"color: #d35400;\">delay<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">1000<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> \r\n<span style=\"color: #000000;\">}<\/span> \r\n<span style=\"color: #95a5a6;\">\/******************************************************\/<\/span> \r\n<span style=\"color: #00979c;\">void<\/span> <span style=\"color: #000000;\">color<\/span> <span style=\"color: #000000;\">(<\/span><span style=\"color: #00979c;\">unsigned<\/span> <span style=\"color: #00979c;\">char<\/span> <span style=\"color: #000000;\">red<\/span><span style=\"color: #434f54;\">,<\/span> <span style=\"color: #00979c;\">unsigned<\/span> <span style=\"color: #00979c;\">char<\/span> <span style=\"color: #000000;\">green<\/span><span style=\"color: #434f54;\">,<\/span> <span style=\"color: #00979c;\">unsigned<\/span> <span style=\"color: #00979c;\">char<\/span> <span style=\"color: #000000;\">blue<\/span><span style=\"color: #000000;\">)<\/span> \r\n<span style=\"color: #434f54;\">\/\/ the color generating function <\/span> \r\n<span style=\"color: #000000;\">{\r\n<\/span> <span style=\"color: #d35400;\">analogWrite<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">redPin<\/span><span style=\"color: #434f54;\">,<\/span> <span style=\"color: #000000;\">red<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> \r\n<span style=\"color: #d35400;\">analogWrite<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">greenPin<\/span><span style=\"color: #434f54;\">,<\/span> <span style=\"color: #000000;\">green<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> \r\n<span style=\"color: #d35400;\">analogWrite<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">bluePin<\/span><span style=\"color: #434f54;\">,<\/span> <span style=\"color: #000000;\">blue<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> \r\n<span style=\"color: #000000;\">}<\/span><\/pre>\n<h1 id=\"6\">Running Result<\/h1>\n<p>A few seconds after the upload finishes, you should see the RGB LED flash circularly red, green, and blue first, then red, orange, yellow, green, blue, indigo, and purple.<\/p>\n<div align=\"center\"><iframe src=\"https:\/\/www.youtube.com\/embed\/80gb8gVlU7Y\" width=\"853\" height=\"480\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/div>\n<p><a href=\"https:\/\/osoyoo.info\/index.php\/2020\/10\/12\/arduino-basic-lesson-15-i2c-lcd1602-display\/\"><img loading=\"lazy\" class=\"alignnone\" src=\"https:\/\/osoyoo.com\/picture\/Arduino_Graphical_Programming_Kit\/Previous.png\" alt=\"\" width=\"206\" height=\"59\" \/><\/a>\u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0<a href=\"https:\/\/osoyoo.info\/index.php\/2020\/10\/11\/arduino-basic-tutorial-directory\/\"><img loading=\"lazy\" class=\"alignnone\" src=\"https:\/\/osoyoo.com\/picture\/Arduino_Graphical_Programming_Kit\/Tutorial.png\" alt=\"\" width=\"206\" height=\"59\" \/><\/a>\u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0<a href=\"https:\/\/osoyoo.info\/index.php\/2020\/10\/12\/lesson-17-dht11-sensor\/\"><img loading=\"lazy\" class=\"alignright\" src=\"https:\/\/osoyoo.com\/picture\/Arduino_Graphical_Programming_Kit\/Next.png\" alt=\"\" width=\"206\" height=\"59\" \/><\/a><\/p>\n<div align=\"center\">\n<div align=\"center\"><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0\u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0 Buy from US Buy from UK Buy from DE Buy from IT Buy from FR Buy from ES Buy from JP Content Introduction Preparations Hardware Software About the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":158,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[],"_links":{"self":[{"href":"https:\/\/osoyoo.info\/index.php\/wp-json\/wp\/v2\/posts\/99"}],"collection":[{"href":"https:\/\/osoyoo.info\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/osoyoo.info\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/osoyoo.info\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/osoyoo.info\/index.php\/wp-json\/wp\/v2\/comments?post=99"}],"version-history":[{"count":3,"href":"https:\/\/osoyoo.info\/index.php\/wp-json\/wp\/v2\/posts\/99\/revisions"}],"predecessor-version":[{"id":106,"href":"https:\/\/osoyoo.info\/index.php\/wp-json\/wp\/v2\/posts\/99\/revisions\/106"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/osoyoo.info\/index.php\/wp-json\/wp\/v2\/media\/158"}],"wp:attachment":[{"href":"https:\/\/osoyoo.info\/index.php\/wp-json\/wp\/v2\/media?parent=99"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/osoyoo.info\/index.php\/wp-json\/wp\/v2\/categories?post=99"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/osoyoo.info\/index.php\/wp-json\/wp\/v2\/tags?post=99"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}