{"id":253,"date":"2023-01-11T17:19:32","date_gmt":"2023-01-11T17:19:32","guid":{"rendered":"https:\/\/trewest.dev\/blog\/?p=253"},"modified":"2023-12-05T09:34:34","modified_gmt":"2023-12-05T09:34:34","slug":"arduino-light-effects","status":"publish","type":"post","link":"https:\/\/trewest.dev\/blog\/index.php\/2023\/01\/11\/arduino-light-effects\/","title":{"rendered":"Arduino Light effects"},"content":{"rendered":"<div class=\"wp-post-series-box series-project-overviews wp-post-series-box--expandable\">\n\t\t\t<input id=\"collapsible-series-project-overviews69e8ce2b0aaf8\" class=\"wp-post-series-box__toggle_checkbox\" type=\"checkbox\">\n\t\n\t<label\n\t\tclass=\"wp-post-series-box__label\"\n\t\t\t\t\tfor=\"collapsible-series-project-overviews69e8ce2b0aaf8\"\n\t\t\ttabindex=\"0\"\n\t\t\t\t>\n\t\t<p class=\"wp-post-series-box__name wp-post-series-name\">\n\t\t\tThis is post 5 of 21 in the series <em>&ldquo;Project Overviews&rdquo;<\/em>\t\t<\/p>\n\t\t\t\t\t<div class=\"wp-post-series-box__description wp-post-series-description\">\n\t\t\t\t<p>A series of posts detailing and highlighting projects that I&#8217;ve made.<\/p>\n\t\t\t<\/div>\n\t\t\t<\/label>\n\n\t\t\t<div class=\"wp-post-series-box__posts\">\n\t\t\t<ol>\n\t\t\t\t\t\t\t\t\t<li><a href=\"https:\/\/trewest.dev\/blog\/index.php\/2023\/01\/10\/project-bugtrakt\/\">Project: Bugtrakt<\/a><\/li>\n\t\t\t\t\t\t\t\t\t<li><a href=\"https:\/\/trewest.dev\/blog\/index.php\/2023\/01\/10\/project-imgalib\/\">Project: Imgalib<\/a><\/li>\n\t\t\t\t\t\t\t\t\t<li><a href=\"https:\/\/trewest.dev\/blog\/index.php\/2023\/01\/10\/project-go-fish\/\">Project: Go Fish!<\/a><\/li>\n\t\t\t\t\t\t\t\t\t<li><a href=\"https:\/\/trewest.dev\/blog\/index.php\/2023\/01\/11\/project-trewest-dev\/\">Project: trewest.dev<\/a><\/li>\n\t\t\t\t\t\t\t\t\t<li><span class=\"wp-post-series-box__current\">Arduino Light effects<\/span><\/li>\n\t\t\t\t\t\t\t\t\t<li><a href=\"https:\/\/trewest.dev\/blog\/index.php\/2023\/01\/11\/project-mini-stacker\/\">Project: Mini Stacker<\/a><\/li>\n\t\t\t\t\t\t\t\t\t<li><a href=\"https:\/\/trewest.dev\/blog\/index.php\/2023\/01\/12\/project-arduino-nes-controller\/\">Project: Arduino NES Controller<\/a><\/li>\n\t\t\t\t\t\t\t\t\t<li><a href=\"https:\/\/trewest.dev\/blog\/index.php\/2023\/01\/12\/project-metroidvania-like\/\">Project: Metroidvania-Like<\/a><\/li>\n\t\t\t\t\t\t\t\t\t<li><a href=\"https:\/\/trewest.dev\/blog\/index.php\/2023\/01\/12\/project-susminer\/\">Project: Susminer<\/a><\/li>\n\t\t\t\t\t\t\t\t\t<li><a href=\"https:\/\/trewest.dev\/blog\/index.php\/2023\/01\/12\/project-farming-demo\/\">Project: Farming Demo<\/a><\/li>\n\t\t\t\t\t\t\t\t\t<li><a href=\"https:\/\/trewest.dev\/blog\/index.php\/2023\/01\/13\/project-vrc-basement\/\">Project: VRC Basement<\/a><\/li>\n\t\t\t\t\t\t\t\t\t<li><a href=\"https:\/\/trewest.dev\/blog\/index.php\/2023\/01\/13\/project-hash-clear\/\">Project: Hash Clear<\/a><\/li>\n\t\t\t\t\t\t\t\t\t<li><a href=\"https:\/\/trewest.dev\/blog\/index.php\/2023\/01\/13\/project-titan-help\/\">Project: Titan Help<\/a><\/li>\n\t\t\t\t\t\t\t\t\t<li><a href=\"https:\/\/trewest.dev\/blog\/index.php\/2023\/01\/13\/project-computer-craft-scripts\/\">Project: Computer Craft Scripts<\/a><\/li>\n\t\t\t\t\t\t\t\t\t<li><a href=\"https:\/\/trewest.dev\/blog\/index.php\/2023\/01\/15\/project-esp8266-plant-watering\/\">Project: ESP8266 Plant Watering<\/a><\/li>\n\t\t\t\t\t\t\t\t\t<li><a href=\"https:\/\/trewest.dev\/blog\/index.php\/2023\/01\/15\/project-golf-demo\/\">Project: Golf Demo<\/a><\/li>\n\t\t\t\t\t\t\t\t\t<li><a href=\"https:\/\/trewest.dev\/blog\/index.php\/2023\/01\/15\/project-ghost-holic\/\">Project: Ghost Holic<\/a><\/li>\n\t\t\t\t\t\t\t\t\t<li><a href=\"https:\/\/trewest.dev\/blog\/index.php\/2023\/03\/27\/project-multi-chat-viewer\/\">Project: Multi-Chat Viewer<\/a><\/li>\n\t\t\t\t\t\t\t\t\t<li><a href=\"https:\/\/trewest.dev\/blog\/index.php\/2024\/08\/22\/project-interview-simulator\/\">Project: Interview Simulator<\/a><\/li>\n\t\t\t\t\t\t\t\t\t<li><a href=\"https:\/\/trewest.dev\/blog\/index.php\/2024\/10\/18\/project-healers-journey\/\">Project: Healer&#8217;s Journey<\/a><\/li>\n\t\t\t\t\t\t\t\t\t<li><a href=\"https:\/\/trewest.dev\/blog\/index.php\/2024\/10\/18\/project-biota\/\">Project: Biota<\/a><\/li>\n\t\t\t\t\t\t\t<\/ol>\n\t\t<\/div>\n\t<\/div>\n\n<p>Status: Complete<br>Type: Microcontroller<br>Technology: Arduino, PlatformIO, Arduino UNO, C++<\/p>\n\n\n\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link wp-element-button\" href=\"https;\/\/trewest.dev\">Return to Portfolio<\/a><\/div>\n<\/div>\n\n\n\n<p>In November of 2021 my interest in Arduino, something I had vaguely known of for years.  It wasn&#8217;t until someone on Youtube who goes by Dave&#8217;s Garage made a video that showed up in my recommended feed going over the programming of WS2812B ARGB Strip lights.  And so I promptly did my own in a Arduino Emulator which basically allows you to code everything without the physical hardware.   Anyhow, the code is below.<br><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Comet Effect<\/h2>\n\n\n\n<figure class=\"wp-block-video\"><video height=\"720\" style=\"aspect-ratio: 1080 \/ 720;\" width=\"1080\" controls muted src=\"https:\/\/trewest.dev\/blog\/wp-content\/uploads\/2023\/01\/20211102-025839-1.m4v\"><\/video><figcaption class=\"wp-element-caption\">This effect basically has a line of light traveling up and down the strip<\/figcaption><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/Simple Comet Effect\n\/\/Designed for WS2812B LED strips,\n\/\/Tested on an Arduino Uno\n\/\/Using the FastLED Library\n\/\/Copyright William West 2021\n#include &lt;Arduino.h&gt;\n#include &lt;FastLED.h&gt;\n\n#define STRIP_SIZE 120 \/\/ Length of the LED Strip\n#define FPS 60 \/\/ Frames per second, speed is tied to FPS\nCRGB leds &#91;STRIP_SIZE]; \/\/ Creating the LEDS array\n\n\n\nvoid setup() {\n  \/\/ put your setup code here, to run once:\n\n  \/\/ tell FastLED there's 30 NEOPIXEL leds on pin 9\n  FastLED.addLeds&lt;NEOPIXEL, 9&gt;(leds, 150);\n}\nint comet = 12; \/\/ Length of the Comet\nint r = 255; \/\/ red\nint g = 255; \/\/ green\nint b = 0; \/\/ blue\n\nint pos = 50; \/\/ Position of the Comet\nbool dir = false; \/\/ Direction false = up, true = down\nvoid loop() {\n  int trail = 1; \/\/ Iterator for dimming the trail\n  if (dir)  \/\/ If going down\n  {\n    pos--; \/\/ Position goes downward\n    for (int i = pos; i &lt; pos + comet; i++ ) { \/\/ Then start a for loop\n      FastLED.setBrightness(255\/trail);\/\/Setting brightness\n      if (i &gt; -1 &amp;&amp; i &lt; STRIP_SIZE) { \/\/ Checking if we can draw\n      leds&#91;i] = CRGB(r\/trail,g\/trail,b\/trail); \/\/ Drawing\n      }\n      else \n      {\n        break; \/\/ Breaking the loop if we cant, reducing unecessary cpu use\n      }\n      trail++; \/\/ iterate trail\n    }\n    if (pos+comet+1 &lt; STRIP_SIZE) \/\/Checking if we're not at the edge\n    {\n      leds&#91;pos+comet+1] = CRGB::Black; \/\/ If not clean the last pixel on the previous trail\n    }\n  }\n  else \n  {\n    pos++;\n    for (int i = pos; i &gt; pos - comet; i--) {\n      FastLED.setBrightness(255\/trail);\n      if (i &gt; -1 &amp;&amp; i &lt; STRIP_SIZE) {\n      leds&#91;i] = CRGB(r\/trail,g\/trail,b\/trail);\n      }\n      else \n      {\n        break;\n      }\n      trail++;\n    }\n    if (pos-comet-1 &gt;= 0) \n    {\n      leds&#91;pos-comet-1] = CRGB::Black;\n    }\n  }\n\n  if (pos &gt; STRIP_SIZE) \n  {\n    dir = true;\n  }\n  else if (pos &lt; 0)\n  {\n    dir = false;\n  }\n\n  FastLED.show(); \/\/This is what actually draws the leds on the strip.\n  delay(1000\/FPS); \/\/ One second \n\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Fire Effect<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"485\" src=\"https:\/\/trewest.dev\/blog\/wp-content\/uploads\/2023\/01\/20211031_191010-1024x485.jpg\" alt=\"\" class=\"wp-image-254\" srcset=\"https:\/\/trewest.dev\/blog\/wp-content\/uploads\/2023\/01\/20211031_191010-1024x485.jpg 1024w, https:\/\/trewest.dev\/blog\/wp-content\/uploads\/2023\/01\/20211031_191010-300x142.jpg 300w, https:\/\/trewest.dev\/blog\/wp-content\/uploads\/2023\/01\/20211031_191010-768x363.jpg 768w, https:\/\/trewest.dev\/blog\/wp-content\/uploads\/2023\/01\/20211031_191010-1536x727.jpg 1536w, https:\/\/trewest.dev\/blog\/wp-content\/uploads\/2023\/01\/20211031_191010-2048x969.jpg 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-video\"><video height=\"1080\" style=\"aspect-ratio: 1920 \/ 1080;\" width=\"1920\" controls muted src=\"https:\/\/trewest.dev\/blog\/wp-content\/uploads\/2023\/01\/20211031_191101.mp4\"><\/video><figcaption class=\"wp-element-caption\">You can see a pretty major flicker in here, while the glowing is subtle<\/figcaption><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/Simple Fire Effect\n\/\/Designed for WS2812B LED strips,\n\/\/Tested on an Arduino Uno\n\/\/Using the FastLED Library\n\/\/Copyright William West 2021\n#include &lt;Arduino.h&gt;\n#include &lt;FastLED.h&gt;\n\n#define STRIP_LENGTH 150\n\nCRGB leds &#91;1]&#91;STRIP_LENGTH];\n\nvoid setup() {\n  \/\/ tell FastLED there's leds on pin 9\n  FastLED.addLeds&lt;WS2812B, 9&gt;(leds&#91;0], STRIP_LENGTH);\n  \/\/Begin Serial output, platform IO likes 9600.\n  Serial.begin(9600);\n}\n\nvoid loop() {\n\t\/\/Initializing Random\n  srand((unsigned) millis());\n\/\/Getting a random chance the whole strip will flicker together\n  int wholeFlicker = rand() % 500;\n\n  for (int i = 0; i &lt; STRIP_LENGTH; i++) \/\/For loop to iterate through the strip\n  {\n    int flicker = rand() %10; \/\/Testing if the individual LED will flicker\n    int mod = rand() % 55; \/\/ Modifier for the red\n    int mod2 = rand() %30; \/\/ Modifier for the green\n    int yolo = rand() %15; \/\/ Modifier for the blue\n    if (wholeFlicker !=250)  \/\/ Testing if the strip should flicker\n    {\n      if (flicker != 1) \/\/ If we're not flickering\n      {\/\/We're drawing the regular colors\n        leds&#91;0]&#91;i] = CRGB(40+mod2, 200 +mod, yolo); \/\/For some reason my strip processes color GREEN, RED, BLUE\n      }\n      else \/\/Otherwise we're drawing dimmed colors\n      {\n        leds&#91;0]&#91;i] = CRGB((40+mod2) - 40, (200 +mod) -10, 5);\n      }\n    }\n    else \/\/If the whole strips flickering it'd be really dim\n    {\n      leds&#91;0]&#91;i] = CRGB(0,20+yolo,0);\n    }\n  }\n  \/\/This happens after we determine what the strip is doing this 'frame'\n  FastLED.show(); \/\/ Basically the print or render command\n  delay(20); \/\/Wait 20 miliseconds to repeat\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Red White Blue<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/Red White Blue\n\/\/Designed for WS2812B LED strips,\n\/\/Tested on an Arduino Uno\n\/\/Using the FastLED Library\n\/\/Copyright William West 2021\n#include &lt;Arduino.h&gt;\n#include &lt;FastLED.h&gt;\n\n#define RED_PIN 7\n#define BLUE_PIN 4\n#define GREEN_PIN 5\n\n\nCRGB leds &#91;1]&#91;150];\n\n\n\nvoid setup() {\n  \/\/ put your setup code here, to run once:\n\n  \/\/ tell FastLED there's 30 NEOPIXEL leds on pin 9\n  FastLED.addLeds&lt;WS2812B, 9&gt;(leds&#91;0], 150);\n\n  Serial.begin(9600);\n\n  pinMode(RED_PIN, INPUT_PULLUP);\n  pinMode(BLUE_PIN, INPUT_PULLUP);\n  pinMode(GREEN_PIN, INPUT_PULLUP);\n}\n\nint start = 0;\n\nvoid loop() {\n  int color = start;\n  int iterator = 0;\n  for (int i = 0; i &lt; 150; i++) \n  {\n    if (iterator &gt; 5) \n    {\n      iterator = 0;\n      color++;\n      if (color &gt; 2) \n      {\n        color=0;\n      }\n      Serial.println(\"Color:\");\n      Serial.print(color);\n    }\n    iterator++;\n    switch (color) {\n      case 0: leds&#91;0]&#91;i] = CRGB::Blue; break;\n      case 1: leds&#91;0]&#91;i] = CRGB::Red; break;\n      case 2: leds&#91;0]&#91;i] = CRGB::White; break;\n    }\n  }\n  FastLED.show();\n  start++;\n  if (start &gt; 3) {start = 0;}\n  delay(2000);\n\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>In November of 2021 my interest in Arduino, something I had vaguely known of for years. It wasn\u2019t until someone on Youtube who goes by Dave\u2019s Garage made a video that showed up in my recommended feed going over the programming of WS2812B ARGB Strip lights. And so I promptly did my own in a Arduino Emulator which basically allows you to code everything without the physical hardware. Anyhow, the code is below.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[48,45,4,8],"tags":[26,50,16,49],"post_series":[53],"class_list":["post-253","post","type-post","status-publish","format-standard","hentry","category-arduino","category-c-coding","category-coding","category-project","tag-arduino","tag-argb","tag-c","tag-led-lights","post_series-project-overviews"],"_links":{"self":[{"href":"https:\/\/trewest.dev\/blog\/index.php\/wp-json\/wp\/v2\/posts\/253","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/trewest.dev\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/trewest.dev\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/trewest.dev\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/trewest.dev\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=253"}],"version-history":[{"count":3,"href":"https:\/\/trewest.dev\/blog\/index.php\/wp-json\/wp\/v2\/posts\/253\/revisions"}],"predecessor-version":[{"id":352,"href":"https:\/\/trewest.dev\/blog\/index.php\/wp-json\/wp\/v2\/posts\/253\/revisions\/352"}],"wp:attachment":[{"href":"https:\/\/trewest.dev\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=253"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/trewest.dev\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=253"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/trewest.dev\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=253"},{"taxonomy":"post_series","embeddable":true,"href":"https:\/\/trewest.dev\/blog\/index.php\/wp-json\/wp\/v2\/post_series?post=253"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}