{"id":211,"date":"2009-10-10T18:03:09","date_gmt":"2009-10-11T00:03:09","guid":{"rendered":"http:\/\/www.tamarziv.com\/itp\/?p=211"},"modified":"2009-10-15T10:07:04","modified_gmt":"2009-10-15T16:07:04","slug":"w4-stupid-pet-trick","status":"publish","type":"post","link":"https:\/\/www.tamarziv.com\/itp\/w4-stupid-pet-trick\/","title":{"rendered":"W4-Stupid Pet Trick"},"content":{"rendered":"<p>My stupid pet trick started at the junk shelf, where I happened to find an old Zip drive, I liked the idea of having a clean translucent case to hide my dirty electronic circuitry crafting skills. I knew I wanted it to have one obvious control and others which are hidden and discrete, that effect the behavior of the device in an unapparent manner. Since me little case had one button, a door and a USB port, I figured, why not use these. <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.tamarziv.com\/itp\/wp-content\/themes\/tma\/images\/uploads\/ITP30-1.jpg\" alt=\"ITP30-1\" title=\"ITP30-1\" width=\"650\" height=\"488\" class=\"alignnone size-full wp-image-212\" srcset=\"https:\/\/www.tamarziv.com\/itp\/wp-content\/themes\/tma\/images\/uploads\/ITP30-1.jpg 650w, https:\/\/www.tamarziv.com\/itp\/wp-content\/themes\/tma\/images\/uploads\/ITP30-1-300x225.jpg 300w\" sizes=\"auto, (max-width: 650px) 100vw, 650px\" \/><\/p>\n<p>I decided to drill a hole in the shell for a potentiometer, kind of &#8220;in your face&#8221; obvious interface. After that I went on trying to figure out how to use the flap door and make it work with an FSR. Hiding a photocell behind the button hole for some extra input, and finally adding a vibrating motor connected to some rattling parts from the zip drive itself to give some nice buzzy feedback. And of course the LED&#8217;s. those RGB ones are really fun but hard to figure out how to control at first.  <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.tamarziv.com\/itp\/wp-content\/themes\/tma\/images\/uploads\/ITP30-10.jpg\" alt=\"ITP30-10\" title=\"ITP30-10\" width=\"650\" height=\"488\" class=\"alignnone size-full wp-image-214\" srcset=\"https:\/\/www.tamarziv.com\/itp\/wp-content\/themes\/tma\/images\/uploads\/ITP30-10.jpg 650w, https:\/\/www.tamarziv.com\/itp\/wp-content\/themes\/tma\/images\/uploads\/ITP30-10-300x225.jpg 300w\" sizes=\"auto, (max-width: 650px) 100vw, 650px\" \/><\/p>\n<p>This is how it looked like with all the pieced put in place and a simple &#8220;blink&#8221; running through the arduino just to make sure everything works as it should, and all that is left is writing the code!<\/p>\n<p><object width=\"650\" height=\"488\"><param name=\"allowfullscreen\" value=\"true\" \/><param name=\"allowscriptaccess\" value=\"always\" \/><param name=\"movie\" value=\"http:\/\/vimeo.com\/moogaloop.swf?clip_id=7082260&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=00ADEF&amp;fullscreen=1\" \/><embed src=\"http:\/\/vimeo.com\/moogaloop.swf?clip_id=7082260&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=00ADEF&amp;fullscreen=1\" type=\"application\/x-shockwave-flash\" allowfullscreen=\"true\" allowscriptaccess=\"always\" width=\"650\" height=\"488\"><\/embed><\/object><\/p>\n<p>I was aiming to create a neat spectrum effect controlled by the pot, for which I had to map out when to fade each color in and out to get a smooth transition, evidently, this didn&#8217;t work too well at first because I didn&#8217;t figure out the fading right, and because I didn&#8217;t feed the LED&#8217;s with enough power using the wrong resistors, and because values over 255 create an odd flickering effect&#8230;<\/p>\n<p><object width=\"650\" height=\"488\"><param name=\"allowfullscreen\" value=\"true\" \/><param name=\"allowscriptaccess\" value=\"always\" \/><param name=\"movie\" value=\"http:\/\/vimeo.com\/moogaloop.swf?clip_id=7082552&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=00ADEF&amp;fullscreen=1\" \/><embed src=\"http:\/\/vimeo.com\/moogaloop.swf?clip_id=7082552&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=00ADEF&amp;fullscreen=1\" type=\"application\/x-shockwave-flash\" allowfullscreen=\"true\" allowscriptaccess=\"always\" width=\"650\" height=\"488\"><\/embed><\/object><\/p>\n<p>This is my finished result, my stupid little, paranoid neurotic with box with shiny spectrum lights. I&#8217;m proud of this little thing. Hopefully I&#8217;ll make use of the zip drive shell for future projects as a controller of sorts.<embed src=\"http:\/\/blip.tv\/play\/hLt5gablQQA\" type=\"application\/x-shockwave-flash\" width=\"650\" height=\"528\" allowscriptaccess=\"always\" allowfullscreen=\"true\"><\/embed><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 \/>46<br \/>47<br \/>48<br \/>49<br \/>50<br \/>51<br \/>52<br \/>53<br \/>54<br \/>55<br \/>56<br \/>57<br \/>58<br \/>59<br \/>60<br \/>61<br \/>62<br \/>63<br \/>64<br \/>65<br \/>66<br \/>67<br \/>68<br \/>69<br \/>70<br \/>71<br \/>72<br \/>73<br \/>74<br \/>75<br \/>76<br \/>77<br \/>78<br \/>79<br \/>80<br \/>81<br \/>82<br \/>83<br \/>84<br \/>85<br \/>86<br \/>87<br \/>88<br \/>89<br \/>90<br \/>91<br \/>92<br \/>93<br \/>94<br \/>95<br \/>96<br \/>97<br \/>98<br \/>99<br \/>100<br \/>101<br \/>102<br \/>103<br \/>104<br \/>105<br \/>106<br \/>107<br \/>108<br \/>109<br \/>110<br \/>111<br \/>112<br \/>113<br \/>114<br \/>115<br \/>116<br \/>117<br \/>118<br \/>119<br \/>120<br \/>121<br \/>122<br \/>123<br \/>124<br \/>125<br \/>126<br \/>127<br \/>128<br \/>129<br \/>130<br \/>131<br \/>132<br \/>133<br \/>134<br \/>135<br \/>136<br \/>137<br \/>138<br \/>139<br \/>140<br \/>141<br \/>142<br \/>143<br \/>144<br \/>145<br \/>146<br \/>147<br \/>148<br \/>149<br \/>150<br \/>151<br \/>152<br \/>153<br \/>154<br \/>155<br \/>156<br \/>157<br \/><\/div><\/td><td><div class=\"text codecolorer\">int potReadoutPin = 0; \/\/ pot pin<br \/>\nint fsrReadoutPin = 1; \/\/ fsr pin<br \/>\nint cellReadoutPin = 2; \/\/ cell pin<br \/>\nint vibMotorPin = 7; \/\/ motor pin<br \/>\nint redLEDPin = 8; \/\/ red pin<br \/>\nint greenLEDPin = 9; \/\/ green pin<br \/>\nint blueLEDPin = 10; \/\/ blue pin<br \/>\n<br \/>\nint potReadout = 0; \/\/ value pot switch<br \/>\nint fsrReadout = 0; \/\/ value fsr sensor<br \/>\nint cellReadout = 0; \/\/ value cell sensor<br \/>\n<br \/>\nint potReadoutPrevious = 0; \/\/ var to detect state change<br \/>\nint previousCellReadout = 0; \/\/ var to detect state change <br \/>\nint potPowerout = 0; \/\/ output to LED<br \/>\nint potZones = 0; \/\/ dividing pot areas<br \/>\nint potMap = 0; \/\/ mapping pot values to map<br \/>\n<br \/>\nint levelLED = 0; \/\/ set LED level<br \/>\nint maxLevelLED = 255; \/\/ set max LED level<br \/>\nint minLevelLED = 0; \/\/ set min LED level<br \/>\nint fadeLevelLED = 0; \/\/ set fade LED level<br \/>\n<br \/>\nint cellMin = 5; \/\/ define darkness<br \/>\nint cellMax = 55; \/\/ define max lightness<br \/>\nint cellMap = 0; \/\/ map values o fit max and min<br \/>\n<br \/>\nlong previousMillis = 0; \/\/ last time one interval passed<br \/>\nlong interval = 100; \/\/ interval<br \/>\n<br \/>\n\/\/ unused vars<br \/>\nint rOn = 0;<br \/>\nint gOn = 0;<br \/>\nint bOn = 0;<br \/>\n<br \/>\nvoid setup () {<br \/>\n&nbsp; \/\/ start serial<br \/>\n&nbsp; Serial.begin(9600);<br \/>\n&nbsp; \/\/ define pins<br \/>\n&nbsp; pinMode (redLEDPin, OUTPUT); <br \/>\n&nbsp; pinMode (blueLEDPin, OUTPUT);<br \/>\n&nbsp; pinMode (greenLEDPin, OUTPUT);<br \/>\n&nbsp; pinMode (vibMotorPin, OUTPUT); &nbsp;<br \/>\n&nbsp; pinMode (potReadoutPin, INPUT);<br \/>\n&nbsp; pinMode (fsrReadoutPin, INPUT);<br \/>\n&nbsp; pinMode (cellReadoutPin, INPUT);<br \/>\n<br \/>\n}<br \/>\n<br \/>\nvoid loop () {<br \/>\n&nbsp; \/\/ read hidden interface sensors<br \/>\n&nbsp; fsrReadout = analogRead(fsrReadoutPin);<br \/>\n&nbsp; cellReadout = analogRead(cellReadoutPin);<br \/>\n<br \/>\n\/\/ &nbsp;debug printing<br \/>\n\/\/ &nbsp;Serial.println(fsrReadout, DEC);<br \/>\n\/\/ &nbsp;delay(15);<br \/>\n&nbsp; <br \/>\n&nbsp; potReadout = analogRead(potReadoutPin); \/\/ read pot<br \/>\n&nbsp; potPowerout = map(potReadout, 0, 1023, 0, 1529); \/\/ remap pot to measures of 255 to power LED<br \/>\n&nbsp; potZones = map(potReadout, 0 , 1023, 0, 119); \/\/ remap pot to define zones for if funct<br \/>\n&nbsp; levelLED = potPowerout % 255; \/\/ derive LED power value from pot<br \/>\n&nbsp; fadeLevelLED = maxLevelLED - levelLED; \/\/ derive fade value, opposite to pot<br \/>\n&nbsp; int redComp = 100; \/\/ compensate problems with red LED resistors<br \/>\n&nbsp; cellMap = map(cellReadout, cellMin, cellMax, 0, 500); \/\/ map photocell to room conditions<br \/>\n<br \/>\n&nbsp; &nbsp; Serial.println(cellMap, DEC); \/\/ print cell value (debug\/adjust) <br \/>\n&nbsp; &nbsp; Serial.println(cellReadout, DEC); \/\/ print cell value (debug\/adjust) <br \/>\n&nbsp; <br \/>\n&nbsp; if (cellMap&gt;500) { \/\/ when far from light sensor - spectrum effect<br \/>\n&nbsp; &nbsp; if (potZones &gt; 0 &amp;&amp; potZones &lt; 20) { analogWrite (10, levelLED); bOn = 1;} <br \/>\n&nbsp; &nbsp; if (potZones &gt;= 20 &amp;&amp; potZones &lt; 60) { analogWrite (10, maxLevelLED); bOn = 1; } <br \/>\n&nbsp; &nbsp; if (potZones &gt;= 60 &amp;&amp; potZones &lt;= 79) { analogWrite (10, fadeLevelLED); bOn = 1; } <br \/>\n&nbsp; &nbsp; if (potZones &lt;= 0 || potZones &gt; 79) { analogWrite (10, minLevelLED); bOn = 0; }<br \/>\n&nbsp; &nbsp;<br \/>\n&nbsp; &nbsp; if (potZones &gt; 40 &amp;&amp; potZones &lt; 60) { analogWrite (9, levelLED); gOn = 1;} <br \/>\n&nbsp; &nbsp; if (potZones &gt;= 60 &amp;&amp; potZones &lt; 100) { analogWrite (9, maxLevelLED); gOn = 1; } <br \/>\n&nbsp; &nbsp; if (potZones &gt;= 100 &amp;&amp; potZones &lt;= 119) { analogWrite (9, fadeLevelLED); gOn = 1;} <br \/>\n&nbsp; &nbsp; if (potZones &lt;= 40 || potZones &gt; 119) { analogWrite (9, minLevelLED); gOn = 0;}<br \/>\n&nbsp; &nbsp; <br \/>\n&nbsp; &nbsp; if (potZones &gt; 0 &amp;&amp; potZones &lt; 20) { analogWrite (8, levelLED+redComp); rOn = 1; } <br \/>\n&nbsp; &nbsp; if (potZones &gt;= 20 &amp;&amp; potZones &lt; 40) { analogWrite (8, fadeLevelLED-redComp); rOn = 1; } <br \/>\n&nbsp; &nbsp; if (potZones &gt;= 40 &amp;&amp; potZones &lt;= 80) { analogWrite (8, minLevelLED); rOn = 0; }<br \/>\n&nbsp; &nbsp; if (potZones &gt; 80 &amp;&amp; potZones &lt; 100) { analogWrite (8, levelLED+redComp); rOn = 1; } <br \/>\n&nbsp; &nbsp; if (potZones &gt;= 100) { analogWrite (8, maxLevelLED); rOn = 1; }<br \/>\n&nbsp; &nbsp; if (potZones &lt;= 0) { analogWrite (8, minLevelLED); rOn = 0; }<br \/>\n&nbsp; &nbsp;<br \/>\n&nbsp; } else {<br \/>\n&nbsp; <br \/>\n&nbsp; &nbsp; <br \/>\n&nbsp; if (cellMap&lt;0) { cellMap=10; } \/\/ set min value for cellMap<br \/>\n&nbsp; <br \/>\n&nbsp; if (millis() - previousMillis &gt; interval) { \/\/ when close from light sensor - flickering spectrum effect<br \/>\n&nbsp; &nbsp; if (potZones &gt; 0 &amp;&amp; potZones &lt; 20) { analogWrite (10, levelLED); bOn = 1;} <br \/>\n&nbsp; &nbsp; if (potZones &gt;= 20 &amp;&amp; potZones &lt; 60) { analogWrite (10, maxLevelLED); bOn = 1; } <br \/>\n&nbsp; &nbsp; if (potZones &gt;= 60 &amp;&amp; potZones &lt;= 79) { analogWrite (10, fadeLevelLED); bOn = 1; } <br \/>\n&nbsp; &nbsp; if (potZones &lt;= 0 || potZones &gt; 79) { analogWrite (10, minLevelLED); bOn = 0; }<br \/>\n&nbsp; &nbsp;<br \/>\n&nbsp; &nbsp; if (potZones &gt; 40 &amp;&amp; potZones &lt; 60) { analogWrite (9, levelLED); gOn = 1;} <br \/>\n&nbsp; &nbsp; if (potZones &gt;= 60 &amp;&amp; potZones &lt; 100) { analogWrite (9, maxLevelLED); gOn = 1; } <br \/>\n&nbsp; &nbsp; if (potZones &gt;= 100 &amp;&amp; potZones &lt;= 119) { analogWrite (9, fadeLevelLED); gOn = 1;} <br \/>\n&nbsp; &nbsp; if (potZones &lt;= 40 || potZones &gt; 119) { analogWrite (9, minLevelLED); gOn = 0;}<br \/>\n&nbsp; &nbsp; <br \/>\n&nbsp; &nbsp; if (potZones &gt; 0 &amp;&amp; potZones &lt; 20) { analogWrite (8, levelLED+redComp); rOn = 1; } <br \/>\n&nbsp; &nbsp; if (potZones &gt;= 20 &amp;&amp; potZones &lt; 40) { analogWrite (8, fadeLevelLED-redComp); rOn = 1; } <br \/>\n&nbsp; &nbsp; if (potZones &gt;= 40 &amp;&amp; potZones &lt;= 80) { analogWrite (8, minLevelLED); rOn = 0; }<br \/>\n&nbsp; &nbsp; if (potZones &gt; 80 &amp;&amp; potZones &lt; 100) { analogWrite (8, levelLED+redComp); rOn = 1; } <br \/>\n&nbsp; &nbsp; if (potZones &gt;= 100) { analogWrite (8, maxLevelLED); rOn = 1; }<br \/>\n&nbsp; &nbsp; if (potZones &lt;= 0) { analogWrite (8, minLevelLED); rOn = 0; }<br \/>\n&nbsp; &nbsp; delay (cellMap); \/\/ blink<br \/>\n&nbsp; &nbsp; previousMillis = millis(); \/\/ reset interval<br \/>\n&nbsp; &nbsp; <br \/>\n&nbsp; } else { \/\/ kill the lights<br \/>\n&nbsp; &nbsp; analogWrite (8, minLevelLED);<br \/>\n&nbsp; &nbsp; analogWrite (9, minLevelLED);<br \/>\n&nbsp; &nbsp; analogWrite (10, minLevelLED);<br \/>\n&nbsp; }<br \/>\n<br \/>\n&nbsp; }<br \/>\n<br \/>\n&nbsp; <br \/>\n&nbsp;\/* if (potReadout &lt; 79 &amp;&amp; potReadout &gt; 39) {<br \/>\n&nbsp; &nbsp; analogWrite(9, levelLED);<br \/>\n&nbsp; }<br \/>\n&nbsp; else {<br \/>\n&nbsp; &nbsp; analogWrite(9, fadeLED); }<br \/>\n<br \/>\n*\/<br \/>\n&nbsp; &nbsp; <br \/>\n\/\/ &nbsp;if (potReadout != potReadoutPrevious) {<br \/>\n\/\/ &nbsp;Serial.println(potReadout, DEC);<br \/>\n\/\/ &nbsp;Serial.println(levelLED, DEC);<br \/>\n\/\/ &nbsp;potReadoutPrevious = potReadout;<br \/>\n\/\/ &nbsp;}<br \/>\n<br \/>\n&nbsp; <br \/>\n&nbsp; <br \/>\n<br \/>\n&nbsp;\/\/ delay(15);<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;if (fsrReadout &gt; 400) { \/\/ alarm sequence when pushing door<br \/>\n&nbsp; &nbsp;for ( int i = 0; i &lt; 5; i++) {<br \/>\n&nbsp; digitalWrite(redLEDPin, LOW);<br \/>\n&nbsp; digitalWrite(greenLEDPin, LOW);<br \/>\n&nbsp; digitalWrite(blueLEDPin, LOW);<br \/>\n&nbsp; &nbsp;<br \/>\n&nbsp; digitalWrite(redLEDPin, HIGH);<br \/>\n&nbsp; digitalWrite(vibMotorPin, HIGH); <br \/>\n&nbsp; delay (500);<br \/>\n&nbsp; digitalWrite(redLEDPin, LOW);<br \/>\n&nbsp; digitalWrite(vibMotorPin, LOW);<br \/>\n&nbsp; delay (500); <br \/>\n&nbsp; <br \/>\n&nbsp;}<br \/>\n&nbsp;}<br \/>\n}<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n","protected":false},"excerpt":{"rendered":"<p>My stupid pet trick started at the junk shelf, where I happened to find an old Zip drive, I liked the idea of having a clean translucent case to hide my dirty electronic circuitry crafting skills. I knew I wanted it to have one obvious control and others which are hidden and discrete, that effect [&hellip;]<\/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-211","post","type-post","status-publish","format-standard","hentry","category-p_comp"],"_links":{"self":[{"href":"https:\/\/www.tamarziv.com\/itp\/wp-json\/wp\/v2\/posts\/211","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=211"}],"version-history":[{"count":12,"href":"https:\/\/www.tamarziv.com\/itp\/wp-json\/wp\/v2\/posts\/211\/revisions"}],"predecessor-version":[{"id":218,"href":"https:\/\/www.tamarziv.com\/itp\/wp-json\/wp\/v2\/posts\/211\/revisions\/218"}],"wp:attachment":[{"href":"https:\/\/www.tamarziv.com\/itp\/wp-json\/wp\/v2\/media?parent=211"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tamarziv.com\/itp\/wp-json\/wp\/v2\/categories?post=211"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tamarziv.com\/itp\/wp-json\/wp\/v2\/tags?post=211"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}