{"id":1907,"date":"2011-03-23T21:14:05","date_gmt":"2011-03-24T02:14:05","guid":{"rendered":"http:\/\/www.plastibots.com\/?p=1907"},"modified":"2015-03-14T06:43:41","modified_gmt":"2015-03-14T11:43:41","slug":"dual-led-desk-light-controller-arduino","status":"publish","type":"post","link":"https:\/\/www.plastibots.com\/index.php\/2011\/03\/23\/dual-led-desk-light-controller-arduino\/","title":{"rendered":"Dual LED Desk Light Controller &#8211; Arduino"},"content":{"rendered":"<p><a href=\"http:\/\/www.plastibots.com\/wordpress\/wp-content\/uploads\/2011\/03\/ArduinoLED_ControllerMainboard.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-1900  alignright\" title=\"ArduinoLED_ControllerMainboard\" src=\"http:\/\/www.plastibots.com\/wordpress\/wp-content\/uploads\/2011\/03\/ArduinoLED_ControllerMainboard-300x162.jpg\" alt=\"Main Board\" width=\"300\" height=\"162\" srcset=\"https:\/\/www.plastibots.com\/wordpress\/wp-content\/uploads\/2011\/03\/ArduinoLED_ControllerMainboard-300x162.jpg 300w, https:\/\/www.plastibots.com\/wordpress\/wp-content\/uploads\/2011\/03\/ArduinoLED_ControllerMainboard.jpg 1024w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>I&#8217;ve been involved in microcontrollers for some time &#8211; but of the LEGO Mindstorms flavour (and BASIC Stamp to a lesser extent). Lately, I&#8217;ve jumped on the Arduino bandwagon. I&#8217;ve always had the natural nack to fix pretty much anything that has batteries or a plug running out of it. \u00a0As the Arduino revolution has picked up dramatically over the past few years, so to has my desire to do DIY projects around the house. At some point in the future, we plan a kitchen reno. \u00a0Part of that reno will the addition of under-cabinet LED lighting. \u00a0 \u00a0Since that is far off, but I also had the need for better lighting in my office, I figured this would be a great time to proto something for the kitchen upgrade, while making something functional for the office. So, here it is..<\/p>\n<p>&nbsp;<\/p>\n<p><!--more--><\/p>\n<p>Update Feb 2015: \u00a0It&#8217;s been nearly 4 years since I built this project and it is still running strong. \u00a0It is by far my most used DIY mod and gets used several times per day. \u00a0The touchpad still functions as expected and the controller\/LED&#8217;s are still good. \u00a0 I had one hiccup a few months ago where one of the channels (think it was green) had a connector come loose which resulted in the light emitting purple. \u00a0A quick re-solder of that channel fixed things.<\/p>\n<p>&nbsp;<\/p>\n<p><center><br \/>\n<object width=\"425\" height=\"344\" classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http:\/\/download.macromedia.com\/pub\/shockwave\/cabs\/flash\/swflash.cab#version=6,0,40,0\"><param name=\"allowFullScreen\" value=\"true\" \/><param name=\"allowscriptaccess\" value=\"always\" \/><param name=\"src\" value=\"http:\/\/www.youtube.com\/v\/ViBDuM0C-KM?hl=en&amp;fs=1\" \/><param name=\"allowfullscreen\" value=\"true\" \/><\/object><\/center>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>[ad name=&#8221;GoogleAS728x90ImgOnly&#8221;]<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<figure id=\"attachment_1921\" aria-describedby=\"caption-attachment-1921\" style=\"width: 150px\" class=\"wp-caption alignright\"><a href=\"http:\/\/www.plastibots.com\/wordpress\/wp-content\/uploads\/2011\/03\/ArduinoLED_TouchPadMappedAreas.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-thumbnail wp-image-1921 \" title=\"ArduinoLED_TouchPadMappedAreas\" src=\"http:\/\/www.plastibots.com\/wordpress\/wp-content\/uploads\/2011\/03\/ArduinoLED_TouchPadMappedAreas-150x150.jpg\" alt=\"TouchPad Mapped Areas\" width=\"150\" height=\"150\" \/><\/a><figcaption id=\"caption-attachment-1921\" class=\"wp-caption-text\">TouchPad Mapped Areas<\/figcaption><\/figure>\n<p>&nbsp;<\/p>\n<p>At first, I did not really have a plan. \u00a0I knew I wanted some sort of switchless control of the LEDs, and to illuminate the main part of my desk. My initial prototype used a capacitive touch control using 2 copper tubes mounted on the project box. \u00a0The idea being bridging the two tubes with your finger, the LEDs would dim up\/down. \u00a0 You could also to a tap to turn them on (ramp up) and another tap to turn them off (ramp down). \u00a0 I was nearly done, but while perusing the web, I came across someone using an <a title=\"Arduino TouchPad\" href=\"http:\/\/www.instructables.com\/id\/The-5-Karduinoss-pad\/?ALLSTEPS\" target=\"_blank\">arduino and a synaptics touchpad<\/a> together for another purpose &#8211; which got me thinking (smoke coming out of ears). \u00a0 I also found the need to want to control more than one light at my desk. \u00a0I have multiple shelves and, even though the desk area can be illuminated, the shelf above are dark at night. \u00a0This is also the place where all my electronic bits manage to find themselves when Im tinkering &#8211; and I often have to go fishing around for a flashlight to find bits I&#8217;m looking for. \u00a0 The addition of a touchpad provides many possibilities here.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>When connected to the Arduino, a Synaptics touchpad can be used in two modes. \u00a0Relative mode is the norm. \u00a0It works like you would expect it to on a laptop. \u00a0No matter where you put your finger and move it, your mouse will move from its current point in the direction you move your finger. \u00a0 Well, I&#8217;m not using a computer or moving a mouse around. \u00a0I needed the unit to work in absolute mode. \u00a0I need to know the exact X\/Y coordinates of where my fingers were moving. Knowing this, I could create mapped areas to monitor in the Sketch and perform various actions when movement was detected in those areas. \u00a0Thanks to this <a href=\"http:\/\/www.instructables.com\/id\/The-5-Karduinoss-pad\/step3\/Interfacing-to-the-arduino\/?files#files\" target=\"_blank\">Instructable<\/a>, \u00a0the users Sketch contained the necessary commands to put the Synaptics touchpad in Absolute mode. \u00a0The sketch uses the PS2 library as well. \u00a0More on this later.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"http:\/\/www.plastibots.com\/wordpress\/wp-content\/uploads\/2011\/03\/ArduinoLED_TouchPadFront.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-thumbnail wp-image-1935 alignright\" title=\"ArduinoLED_TouchPadFront\" src=\"http:\/\/www.plastibots.com\/wordpress\/wp-content\/uploads\/2011\/03\/ArduinoLED_TouchPadFront-e1300560538551-150x94.jpg\" alt=\"\" width=\"150\" height=\"94\" \/><\/a><\/p>\n<p>After testing a touchpad from my old and trusty Compact N600c, \u00a0I decided to pickup a few extras from Ebay. I managed to pickup one from a Gateway W340UA and a Gateway Solo unit ($5 each). \u00a0Both units had the Synaptics chip I was looking for, but I am sure there are many other Laptops that have similar units (eg IBM T42 does), and quick<a href=\"http:\/\/sparktronics.blogspot.com\/2008\/05\/synaptics-t1004-based-touchpad-to-ps2.html\" target=\"_blank\"> Google search<\/a> will yield lots of results. \u00a0I like this touchpad as it already has the arrow markers for the dimming feature that I wanted (more on this later re X\/Y values). The next image shows the pinouts and trace paths for the Gateway W340UA touchpad that I used for this project. I have toyed with 4 different Synaptics touchpads and found them all very similar in their layout.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>[ad name=&#8221;GoogleAS728x90&#8243;]<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<figure id=\"attachment_1906\" aria-describedby=\"caption-attachment-1906\" style=\"width: 300px\" class=\"wp-caption alignleft\"><a href=\"http:\/\/www.plastibots.com\/wordpress\/wp-content\/uploads\/2011\/03\/ArduinoLED_TouchPadPinouts.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-1906 \" title=\"ArduinoLED_TouchPadPinouts\" src=\"http:\/\/www.plastibots.com\/wordpress\/wp-content\/uploads\/2011\/03\/ArduinoLED_TouchPadPinouts-300x158.jpg\" alt=\"TouchPad Pinouts\" width=\"300\" height=\"158\" srcset=\"https:\/\/www.plastibots.com\/wordpress\/wp-content\/uploads\/2011\/03\/ArduinoLED_TouchPadPinouts-300x158.jpg 300w, https:\/\/www.plastibots.com\/wordpress\/wp-content\/uploads\/2011\/03\/ArduinoLED_TouchPadPinouts-1024x541.jpg 1024w, https:\/\/www.plastibots.com\/wordpress\/wp-content\/uploads\/2011\/03\/ArduinoLED_TouchPadPinouts.jpg 1619w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-1906\" class=\"wp-caption-text\">TouchPad Pinouts<\/figcaption><\/figure>\n<p>&nbsp;<\/p>\n<p>The pinouts are straight forward: \u00a0+5V, GND, Data and Clock. Most sample sketches out there (especially the PS2 library) will have info on where to hook each of these up to on the Arduino. \u00a0You can also download my sketch for this project further down below. \u00a0Synaptics was even nice enough to give us DIY&#8217;ers \u00a0little pads to solder to. \u00a0These are evident for the Data and Clock points below. \u00a0Note that, for the 5V power, you should track back as far to the ribbon connector as you can. \u00a0There is at least 1 resistor and capacitor along the path to the pin on the Synaptics chip. \u00a0Don&#8217;t bypass them if they are there. \u00a0The Data and Clock pins are ok to go direct to the Synaptics pins. \u00a0Also take note of the reference dot on the Synaptics chip &#8211; this typically refers to the starting location of PIN#1 on the chip.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>After soldering the pin connections on the back of the touchpad, I had to find a way to mount it. \u00a0I thought of different ways to do this (embedding it on the desk, on the side, etc etc). Since I had a lot of metal mounting points aronund me (filing cabinet, side shelf beams, shelves), I just decided to put some magnets to the back of it. \u00a0Of course, since my roots are with LEGO I could not fore-go the bastardization of a LEGO plate to mask the circuit board and soldering I had done with that fine blue wire (figure it must be 30-something gauge &#8211; it&#8217;s like thread!). \u00a0So, I took to the dremmel and cut up a black plate and glued it to the back of the touchpad. \u00a0Now, if I want to in the future, I can build any type of mounting system I want &#8211; using LEGO!<\/p>\n<p>&nbsp;<\/p>\n<figure id=\"attachment_1903\" aria-describedby=\"caption-attachment-1903\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.plastibots.com\/wordpress\/wp-content\/uploads\/2011\/03\/ArduinoLED_TouchPadControllerBack.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-1903 \" title=\"ArduinoLED_TouchPadControllerBack\" src=\"http:\/\/www.plastibots.com\/wordpress\/wp-content\/uploads\/2011\/03\/ArduinoLED_TouchPadControllerBack-300x189.jpg\" alt=\"Touch Pad Back - Mounting\" width=\"300\" height=\"189\" srcset=\"https:\/\/www.plastibots.com\/wordpress\/wp-content\/uploads\/2011\/03\/ArduinoLED_TouchPadControllerBack-300x189.jpg 300w, https:\/\/www.plastibots.com\/wordpress\/wp-content\/uploads\/2011\/03\/ArduinoLED_TouchPadControllerBack.jpg 1024w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-1903\" class=\"wp-caption-text\">Touch Pad Back &#8211; Mounting<\/figcaption><\/figure>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>I am a minimalist when it comes to designing circuits. \u00a0I don&#8217;t like large boxy control units. \u00a0One day, I will perfect my SMD abilities and make these things even smaller. \u00a0For now, I had to settle with a project box that I&#8217;m pretty happy with &#8211; approx 3&#8243; x 2&#8243; x 1&#8243;. \u00a0 I managed to cram in an Arduino Nano, 12V power connector, regulated 5V supply, \u00a04x IRF 530&#8217;s (to control the LEDs), status LEDs and a number of connectors. \u00a0 It&#8217;s tight. \u00a0I know what you Arduino junkes are thinking.. \u00a0What a waste of a Nano. \u00a0I&#8217;m cool with that. \u00a0This is the first, and in future projects, I plan on creating my own Atmega based circuits. \u00a0I&#8217;ve already cobbled together a staging board that I can use to program future chips. \u00a0In the case of this circuit, I needed to use the PWM abilities of the 168\/328 chips. \u00a0I&#8217;m using all available PWM pins (4 of them). \u00a0 Again, Arduino junkies, I know what you are thinking &#8211; there are more than 4 PWM pins. \u00a0Yes there are. \u00a0However, I&#8217;m using the MSTimer2 library which kills the PWM of pins 3 and 11 for this project &#8211; I could have used another for the secondary LED lights, so if you have any ideas, share them up in the comments.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<figure id=\"attachment_1899\" aria-describedby=\"caption-attachment-1899\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.plastibots.com\/wordpress\/wp-content\/uploads\/2011\/03\/ArduinoLED_ControllerCase.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-1899 \" title=\"ArduinoLED_ControllerCase\" src=\"http:\/\/www.plastibots.com\/wordpress\/wp-content\/uploads\/2011\/03\/ArduinoLED_ControllerCase-300x225.jpg\" alt=\"Project Box\" width=\"300\" height=\"225\" srcset=\"https:\/\/www.plastibots.com\/wordpress\/wp-content\/uploads\/2011\/03\/ArduinoLED_ControllerCase-300x225.jpg 300w, https:\/\/www.plastibots.com\/wordpress\/wp-content\/uploads\/2011\/03\/ArduinoLED_ControllerCase.jpg 1024w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-1899\" class=\"wp-caption-text\">LED Light Controller project box.<\/figcaption><\/figure>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>Looking at the Main Board below, I&#8217;ve labelled all the main parts. \u00a0I used IRF530 MOSFETs to allow the Arduino to cleanly regulate 0-12V to each of the R, G, B on the main LED light bar and 1 IRF530 to do the same for the second LED light. \u00a0In the case of the second LED light, I used a leftover strip of 3 RGB LEDs. \u00a0In this case, I did not care to individually control Red, Green and Blue. \u00a0What I did was simply use the IRF530 to power 0-12V to the LEDs on 2 wires. \u00a0On the LED strip itself, I bridged R+G and from RG added a 330 Ohm resistor to Blue. \u00a0This reduces the power output of blue which gives the light a warmer more natural light (not that bluish white light).<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<figure id=\"attachment_1900\" aria-describedby=\"caption-attachment-1900\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.plastibots.com\/wordpress\/wp-content\/uploads\/2011\/03\/ArduinoLED_ControllerMainboard.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-1900 \" title=\"ArduinoLED_ControllerMainboard\" src=\"http:\/\/www.plastibots.com\/wordpress\/wp-content\/uploads\/2011\/03\/ArduinoLED_ControllerMainboard-300x162.jpg\" alt=\"Main Board\" width=\"300\" height=\"162\" srcset=\"https:\/\/www.plastibots.com\/wordpress\/wp-content\/uploads\/2011\/03\/ArduinoLED_ControllerMainboard-300x162.jpg 300w, https:\/\/www.plastibots.com\/wordpress\/wp-content\/uploads\/2011\/03\/ArduinoLED_ControllerMainboard.jpg 1024w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-1900\" class=\"wp-caption-text\">Main Board<\/figcaption><\/figure>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>I&#8217;ve also included a breadboard layout created i Fritzing. \u00a0 Although <a href=\"http:\/\/fritzing.org\/\" target=\"_blank\">Fritzing <\/a>has some bugs, its a great app for rapidly producing usable breadboard, PCB and Schamatics of your circuits. \u00a0I recommend it. \u00a0I almost forgot to mention the speaker. \u00a0This was a bit of an afterthought, but i had one laying around and thought it would be good to have some aural feedback when the touchpad was being used. \u00a0Glad I did it. \u00a0I have the LEDs ramp up\/down and it can lead the user to wonder if it&#8217;s working as it can take a few seconds to complete its on\/off cycle. \u00a0This way, I can add beeps and chirps to the interaction of the unit.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<figure id=\"attachment_1902\" aria-describedby=\"caption-attachment-1902\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.plastibots.com\/wordpress\/wp-content\/uploads\/2011\/03\/ArduinoLED_Schematic.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-1902 \" title=\"ArduinoLED_Schematic\" src=\"http:\/\/www.plastibots.com\/wordpress\/wp-content\/uploads\/2011\/03\/ArduinoLED_Schematic-300x166.jpg\" alt=\"Breadboard Layout\" width=\"300\" height=\"166\" srcset=\"https:\/\/www.plastibots.com\/wordpress\/wp-content\/uploads\/2011\/03\/ArduinoLED_Schematic-300x166.jpg 300w, https:\/\/www.plastibots.com\/wordpress\/wp-content\/uploads\/2011\/03\/ArduinoLED_Schematic.jpg 619w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-1902\" class=\"wp-caption-text\">Breadboard Layout<\/figcaption><\/figure>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"text-decoration: underline;\">The Sketch:<\/span><\/strong><\/p>\n<p>There are a few interesting things I thought I would point out about the sketch:<\/p>\n<ul>\n<li>To turn the Main LED on off &#8211; touch the center of the touchpad. \u00a0The Main LEDs will ramp up to max brightness (more on this later). \u00a0If they LED is on, it will ramp down to an OFF position.<\/li>\n<li>To manually control Main LED brightness, just slide your finger up\/down along the right side of the touchpad (where the arrows are). \u00a0There was an added bonus to the X values that Synaptics returned to the unit. \u00a0Any touch to the area of the right band returns an X value of 8176. This way, my conditional check only has to check the 1 X value and a range of Y values. \u00a0The Y values are mapped between 0 &#8211; 255 (the range of power to the LEDs)<\/li>\n<li>Delayed Time off &#8211; I have a feature that when the Main LED is on, clicking the top center will initiate a countdown timer of 10 minutes. \u00a0After which the Main LEDs will turn off.<\/li>\n<li>Secondary LED on\/off &#8211; clicking the top left corner of the touchpad will toggle the Secondary LED on or off (depending on its current state). \u00a0 I had to play around a bit with debouncing here as the loop cycle is ~20ms as it was catching multiple on\/off states (even with fast finger taps). \u00a0I used a simple delay in the code on this (did not want to get into fancy debouncing &#8211; will save that for the kitchen project)<\/li>\n<li>LED Brightness Save &#8211; I thought it would be cool to be able to save the Main LED brightness state. \u00a0Using the right slider, you can adjust the brightness of the Main LEDs. \u00a0When the desired level is reached, touching (and holding for approx 3 seconds) the bottom left area of the touchpad will save the brightness to EEPROM within the Arduino. \u00a0 \u00a0The next time the unit is powered up, it will only ramp up to the saved max brightness value. \u00a0 This is persistent even if the Arduino looses power. \u00a0 The only issue is that I can only do it up to approx 100,000 times. \u00a0Shucks&#8230;<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>Arduino Sketch: \u00a0<a href=\"http:\/\/www.plastibots.com\/wordpress\/wp-content\/uploads\/2011\/03\/LEDLightDimmer11.zip\">LEDLightDimmer11<\/a><\/p>\n<pre>\r\n\/*\r\nControl LED light strip via 12V power provided by parking lights (rear red). Additionally,\r\nthe actuation of the brake lights will also illuminate the LED strip at a brighter level to allow it to\r\nenhance the effectiveness and visibility of the rear brake lights\r\nDesign:\r\n12V main to power the arduino (ATTiny85) (via 3.3v regulated circuit). 12V main also directly powers the LED light strip.\r\nHowever, the Arduino will be used to control a MOSFET via PWM to act as a light level controller. On start\r\nthe LEDs will automatically 'ramp up' to specific light intensity, but not 100% power. When the brake lights\r\nare applied, the Arduino will detect this on an input pin and turn the LEDs on to full brightness, and then\r\nback off once the brakes are no longer applied.\r\n*\/\r\n\r\nbyte ledMaxVal = 255; \/\/Full LED brightness level - to be applied when brakes are on.\r\nbyte ledNormVal = 100; \/\/normal LED light level.\r\nboolean ledState = 0; \/\/The current state of the LEDs. 0=off 1=on\r\nboolean ledAtMax = 0;\r\n\/\/boolean brakeState = 0; \/\/The current state of the brake detected on brakePin. 0=off 1=on\r\n\/\/int brakeV = 0; \/\/Mapped value converted read from brakePin mapped from 0-1023 to 0-5V. Note Brake pin has a pull down resistor of 10K to have it read 0 by default.\r\nint flashCounter = 0;\r\nint brakeThresh = 500; \/\/brake threshold. Pin is high. When brakes applied, pin drops to near 0V. value in mV\r\n\r\n\/\/Configurable values\r\nconst int LEDPin = 1; \/\/output pin to control MOSFET switching to power the LED strip from 12V.\r\nconst int brakePin = 3; \/\/pin that will detect when brake lights are on.\r\nconst int LEDstatPin = 0;\r\n\r\nvoid flash() {\r\n  digitalWrite(LEDstatPin, HIGH);\r\n  delay(20);\r\n  digitalWrite(LEDstatPin, LOW);\r\n}\r\n\r\nvoid rampLEDDownNoff(byte lval, int dly)\r\n{\r\n  while (lval > 0)\r\n  {\r\n    analogWrite(LEDPin, lval);\r\n    lval--;\r\n    delay(dly);\r\n  }\r\n  \/\/make sure they are all off\r\n  digitalWrite(LEDPin, LOW);\r\n  ledState = 0;\r\n}\r\n\r\nvoid rampLEDupOn(byte lval, byte ledNormVal, int dly)\r\n{\r\n  while (lval < ledNormVal)\r\n  {\r\n    \/\/give the LED a pulsing look\r\n    \/\/if (lval > 20) {\r\n    \/\/analogWrite(LEDPin,20);\r\n    \/\/delay(5);\r\n    \/\/}\r\n    \/\/comment the above to get rid of the LED pulsing.\r\n\r\n    analogWrite(LEDPin, lval);\r\n    \/\/analogWrite(LEDstatPin, lval); \/\/flash the status LED to show that the LEDs are ramping up.\r\n    flash();\r\n    lval++;\r\n\r\n    \/\/often, the brake lights will be applied on vehicle start. If this is the case, then just go to full power on the LEDs and\r\n    \/\/stop the remp-up procedure\r\n    if (analogRead(brakePin) < brakeThresh) { \/\/ bail out on sensor detect\r\n      analogWrite(LEDPin, ledMaxVal);\r\n      ledState = 1;\r\n      break;\r\n    }\r\n\r\n    delay(dly);\r\n  }\r\n  ledState = 1;\r\n}\r\n\r\nvoid setup()\r\n{\r\n  \/\/Serial.begin(9600);\r\n  pinMode(LEDPin, OUTPUT);\r\n  pinMode(LEDstatPin, OUTPUT);\r\n  pinMode(brakePin, INPUT);\r\n}\r\n\r\nvoid loop()\r\n{\r\n\r\n  if (ledState == 0) \/\/LEDs are not on, turn them on.\r\n  {\r\n\r\n    rampLEDupOn(0, ledNormVal, 20);\r\n    analogWrite(LEDstatPin, 100);\r\n  }\r\n\r\n  else if (analogRead(brakePin) < brakeThresh) \/\/ledState would be 1\r\n    \/\/Optoisolator keeps brakePin Hi at 5V. When 12V applied (brake light), pulls brakePin low. Hi=1023. Just picked an arbitrary # of 500\r\n    \/\/if (analogRead(brakePin) < brakeThresh &#038;&#038; ledState == 1)\r\n  {\r\n    \/\/brakeState = 1;\r\n    analogWrite(LEDPin, ledMaxVal);\r\n    ledAtMax = 1;\r\n  }\r\n  else if (ledAtMax)\r\n  {\r\n    \/\/brakeState = 0;\r\n    analogWrite(LEDPin, ledNormVal);\r\n    ledAtMax = 0;\r\n  }\r\n\r\n  \/\/Serial.print(\"brkState=\");\r\n  \/\/ Serial.print(brakeState, DEC);\r\n  \/\/Serial.print(\" brkPinV=\");\r\n  \/\/ Serial.print(brakeV, DEC);\r\n  \/\/Serial.print(\" brkPinRaw=\");\r\n  \/\/Serial.print(analogRead(brakePin), DEC);\r\n  \/\/ Serial.print(\" flsCnt=\");\r\n  \/\/Serial.print(flashCounter, DEC);\r\n\r\n  \/\/Serial.println();\r\n\r\n  flashCounter++;\r\n\r\n  if (flashCounter == 20)\r\n  {\r\n    flash();\r\n    flashCounter = 0;\r\n  }\r\n\r\n  delay(20); \/\/give the processor some breathing time.\r\n  \/\/brakeV = 0;\r\n\r\n}\r\n\r\n\r\n\r\n\r\n\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been involved in microcontrollers for some time &#8211; but of the LEGO Mindstorms flavour (and BASIC Stamp to a lesser extent). Lately, I&#8217;ve jumped on the Arduino bandwagon. I&#8217;ve always had the natural nack to fix pretty much anything that has batteries or a plug running out of it. \u00a0As the Arduino revolution has picked up dramatically over the past few years, so to has my desire to do DIY projects around the house. &hellip; <a href=\"https:\/\/www.plastibots.com\/index.php\/2011\/03\/23\/dual-led-desk-light-controller-arduino\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[65,6,57],"tags":[64,66,73],"class_list":["post-1907","post","type-post","status-publish","format-standard","hentry","category-arduino-electronics","category-dyihacks","category-electronics","tag-arduino","tag-led","tag-resistive-touch","has_no_thumb"],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pK41j-uL","jetpack_sharing_enabled":true,"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/www.plastibots.com\/index.php\/wp-json\/wp\/v2\/posts\/1907","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.plastibots.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.plastibots.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.plastibots.com\/index.php\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.plastibots.com\/index.php\/wp-json\/wp\/v2\/comments?post=1907"}],"version-history":[{"count":0,"href":"https:\/\/www.plastibots.com\/index.php\/wp-json\/wp\/v2\/posts\/1907\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.plastibots.com\/index.php\/wp-json\/wp\/v2\/media?parent=1907"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.plastibots.com\/index.php\/wp-json\/wp\/v2\/categories?post=1907"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.plastibots.com\/index.php\/wp-json\/wp\/v2\/tags?post=1907"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}