{"id":1490,"date":"2018-04-04T07:40:51","date_gmt":"2018-04-04T14:40:51","guid":{"rendered":"http:\/\/www.donluc.com\/?p=1490"},"modified":"2018-04-04T07:40:51","modified_gmt":"2018-04-04T14:40:51","slug":"project-5-lamps-mk01","status":"publish","type":"post","link":"https:\/\/www.donluc.com\/?p=1490","title":{"rendered":"Project #5: Lamps &#8211; Mk01"},"content":{"rendered":"<p><a href=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2018\/04\/DonLuc1804Mk02a.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2018\/04\/DonLuc1804Mk02a.png\" alt=\"\" width=\"720\" height=\"689\" class=\"alignnone size-full wp-image-1491\" srcset=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2018\/04\/DonLuc1804Mk02a.png 720w, https:\/\/www.donluc.com\/wp-content\/uploads\/2018\/04\/DonLuc1804Mk02a-300x287.png 300w\" sizes=\"auto, (max-width: 720px) 100vw, 720px\" \/><\/a><\/p>\n<div style=\"width: 720px;\" class=\"wp-video\"><video class=\"wp-video-shortcode\" id=\"video-1490-1\" width=\"720\" height=\"406\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2018\/04\/DonLuc18-04mk02.mp4?_=1\" \/><a href=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2018\/04\/DonLuc18-04mk02.mp4\">https:\/\/www.donluc.com\/wp-content\/uploads\/2018\/04\/DonLuc18-04mk02.mp4<\/a><\/video><\/div>\n<p>DonLuc1804Mk02.ino<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"default\" data-enlighter-title=\"DonLuc1804Mk02.ino\">\r\n\/\/ ***** Don Luc *****\r\n\/\/ Software Version Information\r\n\/\/ 1.01\r\n\/\/ DonLuc1804Mk02 1.01\r\n\/\/ Lamps\r\n\r\n#include &lt;Adafruit_NeoPixel.h&gt;\r\n\/\/ Which pin on the Arduino is connected to the NeoPixels\r\n\/\/ Pin connected =&gt; 6\r\n#define PIN 6\r\n\/\/ How many NeoPixels are attached to the Arduino\r\n\/\/ NUMPIXELS =&gt; 4\r\n#define NUMPIXELS 4\r\nAdafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);\r\n\/\/ Panel Mount 1K potentiometer Bright\r\n\/\/ Bright =&gt; A0\r\nconst int sensorBright = A0;\r\nint sBright = 0;\r\nint brightVal = 0;         \/\/ the sensor value\r\nint brightMin = 0;        \/\/ minimum sensor value\r\nint brightMax = 0;           \/\/ maximum sensor value\r\n\/\/ Panel Mount 1K potentiometer\r\n\/\/ Delay =&gt; A1\r\nconst int sensorDelay = A1;\r\nlong delayVal = 0;\r\n\/\/ Rotary Switch - 10 Position\r\n\/\/ Number =&gt; A2 (0 =&gt; 9)\r\nconst int sensorNumber = A2;\r\n\/\/ Panel Mount 1K potentiometer\r\n\/\/ Red - Led\r\nconst int sensorRed = 9;\r\nint red = 0;\r\nint redMin = 0;\r\nint redMax = 0;\r\n\/\/ Panel Mount 1K potentiometer\r\n\/\/ Green - Led\r\nconst int sensorGreen = 8;\r\nint green = 0;\r\nint greenMin = 0;\r\nint greenMax = 0;\r\n\/\/ Panel Mount 1K potentiometer\r\n\/\/ Blue - Led\r\nconst int sensorBlue = 7;\r\nint blue = 0;\r\nint blueMin = 0;\r\nint blueMax = 0;\r\n\/\/ variables:\r\n\/\/int x = 0;\r\nint y = 0;\r\nint z = 0;\r\n\r\nvoid loop() {\r\n\r\n  number();\r\n\r\n}\r\n<\/pre>\n<p>bright.ino<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"default\" data-enlighter-title=\"bright.ino\">\r\nvoid bright(){\r\n\r\n    switch (sBright) {\r\n        case 1:\r\n            brightVal = 255;\r\n            break;\r\n         default:\r\n            \/\/ read the sensor:\r\n            brightVal = analogRead(sensorBright);\r\n            \/\/ apply the calibration to the sensor reading\r\n            brightVal = map(brightVal, brightMin, brightMax, 0, 255);        \r\n            \/\/ in case the sensor value is outside the range seen during calibration\r\n            brightVal = constrain(brightVal, 0, 255);\r\n            break;\r\n    }\r\n  \r\n}\r\n<\/pre>\n<p>iled.ino<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"default\" data-enlighter-title=\"iled.ino\">\r\nvoid iled() {\r\n\r\n   \/\/ red\r\n   red = analogRead(sensorRed); \r\n   \/\/ apply the calibration to the sensor reading red\r\n   red = map(red, redMin, redMax, 0, 255);\r\n   \/\/ in case the sensor value is outside the range seen during calibration\r\n   red = constrain(red, 0, 255);\r\n   \/\/ green\r\n   green = analogRead(sensorGreen); \r\n   \/\/ apply the calibration to the sensor reading red\r\n   green = map(green, greenMin, greenMax, 0, 255);\r\n   \/\/ in case the sensor value is outside the range seen during calibration\r\n   green = constrain(green, 0, 255);\r\n   \/\/ blue\r\n   blue = analogRead(sensorBlue); \r\n   \/\/ apply the calibration to the sensor reading red\r\n   blue = map(blue, blueMin, blueMax, 0, 255);\r\n   \/\/ in case the sensor value is outside the range seen during calibration\r\n   blue = constrain(blue, 0, 255);\r\n                 \r\n}\r\n<\/pre>\n<p>neopix.ino<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"default\" data-enlighter-title=\"neopix.ino\">\r\nvoid neopix() {\r\n  \r\n  for(int i=0; i&lt;NUMPIXELS; i++){\r\n\r\n    \/\/ bright\r\n    bright();   \r\n    pixels.setBrightness( brightVal );\r\n    \/\/ pixels.Color takes RGB values, from 0,0,0 up to 255,255,255    \r\n    pixels.setPixelColor(i, pixels.Color(red,green,blue));\r\n    \/\/ show\r\n    pixels.show(); \/\/ This sends the updated pixel color to the hardware.\r\n    \/\/ delay\r\n    delay(50); \/\/ Delay for a period of time (in milliseconds).\r\n    \r\n  }\r\n  \r\n}\r\n<\/pre>\n<p>neopixt.ino<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"default\" data-enlighter-title=\"neopixt.ino\">\r\nvoid neopixt() {\r\n  \r\n  for(int i=4; i&lt;NUMPIXELS; i--){\r\n\r\n    \/\/ bright\r\n    bright();   \r\n    pixels.setBrightness( brightVal );\r\n    \/\/ pixels.Color takes RGB values, from 0,0,0 up to 255,255,255    \r\n    pixels.setPixelColor(i, pixels.Color(red,green,blue));\r\n    \/\/ show\r\n    pixels.show(); \/\/ This sends the updated pixel color to the hardware.\r\n    \/\/ delay\r\n    delay(50); \/\/ Delay for a period of time (in milliseconds).\r\n    \r\n  }\r\n  \r\n}\r\n<\/pre>\n<p>number.ino<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"default\" data-enlighter-title=\"number.ino\">\r\nvoid number(){\r\n\r\n  z = analogRead(sensorNumber);\r\n  y = (z \/ 127);\r\n\r\n  sBright = 20000;\r\n  \r\n  \/\/ range value:\r\n  switch (y) {\r\n    case  0:\r\n      \/\/ Led\r\n      iled();\r\n      \/\/ neopix\r\n      neopix();\r\n      \/\/ delay\r\n      delayVal = (0);     \r\n      break;\r\n    case 1:\r\n      \/\/ Led\r\n      iled();\r\n      \/\/ neopix\r\n      neopix();\r\n      \/\/ delay\r\n      sdelay();\r\n      break;\r\n    case 2:\r\n      \/\/ Led\r\n      iled();\r\n      \/\/ neopixt\r\n      neopixt();\r\n      \/\/ delay\r\n      sdelay();\r\n      break;\r\n    case 3:\r\n      \/\/ White\r\n      red = 255;\r\n      green = 255;\r\n      blue = 255; \r\n      \/\/ neopix       \r\n      neopix();\r\n      \/\/ delay\r\n      delayVal = (0);\r\n      break;  \r\n    case 4:\r\n      \/\/ Green\r\n      red = 0;\r\n      green = 255;\r\n      blue = 0;\r\n      \/\/ neopix        \r\n      neopix();\r\n      \/\/ delay\r\n      delayVal = (0);\r\n      break;\r\n    case 5:\r\n      \/\/ Red\r\n      red = 255;\r\n      green = 0;\r\n      blue = 0;        \r\n      \/\/ neopix        \r\n      neopix();\r\n      \/\/ delay\r\n      delayVal = (0);\r\n      break;\r\n    case 6:\r\n      \/\/ White\r\n      red = 255;\r\n      green = 255;\r\n      blue = 255; \r\n      \/\/ neopix       \r\n      neopix();\r\n      \/\/ delay\r\n      sdelay();\r\n      break;       \r\n    case 7:\r\n      \/\/ Green\r\n      red = 0;\r\n      green = 255;\r\n      blue = 0; \r\n      \/\/ neopix       \r\n      neopix();\r\n      \/\/ delay\r\n      sdelay();\r\n      break; \r\n    case 8:\r\n      \/\/ Red\r\n      red = 255;\r\n      green = 0;\r\n      blue = 0; \r\n      \/\/ neopix       \r\n      neopix();\r\n      \/\/ delay\r\n      sdelay();\r\n      break; \r\n    case 9:\r\n\r\n      break;\r\n  }\r\n  \r\n}\r\n<\/pre>\n<p>sdelay.ino<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"default\" data-enlighter-title=\"sdelay.ino\">\r\nvoid sdelay() {\r\n\r\n    delayVal = analogRead(sensorDelay);\r\n    delayVal = (250 * delayVal);\r\n      \r\n}\r\n<\/pre>\n<p>setup.ino<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"default\" data-enlighter-title=\"setup.ino\">\r\nvoid setup() {\r\n  \r\n    pixels.begin(); \/\/ This initializes the NeoPixel library.\r\n    \r\n}\r\n<\/pre>\n<p><strong>Don Luc<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>DonLuc1804Mk02.ino \/\/ ***** Don Luc ***** \/\/ Software Version Information \/\/ 1.01 \/\/ DonLuc1804Mk02 1.01 \/\/ Lamps #include &lt;Adafruit_NeoPixel.h&gt; \/\/ Which pin on the Arduino is connected to the NeoPixels \/\/ Pin connected =&gt; 6 #define PIN 6 \/\/ How many NeoPixels are attached to the Arduino \/\/ NUMPIXELS =&gt; 4 #define NUMPIXELS 4 Adafruit_NeoPixel &#8230; <a title=\"Project #5: Lamps &#8211; Mk01\" class=\"read-more\" href=\"https:\/\/www.donluc.com\/?p=1490\" aria-label=\"Read more about Project #5: Lamps &#8211; Mk01\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[68,50,38,5,58,10,43],"tags":[],"class_list":["post-1490","post","type-post","status-publish","format-standard","hentry","category-lamps","category-arduino","category-digitalelectronics","category-microcontrollers","category-arduino-programming","category-projects","category-sparkfun"],"_links":{"self":[{"href":"https:\/\/www.donluc.com\/index.php?rest_route=\/wp\/v2\/posts\/1490","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.donluc.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.donluc.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.donluc.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.donluc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1490"}],"version-history":[{"count":5,"href":"https:\/\/www.donluc.com\/index.php?rest_route=\/wp\/v2\/posts\/1490\/revisions"}],"predecessor-version":[{"id":1497,"href":"https:\/\/www.donluc.com\/index.php?rest_route=\/wp\/v2\/posts\/1490\/revisions\/1497"}],"wp:attachment":[{"href":"https:\/\/www.donluc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1490"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.donluc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1490"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.donluc.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1490"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}