{"id":18,"date":"2013-10-25T03:40:50","date_gmt":"2013-10-25T03:40:50","guid":{"rendered":"http:\/\/mypocket-technologies.com\/?p=723"},"modified":"2013-10-25T03:40:50","modified_gmt":"2013-10-25T03:40:50","slug":"arduino-mood-light-project-continued","status":"publish","type":"post","link":"https:\/\/bitcows.com\/?p=18","title":{"rendered":"Arduino Mood Light Project (Continued)"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/mypocket-technologies.com\/wp-content\/uploads\/2013\/10\/moodelight2.1sketch1.png\" alt=\"\" title=\"moodelight2.1sketch\" width=\"836\" height=\"498\" class=\"alignleft size-full wp-image-740\" \/><br \/>\nSo my 5050 lights came in and they are a little bigger than I thought they would be. So now I had to remove the second RGB lights I had put in.  I did find a small error with the power supply. It was hooked up backwards. Glad I triple checked that. <\/p>\n<p>I also double checked my code and found out that I had done something a little wrong. I needed to switch the positive to negative as the RGB was as common Anode not Cathode. So I quickly fixed some code and tested it on my bread board. Once the transition was nice and smooth I tested it on my new MC chip.  Once all was well it was time to get this made.<br \/>\n<img decoding=\"async\" src=\"http:\/\/mypocket-technologies.com\/wp-content\/uploads\/2013\/10\/back.png\" alt=\"\" title=\"back\" width=\"200\" class=\"alignleft size-full wp-image-729\"><img decoding=\"async\" src=\"http:\/\/mypocket-technologies.com\/wp-content\/uploads\/2013\/10\/front.png\" alt=\"\" title=\"back\" width=\"200\" class=\"size-full wp-image-729\" \/><\/p>\n<div style=\"clear:both\"\/>\nI sent away for the boards to be made now.. After I get them back I will start the final part of the project the stand.<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/mypocket-technologies.com\/wp-content\/uploads\/2013\/10\/moodelight2.1sketch1.png\" alt=\"\" title=\"moodelight2.1sketch\" width=\"836\" height=\"498\" class=\"alignleft size-full wp-image-740\" \/><\/p>\n<p><strong>UPDATE 12\/20\/13<\/strong>:<br \/>\nI received my initial boards back from the fabricator and unfortunately I made a mistake. My original design called for a common anode RGB LED. But my RGB LED&#8217;s never showed up, so I had to order common cathode RGB LED&#8217;s. This was all ok how ever I forgot to change my schema to a common ground from common power. So.. it didn&#8217;t work. <\/p>\n<p><img decoding=\"async\" src=\"http:\/\/mypocket-technologies.com\/wp-content\/uploads\/2013\/10\/IMG_6276.jpg\" alt=\"\" title=\"IMG_6276\" width=\"300\" class=\"alignleft size-full wp-image-815\" \/>However, I sent away for new boards to be made with this problem corrected along with a few minor alignment issues and WALLA! It works!<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/mypocket-technologies.com\/wp-content\/uploads\/2013\/10\/IMG_6278.jpg\" alt=\"\" title=\"arduino mood light\" width=\"250\" class=\"size-full wp-image-817\" \/><\/p>\n<p><b>SO HOW DID I DO IT?<\/b><br \/>\nThis project is pretty simple really. I just made a few dumb mistakes that could have been avoided if i was a little more experienced. If  you read <a href=\"http:\/\/mypocket-technologies.com\/2013\/10\/arduino-mood-light-project\/\">my other post<\/a> I started off with much larger board and a little less integrated power supply. In this version I rectified the power and reduced the size by half. This was a product of both cost and functionality. The cost to have the boards made was cut in half when I reduced it. I also challenged myself with almost all SMD parts. This also made for a nicer compact application.<\/p>\n<p><b>ARDUINO CODE<\/b><br \/>\nThis first part is just the set up. The controller is based off the ATMega88p <a href=\"http:\/\/mypocket-technologies.com\/2013\/09\/bootload-an-atmel-atmega88p\/\">see boot loading an ATMEL ATMega88p<\/a> for help on that. You can get these on Ebay cheap (I paid $10 for 6) and they are great!<\/p>\n<pre>\n#define RED_PIN  9       \/\/13\n#define GREEN_PIN  10    \/\/14\n#define BLUE_PIN  11     \/\/15\n    \n\nvoid setup() {\n  \/\/Serial.begin(9600);\n  \/\/ put your setup code here, to run once:\n  pinMode(RED_PIN, OUTPUT);\n  pinMode(GREEN_PIN, OUTPUT);\n  pinMode(BLUE_PIN, OUTPUT);\n}\n\nvoid loop() { \n  showSpectrum();\n}\n\nvoid showSpectrum()\n{\n  int allLights = 765;\n  \/\/loop 256  * 3 times RGB\n  for (int x = 0; x < allLights; x++)\n  {\n    showRGB(x); \n    delay(100);   \/\/ Delay for 10 ms (1\/100th of a second)\n  }\n}\n<\/pre>\n<p>This function is the main RGB loop. Define the variables<\/p>\n<pre>\n\/**\n* common anode scale\n*\/\nvoid showRGB(int color)\n{\n  int redIntensity;\n  int greenIntensity;\n  int blueIntensity;\n <\/pre>\n<p>I have two ways to do this. One uses a common Anode RGB which is commented here.<\/p>\n<pre>\n\/* COMMON ANDODE\n  if (color <= 255)                                              \/\/ RED TO BLUE (ON IS ZERO OFF IS 255)\n  {\n    \/\/Serial.println(\"*************************** RED TO BLUE ***************************\");\n    redIntensity = color;                                        \/\/ red is going off 0 - 255\n    greenIntensity = 255;                                        \/\/ green goes always off 255\n    blueIntensity = constrain(255 - color, 0, 255);              \/\/ blue is coming up 255 - 0\n  }\n  else if (color <= 510)                                         \/\/ BLUE TO GREEN  (ON IS ZERO OFF IS 255)\n  {\n    \/\/Serial.println(\"*************************** BLUE TO GREEN ***************************\");\n    redIntensity = 255;                                          \/\/ red is off 255\n    greenIntensity = constrain(255 - (color - 255), 0 ,255);     \/\/ greeen is coming up 255 - 0\n    blueIntensity =  constrain((color - 255), 0 , 255);          \/\/ blue is going off 0 - 255\n  }\n  else                                                           \/\/ GREEN TO RED (ON IS ZERO OFF IS 255)\n  {\n    \/\/Serial.println(\"*************************** GREEN TO RED ***************************\");\n    redIntensity = constrain(255 - (color - 510), 0, 255);       \/\/ red is coming up 255 - 0 \n    greenIntensity = constrain((color - 510), 0, 255);           \/\/ green is going off 0 - 255\n    blueIntensity = 255;                                         \/\/ blue is always off 255\n  }\n *\/\n<\/pre>\n<p>One uses a common cathode RGB which is the one I used.<\/p>\n<pre>\n  \/\/ COMMON CATHODE\n  if (color <= 255)          \/\/ zone 1\n  {\n    redIntensity = 255 - color;    \/\/ red goes from on to off 255 - 0\n    greenIntensity = color;        \/\/ green goes from off to on 0 - 255\n    blueIntensity = 0;             \/\/ blue is always off 0\n  }\n  else if (color <= 511)     \/\/ zone 2\n  {\n    redIntensity = 0;                     \/\/ red is always off 0\n    greenIntensity = 255 - (color - 256); \/\/ green on to off 255 - 0\n    blueIntensity = (color - 256);        \/\/ blue off to on 0 - 255\n  }\n  else \/\/ color >= 512       \/\/ zone 3\n  {\n    redIntensity = (color - 512);         \/\/ red off to on 0 - 255\n    greenIntensity = 0;                   \/\/ green is always off 0\n    blueIntensity = 255 - (color - 512);  \/\/ blue on to off 255 - 0\n  }\n<\/pre>\n<p>Some debug code used when breadboarding<\/p>\n<pre>\n \/* DEBUG CODE\n   \/\/ print the three numbers in one string as hexadecimal:\n    Serial.print(\"RED: \");\n    Serial.println(redIntensity);\n    Serial.print(\"GREEN: \");\n    Serial.println(greenIntensity);\n    Serial.print(\"BLUE: \");\n    Serial.println(blueIntensity);\n*\/\n<\/pre>\n<p>Then write to the LEDs<\/p>\n<pre>\n  analogWrite(RED_PIN, redIntensity);\n  analogWrite(GREEN_PIN, greenIntensity);\n  analogWrite(BLUE_PIN, blueIntensity);\n}\n<\/pre>\n<p><b>THE SCHEMA<\/b><br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/mypocket-technologies.com\/wp-content\/uploads\/2013\/10\/moodlightschema.png\" alt=\"\" title=\"moodlightschema\" width=\"600\" height=\"567\" class=\"alignnone size-full wp-image-818\" \/><br \/>\n<b>GET THE SOURCE CODE<\/b><br \/>\n<a href=\"https:\/\/github.com\/djmason9\/Mood-Light\">The Code<\/a><\/p>\n<p><b>PARTS<\/b><br \/>\n- <a href=\"http:\/\/www.ebay.com\/bhp\/dc-buck-converter\" target=\"_new\" rel=\"noopener\">Power Converter<\/a><br \/>\n- <a href=\"http:\/\/www.ebay.com\/itm\/5x-Atmel-ATMEGA88P-20AU-AVR-Microcontroller-32-TQFP-MCU-ATMEGA-ATmega88PA-AU-\/160729526919\">ATMEL ATMega88p<\/a><br \/>\n- <a href=\"http:\/\/www.ebay.com\/itm\/100pcs-2020-5050-RGB-SMD-Superbright-LED-Light-Emitting-Diode-\/370953860947\">Common Anode RGB LED<\/a><br \/>\n- 100ohm -120ohm 0805 SMD Resistor<br \/>\n- <a href=\"https:\/\/www.sparkfun.com\/products\/9609\">Power Switch<\/a><br \/>\n- 6mm Momentary Switch<br \/>\n- <a href=\"http:\/\/www.digikey.com\/product-detail\/en\/PJ-002AH-SMT-TR\/CP-002AHPJCT-ND\/669692\">2.1mm SMD Barrel Plug<\/a><\/p>\n<div style=\"clear:both\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>So my 5050 lights came in and they are a little bigger than I thought they would be. So now I had to remove the second RGB lights I had put in. I did find a small error with the power supply. It was hooked up backwards. Glad I triple checked that. I also double&hellip;<\/p>\n<p class=\"more-link\"><a href=\"https:\/\/bitcows.com\/?p=18\" class=\"themebutton\">Read More<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[33,45],"class_list":["post-18","post","type-post","status-publish","format-standard","hentry","category-electronics","tag-arduino","tag-electronics"],"_links":{"self":[{"href":"https:\/\/bitcows.com\/index.php?rest_route=\/wp\/v2\/posts\/18","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bitcows.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bitcows.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bitcows.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bitcows.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=18"}],"version-history":[{"count":0,"href":"https:\/\/bitcows.com\/index.php?rest_route=\/wp\/v2\/posts\/18\/revisions"}],"wp:attachment":[{"href":"https:\/\/bitcows.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=18"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bitcows.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=18"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bitcows.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=18"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}