{"id":94,"date":"2009-09-22T21:41:33","date_gmt":"2009-09-23T03:41:33","guid":{"rendered":"http:\/\/www.tamarziv.com\/itp\/?p=94"},"modified":"2010-01-20T16:44:33","modified_gmt":"2010-01-20T22:44:33","slug":"dark","status":"publish","type":"post","link":"https:\/\/www.tamarziv.com\/itp\/dark\/","title":{"rendered":"W2-Achluophobic LED"},"content":{"rendered":"<p>Or what would your LED do if it were sacred of the dark?<br \/>\nBuilding upon the lab example and adding a cell sensor into the mix, plus some simple programming.<br \/>\nThe trick was in calibrating the values correctly in order to achieve a pleasing effect.<\/p>\n<p><embed src=\"http:\/\/blip.tv\/play\/hLt5gaHoDwA\" type=\"application\/x-shockwave-flash\" width=\"650\" height=\"528\" allowscriptaccess=\"always\" allowfullscreen=\"true\"><\/embed><\/p>\n<p>Or what would your LED do if it were sacred of the dark?<br \/>\nBuilding upon the lab example and adding a cell sensor into the mix, plus some simple programming.<br \/>\nThe trick was in calibrating the values correctly in order to achieve a pleasing effect.<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;width:648px;height:300px;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/>6<br \/>7<br \/>8<br \/>9<br \/>10<br \/>11<br \/>12<br \/>13<br \/>14<br \/>15<br \/>16<br \/>17<br \/>18<br \/>19<br \/>20<br \/>21<br \/>22<br \/>23<br \/>24<br \/>25<br \/>26<br \/>27<br \/>28<br \/>29<br \/>30<br \/>31<br \/>32<br \/>33<br \/>34<br \/>35<br \/>36<br \/>37<br \/>38<br \/>39<br \/>40<br \/>41<br \/>42<br \/>43<br \/>44<br \/>45<br \/><\/div><\/td><td><div class=\"text codecolorer\">&lt;em&gt; int potPin = 0; &nbsp; &nbsp;\/\/ Analog input pin that the potentiometer is attached to<br \/>\n&nbsp;int potValue = 0; &nbsp; \/\/ value read from the pot<br \/>\n&nbsp;int cellPin = 1; &nbsp; &nbsp;\/\/ Analog input pin that the potentiometer is attached to<br \/>\n&nbsp;int cellValue = 0; &nbsp; \/\/ value read from the pot<br \/>\n&nbsp;int led = 9; &nbsp; &nbsp;\/\/ PWM pin that the LED is on. &nbsp;n.b. PWM 0 is on digital pin 9<br \/>\n<br \/>\n&nbsp;void setup() { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \/\/ initialize serial communications at 9600 bps:<br \/>\n&nbsp; &nbsp;Serial.begin(9600); <br \/>\n&nbsp;}<br \/>\n<br \/>\n&nbsp;void loop() {<br \/>\n&nbsp; &nbsp;cellValue = analogRead(cellPin); &nbsp; &nbsp; &nbsp;\/\/ Read the cell value<br \/>\n&nbsp; &nbsp;int outputCellValue = map(cellValue,1,25,1,1000); &nbsp;\/\/ map the cell value<br \/>\n&nbsp; &nbsp;Serial.println(&quot;Cell Value = &quot;); &nbsp; &nbsp; &nbsp;\/\/ print the cell tag<br \/>\n&nbsp; &nbsp;Serial.println(cellValue); &nbsp; &nbsp; &nbsp;\/\/ print the cell value back to the debugger pane<br \/>\n&nbsp; &nbsp;Serial.println(&quot;Cell output = &quot;); &nbsp; &nbsp; &nbsp;\/\/ print the cell tag<br \/>\n&nbsp; &nbsp;Serial.println(outputCellValue); &nbsp; &nbsp; &nbsp;\/\/ print the cell value back to the debugger pane<br \/>\n&nbsp; &nbsp;potValue = analogRead(potPin); \/\/ read the pot value<br \/>\n&nbsp; &nbsp;<br \/>\n&nbsp; &nbsp;if (outputCellValue&lt;320) { &nbsp; &nbsp; &nbsp; \/\/ check for light conditions<br \/>\n&nbsp; &nbsp; &nbsp;if (outputCellValue&lt;20) { &nbsp; &nbsp; &nbsp; \/\/ set low limit for behavior in extreme darkness &nbsp;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp;outputCellValue=20;<br \/>\n&nbsp; &nbsp; &nbsp;}<br \/>\n&nbsp; &nbsp; &nbsp;if (outputCellValue&gt;2000) { &nbsp; \/\/ set high limit for behavior in bright conditions<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp;outputCellValue=1950;<br \/>\n&nbsp; &nbsp; &nbsp;} &nbsp;<br \/>\n&nbsp; &nbsp; &nbsp;int delayVar = outputCellValue;<br \/>\n<br \/>\n&nbsp; &nbsp;\/\/Serial.println(&quot;delayVar = &quot;);<br \/>\n&nbsp; &nbsp;\/\/Serial.println(delayVar); &nbsp; &nbsp; &nbsp;\/\/ print the cell value back to the debugger pane<br \/>\n&nbsp; &nbsp;<br \/>\n&nbsp; &nbsp; &nbsp;analogWrite(led, potValue\/4); &nbsp;\/\/ PWM the LED with the pot value (divided by 4 to fit in a byte)<br \/>\n&nbsp; &nbsp; &nbsp;delay(delayVar); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \/\/ blink delay<br \/>\n&nbsp; &nbsp; &nbsp;analogWrite(led, 0); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \/\/ blink off<br \/>\n&nbsp; &nbsp; &nbsp;delay(delayVar); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\/\/ blink delay<br \/>\n&nbsp; &nbsp; &nbsp;\/\/ Serial.println(&quot;Dial Value:&quot;); &nbsp; &nbsp; &nbsp;\/\/ print the pot value back to the debugger pane<br \/>\n&nbsp; &nbsp; &nbsp;\/\/ Serial.println(potValue); &nbsp; &nbsp; &nbsp;\/\/ print the pot value back to the debugger pane<br \/>\n&nbsp; &nbsp;}<br \/>\n&nbsp; &nbsp;<br \/>\n&nbsp; &nbsp;else &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\/\/ Simply turn LED according to potentiometer values when in lit conditions<br \/>\n&nbsp; &nbsp;{<br \/>\n&nbsp; &nbsp; analogWrite(led, potValue\/4); <br \/>\n&nbsp; &nbsp;}<br \/>\n&nbsp; &nbsp;delay(20); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \/\/ wait 10 milliseconds before the next loop<br \/>\n&nbsp;}&lt;\/em&gt;<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Or what would your LED do if it were sacred of the dark? Building upon the lab example and adding a cell sensor into the mix, plus some simple programming. The trick was in calibrating the values correctly in order to achieve a pleasing effect.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[5],"tags":[],"class_list":["post-94","post","type-post","status-publish","format-standard","hentry","category-p_comp"],"_links":{"self":[{"href":"https:\/\/www.tamarziv.com\/itp\/wp-json\/wp\/v2\/posts\/94","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tamarziv.com\/itp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tamarziv.com\/itp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tamarziv.com\/itp\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tamarziv.com\/itp\/wp-json\/wp\/v2\/comments?post=94"}],"version-history":[{"count":19,"href":"https:\/\/www.tamarziv.com\/itp\/wp-json\/wp\/v2\/posts\/94\/revisions"}],"predecessor-version":[{"id":322,"href":"https:\/\/www.tamarziv.com\/itp\/wp-json\/wp\/v2\/posts\/94\/revisions\/322"}],"wp:attachment":[{"href":"https:\/\/www.tamarziv.com\/itp\/wp-json\/wp\/v2\/media?parent=94"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tamarziv.com\/itp\/wp-json\/wp\/v2\/categories?post=94"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tamarziv.com\/itp\/wp-json\/wp\/v2\/tags?post=94"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}