{"id":2329,"date":"2024-04-10T12:31:35","date_gmt":"2024-04-10T12:31:35","guid":{"rendered":"https:\/\/darjaportnova23.thkit.ee\/wp\/?page_id=2329"},"modified":"2024-05-11T12:21:36","modified_gmt":"2024-05-11T12:21:36","slug":"subject-led-and-rgb-led","status":"publish","type":"page","link":"https:\/\/darjaportnova23.thkit.ee\/wp\/robotics\/tasks-and-topics-on-robotics\/subject-led-and-rgb-led\/","title":{"rendered":"Topic: LED and RGB LEDs"},"content":{"rendered":"\n<p class=\"has-text-align-center\">Start exploring Arduino RGB LEDs with me! Initially, I&#8217;m learning how to use Arduino and RGB LEDs to make lights that change colors and create exciting effects. Consequently, I will share my journey through easy tutorials featuring Arduino RGB LEDs. Moreover, you&#8217;ll see <a href=\"https:\/\/darjaportnova23.thkit.ee\/wp\/robotics\/\">my progress<\/a> with straightforward code examples, detailed Arduino sketches, and vivid photos.<\/p>\n\n\n\n<h2 class=\"wp-block-heading has-text-align-center\" style=\"margin-top:var(--wp--preset--spacing--30);margin-bottom:var(--wp--preset--spacing--30)\">LED (Light Emitting Diodes)<\/h2>\n\n\n\n<div class=\"wp-block-columns alignwide is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<p class=\"has-text-align-left\" style=\"margin-top:var(--wp--preset--spacing--30);margin-right:0;margin-bottom:var(--wp--preset--spacing--30);margin-left:0\">This sketch shows how to make two LEDs\u2014yellow and white\u2014blink alternately. It employs digital pins 13 and 11 for the yellow (LEDY) and white (LEDW) LEDs, respectively. After setting these pins as outputs during the setup phase, the loop continuously alternates these LEDs between on and off states every 500 milliseconds, creating a dynamic flashing effect as the yellow LED lights up while the white LED turns off, and vice versa.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: arduino; title: ; notranslate\" title=\"\">\nconst int LEDY = 13;\nconst int LEDW = 11;\nvoid setup()\n{\n  pinMode(LEDY, OUTPUT);\n  pinMode(LEDW, OUTPUT);\n}\nvoid loop()\n{\n  digitalWrite(LEDY, HIGH);\n  digitalWrite(LEDW, LOW);\n  delay(500);\n  digitalWrite(LEDY, LOW);\n  digitalWrite(LEDW, HIGH);\n  delay(500);\n}\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image size-full\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1741\" height=\"1345\" src=\"https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/image-39.png\" alt=\"\" class=\"wp-image-2427\" srcset=\"https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/image-39.png 1741w, https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/image-39-300x232.png 300w, https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/image-39-1024x791.png 1024w, https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/image-39-768x593.png 768w, https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/image-39-1536x1187.png 1536w, https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/image-39-600x464.png 600w\" sizes=\"(max-width: 1741px) 100vw, 1741px\" \/><\/figure>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<figure class=\"wp-block-image size-full is-style-default\"><img decoding=\"async\" width=\"1014\" height=\"946\" src=\"https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/image-37.png\" alt=\"\" class=\"wp-image-2424\" srcset=\"https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/image-37.png 1014w, https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/image-37-300x280.png 300w, https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/image-37-768x716.png 768w, https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/image-37-600x560.png 600w\" sizes=\"(max-width: 1014px) 100vw, 1014px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img decoding=\"async\" width=\"861\" height=\"484\" src=\"https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/image-38-edited.png\" alt=\"\" class=\"wp-image-2426\" style=\"width:596px;height:auto\" srcset=\"https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/image-38-edited.png 861w, https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/image-38-edited-300x169.png 300w, https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/image-38-edited-768x432.png 768w, https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/image-38-edited-600x337.png 600w\" sizes=\"(max-width: 861px) 100vw, 861px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\" style=\"margin-top:var(--wp--preset--spacing--40);margin-bottom:var(--wp--preset--spacing--40)\"><div class=\"wp-block-embed__wrapper\">\n<iframe title=\"Arduino Robotics:  Dual-Color LED Control\" width=\"500\" height=\"281\" src=\"https:\/\/www.youtube.com\/embed\/IQlqGso5yZI?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><figcaption class=\"wp-element-caption\">Dual-Color LED<\/figcaption><\/figure>\n<\/div>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading alignwide has-text-align-center\">RGB LEDs (Red-Green-Blue Light Emitting Diodes)<\/h2>\n\n\n\n<div class=\"wp-block-columns alignwide is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<p class=\"has-text-align-center\" style=\"margin-top:var(--wp--preset--spacing--30);margin-bottom:var(--wp--preset--spacing--30)\"><em>RGB LEDs are capable of blending red, green, and blue light at various intensities to generate a multitude of colors.<\/em><\/p>\n\n\n\n<p>This particular Arduino sketch focuses on managing an RGB LED to cycle through primary colors, their combinations, and a full color spectrum.<\/p>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\"><div class=\"wp-block-syntaxhighlighter-code aligncenter\"><pre class=\"brush: arduino; title: ; notranslate\" title=\"\">\n\/\/ Pins connected to the red, green, blue LED\nconst int RED_PIN = 11;\nconst int GREEN_PIN = 9;\nconst int BLUE_PIN = 10;\n\/\/ Display time variable, currently unused\nint DISPLAY_TIME = 100;\nvoid setup()\n{\n  \/\/ Set the LED pins as output\n  pinMode(RED_PIN, OUTPUT);\n  pinMode(GREEN_PIN, OUTPUT);\n  pinMode(BLUE_PIN, OUTPUT);\n}\nvoid loop() {\n\/\/ Function to display primary and mixed colors\nmainColors();\n\/\/ Function to display a color spectrum transition\nshowSpectrum();\n}\nvoid mainColors() {\n  \/\/ Turn all LEDs off initially\n  digitalWrite(RED_PIN, LOW);\n  digitalWrite(GREEN_PIN, LOW);\n  digitalWrite(BLUE_PIN, LOW);\n  delay(1000); \/\/ Wait for 1 second\n  \/\/ Red only\n  digitalWrite(RED_PIN, HIGH);\n  digitalWrite(GREEN_PIN, LOW);\n  digitalWrite(BLUE_PIN, LOW);\n  delay(1000);\n  \/\/ Green only\n  digitalWrite(RED_PIN, LOW);\n  digitalWrite(GREEN_PIN, HIGH);\n  digitalWrite(BLUE_PIN, LOW);\n  delay(1000);\n  \/\/ Blue only\n  digitalWrite(RED_PIN, LOW);\n  digitalWrite(GREEN_PIN, LOW);\n  digitalWrite(BLUE_PIN, HIGH);\n  delay(1000);\n  \/\/ Yellow (red + green)\n  digitalWrite(RED_PIN, HIGH);\n  digitalWrite(GREEN_PIN, HIGH);\n  digitalWrite(BLUE_PIN, LOW);\n  delay(1000);\n  \/\/ Cyan (green + blue)\n  digitalWrite(RED_PIN, LOW);\n  digitalWrite(GREEN_PIN, HIGH);\n  digitalWrite(BLUE_PIN, HIGH);\n  delay(1000);\n  \/\/ Magenta (red + blue)\n  digitalWrite(RED_PIN, HIGH);\n  digitalWrite(GREEN_PIN, LOW);\n  digitalWrite(BLUE_PIN, HIGH);\n  delay(1000);\n  \/\/ White (red + green + blue)\n  digitalWrite(RED_PIN, HIGH);\n  digitalWrite(GREEN_PIN, HIGH);\n  digitalWrite(BLUE_PIN, HIGH);\n  delay(1000);\n}\n\/\/ Function to transition through a spectrum of colors\nvoid showSpectrum()\n{\n  int x;\n  for (x = 0; x &lt; 768; x++)\n  {\n    \/\/ Compute and show color based on x\n    showRGB(x);\n    \/\/ Delay for smooth transition\n    delay(10);\n  }\n}\n\/\/ Function to calculate and set RGB intensity\n\/\/ Color transitions from red to green to blue and back to red\nvoid showRGB(int color)\n{\n  int redIntensity, greenIntensity, blueIntensity;\n\/\/ Calculate intensity based on the color wheel position\n  if (color &lt;= 255)       \/\/ red to green\n  {\n    redIntensity = 255 - color;\n    greenIntensity = color;\n    blueIntensity = 0;\n  }\n  else if (color &lt;= 511)  \/\/ green to blue\n  {\n    redIntensity = 0;\n    greenIntensity = 255 - (color - 256); \n    blueIntensity = (color - 256);        \n  }\n  else if (color &gt;= 512)  \/\/ blue to red\n  {\n    redIntensity = (color - 512);        \n    greenIntensity = 0;                  \n    blueIntensity = 255 - (color - 512);  \n  }\n  \/\/ Apply the calculated intensities to the LEDs\n  analogWrite(RED_PIN, redIntensity);\n  analogWrite(BLUE_PIN, blueIntensity);\n  analogWrite(GREEN_PIN, greenIntensity);\n}\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"993\" height=\"775\" src=\"https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/image-41.png\" alt=\"\" class=\"wp-image-2464\" srcset=\"https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/image-41.png 993w, https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/image-41-300x234.png 300w, https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/image-41-768x599.png 768w, https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/image-41-600x468.png 600w\" sizes=\"(max-width: 993px) 100vw, 993px\" \/><\/figure>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"padding-top:var(--wp--preset--spacing--20);padding-bottom:var(--wp--preset--spacing--20)\">\n<p>Here&#8217;s a detailed description of the code:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The script begins by defining the pins connected to the red (11), green (9), and blue (10) components of an RGB LED. Subsequently, in the <code><em>setup()<\/em><\/code> function, these pins are configured as outputs, enabling control over the LED.<\/li>\n\n\n\n<li>The<em> <code>mainColors()<\/code><\/em> function. It controls the RGB LED to sequentially illuminate red, green, blue, yellow, cyan, magenta, and white. Each color is displayed for one second, demonstrating how to mix different LED colors by activating multiple LEDs at the same time.<\/li>\n\n\n\n<li>Additionally, the <code><em>showSpectrum()<\/em><\/code> function enhances the visual display by looping through color values and adjusting each LED&#8217;s intensity. This process ensures smooth transitions between colors.<\/li>\n\n\n\n<li>The <code><em>showRGB(int color)<\/em><\/code> function plays a crucial role. It precisely calculates the intensity of each LED based on the provided color value, handling color transitions in three distinct phases: from red to green (0-255), from green to blue (256-511), and from blue back to red (512-767). The calculated intensities are then meticulously applied to the LED pins via <code><em>analogWrite()<\/em><\/code>.<\/li>\n\n\n\n<li>Finally, the <code><em>loop()<\/em><\/code> function ensures the display never ends. It continuously calls <code><em>mainColors()<\/em><\/code> and <code><em>showSpectrum()<\/em><\/code>, showcasing the programmed color patterns and transitions without interruption.<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"784\" height=\"448\" src=\"https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/image-40.png\" alt=\"\" class=\"wp-image-2463\" srcset=\"https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/image-40.png 784w, https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/image-40-300x171.png 300w, https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/image-40-768x439.png 768w, https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/image-40-600x343.png 600w\" sizes=\"(max-width: 784px) 100vw, 784px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"664\" height=\"711\" src=\"https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/image-42.png\" alt=\"\" class=\"wp-image-2465\" srcset=\"https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/image-42.png 664w, https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/image-42-280x300.png 280w, https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/image-42-600x642.png 600w\" sizes=\"(max-width: 664px) 100vw, 664px\" \/><figcaption class=\"wp-element-caption\"><a href=\"https:\/\/www.tinkercad.com\/\">Tinkercad<\/a><\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"576\" src=\"https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/IMG_4180-1024x576.jpeg\" alt=\"\" class=\"wp-image-2466\" srcset=\"https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/IMG_4180-1024x576.jpeg 1024w, https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/IMG_4180-300x169.jpeg 300w, https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/IMG_4180-768x432.jpeg 768w, https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/IMG_4180-1536x864.jpeg 1536w, https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/IMG_4180-2048x1152.jpeg 2048w, https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/IMG_4180-600x338.jpeg 600w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe title=\"Dynamic RGB LED Control with Arduino\" width=\"500\" height=\"281\" src=\"https:\/\/www.youtube.com\/embed\/agf3sG-8UKU?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><figcaption class=\"wp-element-caption\">RGB LED<\/figcaption><\/figure>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading has-text-align-center\">Traffic lights<\/h2>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<p>This segment of an Arduino sketch sets up a traffic light system with both car and pedestrian lights, and it includes a mode for daytime and nighttime operation.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code><em>changeTimestamp<\/em><\/code> is an unsigned long variable that will hold the timestamp of the last mode change from day to night or vice versa. It is initially set to 0<\/li>\n\n\n\n<li><code><em>isDayMode<\/em><\/code> is a boolean variable that indicates whether the system is currently in day mode (<code>true<\/code>) or night mode (<code>false<\/code>). It is initially set to <code>true<\/code>, meaning the system will start in day mode.<\/li>\n<\/ul>\n\n\n<div class=\"wp-block-syntaxhighlighter-code aligncenter\"><pre class=\"brush: arduino; title: ; notranslate\" title=\"\">\nconst int RED_LED = 13;       \/\/ Car red light\nconst int YELLOW_LED = 12;    \/\/ Car yellow light\nconst int GREEN_LED = 11;     \/\/ Car green light\nconst int PED_RED_LED = 6;    \/\/ Pedestrian red light\nconst int PED_GREEN_LED = 5;  \/\/ Pedestrian green light\n\n\/\/ 1 minute for example\nconst long DAY_MODE_DURATION = 60000;\nconst long NIGHT_MODE_DURATION = 60000;\n\/\/ Delay for flashing light\nconst int FLASHING_DELAY = 1000;\n\nunsigned long changeTimestamp = 0;\nbool isDayMode = true;\n<\/pre><\/div>\n\n\n<p>The <code><em>setup()<\/em><\/code> function in an Arduino sketch is called once when the program starts. It&#8217;s used to initialize the digital pins as inputs or outputs, start communication protocols, etc.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: arduino; title: ; notranslate\" title=\"\">\nvoid setup() {\n  pinMode(RED_LED, OUTPUT);\n  pinMode(YELLOW_LED, OUTPUT);\n  pinMode(GREEN_LED, OUTPUT);\n  pinMode(PED_RED_LED, OUTPUT);\n  pinMode(PED_GREEN_LED, OUTPUT);\n}\n<\/pre><\/div>\n\n\n<p>The<em> <code>loop()<\/code><\/em> function is executing over and over again, indefinitely.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The function starts by capturing the current time since the Arduino started running with<em> <code>millis()<\/code><\/em>, which returns the number of milliseconds passed.<\/li>\n\n\n\n<li>It then checks if the current mode should be changed. This is based on how much time has passed since the last change (<code><em>changeTimestamp<\/em><\/code>).<\/li>\n\n\n\n<li>If it&#8217;s day mode (<code><em>isDayMode<\/em><\/code> is true) and the time elapsed since <code><em>changeTimestamp<\/em><\/code> exceeds <code><em>DAY_MODE_DURATION<\/em><\/code>, the mode switches to night mode by setting<em> <code>isDayMode<\/code><\/em> to false. It also updates <code><em>changeTimestamp<\/em><\/code> to the current time.<\/li>\n\n\n\n<li>Conversely, if it&#8217;s night mode (<code><em>isDayMode<\/em><\/code> is false) and the time since <code><em>changeTimestamp<\/em><\/code> is greater than <code><em>NIGHT_MODE_DURATION<\/em><\/code>, it switches back to day mode, again updating <code><em>changeTimestamp<\/em><\/code>.<\/li>\n<\/ul>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: arduino; title: ; notranslate\" title=\"\">\nvoid loop() {\n  unsigned long currentTimestamp = millis();\n  \/\/ if we should change the mode\n  if (isDayMode &amp;&amp; currentTimestamp - changeTimestamp &gt; DAY_MODE_DURATION) {\n    isDayMode = false;\n    changeTimestamp = currentTimestamp;\n  } else if (!isDayMode &amp;&amp; currentTimestamp - changeTimestamp &gt; NIGHT_MODE_DURATION) {\n    isDayMode = true;\n    changeTimestamp = currentTimestamp;\n  }\n\n  if (isDayMode) {\n    dayMode();\n  } else {\n    nightMode();\n  }\n}\n<\/pre><\/div><\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"878\" height=\"1024\" src=\"https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/image-47-878x1024.png\" alt=\"\" class=\"wp-image-2502\" srcset=\"https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/image-47-878x1024.png 878w, https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/image-47-257x300.png 257w, https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/image-47-768x896.png 768w, https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/image-47-1316x1536.png 1316w, https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/image-47-600x700.png 600w, https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/image-47.png 1330w\" sizes=\"(max-width: 878px) 100vw, 878px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"571\" src=\"https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/image-49-1024x571.png\" alt=\"\" class=\"wp-image-2504\" srcset=\"https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/image-49-1024x571.png 1024w, https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/image-49-300x167.png 300w, https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/image-49-768x428.png 768w, https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/image-49-600x335.png 600w, https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/image-49.png 1406w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-embed aligncenter is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe title=\"Arduino Traffic Lights: Day &amp; Night Modes for Vehicles and Pedestrians\" width=\"500\" height=\"281\" src=\"https:\/\/www.youtube.com\/embed\/BuytrI19po4?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><figcaption class=\"wp-element-caption\">Traffic Lights: Day &amp; Night Mode<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"576\" src=\"https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/IMG_4217-3-1024x576.jpg\" alt=\"\" class=\"wp-image-2583\" srcset=\"https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/IMG_4217-3-1024x576.jpg 1024w, https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/IMG_4217-3-300x169.jpg 300w, https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/IMG_4217-3-768x432.jpg 768w, https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/IMG_4217-3-1536x864.jpg 1536w, https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/IMG_4217-3-2048x1152.jpg 2048w, https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/IMG_4217-3-600x337.jpg 600w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"998\" height=\"776\" src=\"https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/image-48.png\" alt=\"\" class=\"wp-image-2503\" srcset=\"https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/image-48.png 998w, https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/image-48-300x233.png 300w, https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/image-48-768x597.png 768w, https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/image-48-600x467.png 600w\" sizes=\"(max-width: 998px) 100vw, 998px\" \/><\/figure>\n<\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<p>Traffic light sequence for day mode<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: arduino; title: ; notranslate\" title=\"\">\nvoid dayMode() {\n  digitalWrite(GREEN_LED, HIGH);\n  digitalWrite(YELLOW_LED, LOW);\n  digitalWrite(RED_LED, LOW);\n  \n  digitalWrite(PED_GREEN_LED, LOW);\n  digitalWrite(PED_RED_LED, HIGH);\n  delay(5000);   \/\/ Cars - Green, Pedestrians - Red\n\n\n  digitalWrite(GREEN_LED, LOW);\n  digitalWrite(YELLOW_LED, HIGH);\n  delay(1000);   \/\/ Yellow for 1 second\n\n\n  digitalWrite(YELLOW_LED, LOW);\n  digitalWrite(RED_LED, HIGH);\n\n  digitalWrite(PED_RED_LED, LOW);\n  digitalWrite(PED_GREEN_LED, HIGH);\n  delay(5000);  \/\/ Red and pedestrian green for 5 seconds\n\n\n  digitalWrite(RED_LED, LOW);\n  digitalWrite(YELLOW_LED, HIGH);\n  \n  digitalWrite(PED_RED_LED, HIGH);\n  digitalWrite(PED_GREEN_LED, LOW);\n  delay(1000);  \/\/ Pedestrian red and car yellow\n}\n<\/pre><\/div><\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<p>Night mode traffic light sequence<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code alignwide\"><pre class=\"brush: arduino; title: ; notranslate\" title=\"\">\nvoid nightMode() {\n\n  \/\/ All lights off except yellow, which flashes\n  digitalWrite(RED_LED, LOW);\n  digitalWrite(GREEN_LED, LOW);\n\n  \/\/ Pedestrian red is always on\n  digitalWrite(PED_GREEN_LED, LOW);\n  digitalWrite(PED_RED_LED, HIGH);\n  \n\n  \/\/ Flashing yellow light\n  digitalWrite(YELLOW_LED, HIGH);\n  delay(FLASHING_DELAY);\n  digitalWrite(YELLOW_LED, LOW);\n  delay(FLASHING_DELAY);\n}\n<\/pre><\/div><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Start exploring Arduino RGB LEDs with me! Initially, I&#8217;m learning how to use Arduino and RGB LEDs to make lights that change colors and create exciting effects. Consequently, I will share my journey through easy tutorials featuring Arduino RGB LEDs. Moreover, you&#8217;ll see my progress with straightforward code examples, detailed Arduino sketches, and vivid photos. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":2366,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-2329","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Topic: LED and RGB LEDs - Darja Suhhanova (Portnova) - Portfolio<\/title>\n<meta name=\"description\" content=\"Discover the world of Arduino RGB LEDs with detailed tutorials. Learn how to enhance your electronics projects using both standard and RGB LEDs through easy-to-follow code, Arduino sketches, and insightful photos.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/darjaportnova23.thkit.ee\/wp\/robotics\/tasks-and-topics-on-robotics\/subject-led-and-rgb-led\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Topic: LED and RGB LEDs - Darja Suhhanova (Portnova) - Portfolio\" \/>\n<meta property=\"og:description\" content=\"Discover the world of Arduino RGB LEDs with detailed tutorials. Learn how to enhance your electronics projects using both standard and RGB LEDs through easy-to-follow code, Arduino sketches, and insightful photos.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/darjaportnova23.thkit.ee\/wp\/robotics\/tasks-and-topics-on-robotics\/subject-led-and-rgb-led\/\" \/>\n<meta property=\"og:site_name\" content=\"Darja Suhhanova (Portnova) - Portfolio\" \/>\n<meta property=\"article:modified_time\" content=\"2024-05-11T12:21:36+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/image-39.png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/darjaportnova23.thkit.ee\\\/wp\\\/robotics\\\/tasks-and-topics-on-robotics\\\/subject-led-and-rgb-led\\\/\",\"url\":\"https:\\\/\\\/darjaportnova23.thkit.ee\\\/wp\\\/robotics\\\/tasks-and-topics-on-robotics\\\/subject-led-and-rgb-led\\\/\",\"name\":\"Topic: LED and RGB LEDs - Darja Suhhanova (Portnova) - Portfolio\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/darjaportnova23.thkit.ee\\\/wp\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/darjaportnova23.thkit.ee\\\/wp\\\/robotics\\\/tasks-and-topics-on-robotics\\\/subject-led-and-rgb-led\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/darjaportnova23.thkit.ee\\\/wp\\\/robotics\\\/tasks-and-topics-on-robotics\\\/subject-led-and-rgb-led\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/darjaportnova23.thkit.ee\\\/wp\\\/wp-content\\\/uploads\\\/2024\\\/04\\\/image-39.png\",\"datePublished\":\"2024-04-10T12:31:35+00:00\",\"dateModified\":\"2024-05-11T12:21:36+00:00\",\"description\":\"Discover the world of Arduino RGB LEDs with detailed tutorials. Learn how to enhance your electronics projects using both standard and RGB LEDs through easy-to-follow code, Arduino sketches, and insightful photos.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/darjaportnova23.thkit.ee\\\/wp\\\/robotics\\\/tasks-and-topics-on-robotics\\\/subject-led-and-rgb-led\\\/#breadcrumb\"},\"inLanguage\":\"en\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/darjaportnova23.thkit.ee\\\/wp\\\/robotics\\\/tasks-and-topics-on-robotics\\\/subject-led-and-rgb-led\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en\",\"@id\":\"https:\\\/\\\/darjaportnova23.thkit.ee\\\/wp\\\/robotics\\\/tasks-and-topics-on-robotics\\\/subject-led-and-rgb-led\\\/#primaryimage\",\"url\":\"https:\\\/\\\/darjaportnova23.thkit.ee\\\/wp\\\/wp-content\\\/uploads\\\/2024\\\/04\\\/image-39.png\",\"contentUrl\":\"https:\\\/\\\/darjaportnova23.thkit.ee\\\/wp\\\/wp-content\\\/uploads\\\/2024\\\/04\\\/image-39.png\",\"width\":1741,\"height\":1345},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/darjaportnova23.thkit.ee\\\/wp\\\/robotics\\\/tasks-and-topics-on-robotics\\\/subject-led-and-rgb-led\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/darjaportnova23.thkit.ee\\\/wp\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Robotics\",\"item\":\"https:\\\/\\\/darjaportnova23.thkit.ee\\\/wp\\\/robotics\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Tasks and topics on robotics\",\"item\":\"https:\\\/\\\/darjaportnova23.thkit.ee\\\/wp\\\/robotics\\\/tasks-and-topics-on-robotics\\\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Topic: LED and RGB LEDs\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/darjaportnova23.thkit.ee\\\/wp\\\/#website\",\"url\":\"https:\\\/\\\/darjaportnova23.thkit.ee\\\/wp\\\/\",\"name\":\"Darja Suhhanova (Portnova) - Portfolio\",\"description\":\"Junior Software Developer\",\"publisher\":{\"@id\":\"https:\\\/\\\/darjaportnova23.thkit.ee\\\/wp\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/darjaportnova23.thkit.ee\\\/wp\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/darjaportnova23.thkit.ee\\\/wp\\\/#organization\",\"name\":\"Darja Suhhanova (Portnova) - Portfolio\",\"url\":\"https:\\\/\\\/darjaportnova23.thkit.ee\\\/wp\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en\",\"@id\":\"https:\\\/\\\/darjaportnova23.thkit.ee\\\/wp\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/darjaportnova23.thkit.ee\\\/wp\\\/wp-content\\\/uploads\\\/2023\\\/11\\\/logoDP-7.png\",\"contentUrl\":\"https:\\\/\\\/darjaportnova23.thkit.ee\\\/wp\\\/wp-content\\\/uploads\\\/2023\\\/11\\\/logoDP-7.png\",\"width\":551,\"height\":568,\"caption\":\"Darja Suhhanova (Portnova) - Portfolio\"},\"image\":{\"@id\":\"https:\\\/\\\/darjaportnova23.thkit.ee\\\/wp\\\/#\\\/schema\\\/logo\\\/image\\\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Topic: LED and RGB LEDs - Darja Suhhanova (Portnova) - Portfolio","description":"Discover the world of Arduino RGB LEDs with detailed tutorials. Learn how to enhance your electronics projects using both standard and RGB LEDs through easy-to-follow code, Arduino sketches, and insightful photos.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/darjaportnova23.thkit.ee\/wp\/robotics\/tasks-and-topics-on-robotics\/subject-led-and-rgb-led\/","og_locale":"en_US","og_type":"article","og_title":"Topic: LED and RGB LEDs - Darja Suhhanova (Portnova) - Portfolio","og_description":"Discover the world of Arduino RGB LEDs with detailed tutorials. Learn how to enhance your electronics projects using both standard and RGB LEDs through easy-to-follow code, Arduino sketches, and insightful photos.","og_url":"https:\/\/darjaportnova23.thkit.ee\/wp\/robotics\/tasks-and-topics-on-robotics\/subject-led-and-rgb-led\/","og_site_name":"Darja Suhhanova (Portnova) - Portfolio","article_modified_time":"2024-05-11T12:21:36+00:00","og_image":[{"url":"https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/image-39.png","type":"","width":"","height":""}],"twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/darjaportnova23.thkit.ee\/wp\/robotics\/tasks-and-topics-on-robotics\/subject-led-and-rgb-led\/","url":"https:\/\/darjaportnova23.thkit.ee\/wp\/robotics\/tasks-and-topics-on-robotics\/subject-led-and-rgb-led\/","name":"Topic: LED and RGB LEDs - Darja Suhhanova (Portnova) - Portfolio","isPartOf":{"@id":"https:\/\/darjaportnova23.thkit.ee\/wp\/#website"},"primaryImageOfPage":{"@id":"https:\/\/darjaportnova23.thkit.ee\/wp\/robotics\/tasks-and-topics-on-robotics\/subject-led-and-rgb-led\/#primaryimage"},"image":{"@id":"https:\/\/darjaportnova23.thkit.ee\/wp\/robotics\/tasks-and-topics-on-robotics\/subject-led-and-rgb-led\/#primaryimage"},"thumbnailUrl":"https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/image-39.png","datePublished":"2024-04-10T12:31:35+00:00","dateModified":"2024-05-11T12:21:36+00:00","description":"Discover the world of Arduino RGB LEDs with detailed tutorials. Learn how to enhance your electronics projects using both standard and RGB LEDs through easy-to-follow code, Arduino sketches, and insightful photos.","breadcrumb":{"@id":"https:\/\/darjaportnova23.thkit.ee\/wp\/robotics\/tasks-and-topics-on-robotics\/subject-led-and-rgb-led\/#breadcrumb"},"inLanguage":"en","potentialAction":[{"@type":"ReadAction","target":["https:\/\/darjaportnova23.thkit.ee\/wp\/robotics\/tasks-and-topics-on-robotics\/subject-led-and-rgb-led\/"]}]},{"@type":"ImageObject","inLanguage":"en","@id":"https:\/\/darjaportnova23.thkit.ee\/wp\/robotics\/tasks-and-topics-on-robotics\/subject-led-and-rgb-led\/#primaryimage","url":"https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/image-39.png","contentUrl":"https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2024\/04\/image-39.png","width":1741,"height":1345},{"@type":"BreadcrumbList","@id":"https:\/\/darjaportnova23.thkit.ee\/wp\/robotics\/tasks-and-topics-on-robotics\/subject-led-and-rgb-led\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/darjaportnova23.thkit.ee\/wp\/"},{"@type":"ListItem","position":2,"name":"Robotics","item":"https:\/\/darjaportnova23.thkit.ee\/wp\/robotics\/"},{"@type":"ListItem","position":3,"name":"Tasks and topics on robotics","item":"https:\/\/darjaportnova23.thkit.ee\/wp\/robotics\/tasks-and-topics-on-robotics\/"},{"@type":"ListItem","position":4,"name":"Topic: LED and RGB LEDs"}]},{"@type":"WebSite","@id":"https:\/\/darjaportnova23.thkit.ee\/wp\/#website","url":"https:\/\/darjaportnova23.thkit.ee\/wp\/","name":"Darja Suhhanova (Portnova) - Portfolio","description":"Junior Software Developer","publisher":{"@id":"https:\/\/darjaportnova23.thkit.ee\/wp\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/darjaportnova23.thkit.ee\/wp\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en"},{"@type":"Organization","@id":"https:\/\/darjaportnova23.thkit.ee\/wp\/#organization","name":"Darja Suhhanova (Portnova) - Portfolio","url":"https:\/\/darjaportnova23.thkit.ee\/wp\/","logo":{"@type":"ImageObject","inLanguage":"en","@id":"https:\/\/darjaportnova23.thkit.ee\/wp\/#\/schema\/logo\/image\/","url":"https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2023\/11\/logoDP-7.png","contentUrl":"https:\/\/darjaportnova23.thkit.ee\/wp\/wp-content\/uploads\/2023\/11\/logoDP-7.png","width":551,"height":568,"caption":"Darja Suhhanova (Portnova) - Portfolio"},"image":{"@id":"https:\/\/darjaportnova23.thkit.ee\/wp\/#\/schema\/logo\/image\/"}}]}},"_links":{"self":[{"href":"https:\/\/darjaportnova23.thkit.ee\/wp\/wp-json\/wp\/v2\/pages\/2329","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/darjaportnova23.thkit.ee\/wp\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/darjaportnova23.thkit.ee\/wp\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/darjaportnova23.thkit.ee\/wp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/darjaportnova23.thkit.ee\/wp\/wp-json\/wp\/v2\/comments?post=2329"}],"version-history":[{"count":61,"href":"https:\/\/darjaportnova23.thkit.ee\/wp\/wp-json\/wp\/v2\/pages\/2329\/revisions"}],"predecessor-version":[{"id":2754,"href":"https:\/\/darjaportnova23.thkit.ee\/wp\/wp-json\/wp\/v2\/pages\/2329\/revisions\/2754"}],"up":[{"embeddable":true,"href":"https:\/\/darjaportnova23.thkit.ee\/wp\/wp-json\/wp\/v2\/pages\/2366"}],"wp:attachment":[{"href":"https:\/\/darjaportnova23.thkit.ee\/wp\/wp-json\/wp\/v2\/media?parent=2329"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}