{"id":141,"date":"2008-10-23T08:20:35","date_gmt":"2008-10-23T12:20:35","guid":{"rendered":"http:\/\/mikelberman.com\/blog\/?p=141"},"modified":"2008-10-23T08:20:35","modified_gmt":"2008-10-23T12:20:35","slug":"electro-magnate","status":"publish","type":"post","link":"http:\/\/mikelberman.com\/blog\/?p=141","title":{"rendered":"Electro-Magnate"},"content":{"rendered":"<p><object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" width=\"425\" height=\"344\" codebase=\"http:\/\/download.macromedia.com\/pub\/shockwave\/cabs\/flash\/swflash.cab#version=6,0,40,0\"><param name=\"allowFullScreen\" value=\"true\" \/><param name=\"src\" value=\"http:\/\/www.youtube.com\/v\/F3BvYeuwHN4&amp;hl=en&amp;fs=1\" \/><embed type=\"application\/x-shockwave-flash\" width=\"425\" height=\"344\" src=\"http:\/\/www.youtube.com\/v\/F3BvYeuwHN4&amp;hl=en&amp;fs=1\" allowfullscreen=\"true\"><\/embed><\/object><\/p>\n<p>It&#8217;s 8:08 AM&#8230; yes people, 808.  and i did consume 8+8 caffeinated beverages over the course of the last 22 hours I&#8217;ve been P-Comping.  I&#8217;m not great on documentation after I crash out, but here&#8217;s some Arduino code.<\/p>\n<p>int incomingByte = 0;<\/p>\n<p>\/\/servo variables<\/p>\n<p>int servoPin = 2;\u00a0\u00a0\u00a0\u00a0 \/\/ Control pin for servo motor<\/p>\n<p>int minPulse = 500;\u00a0\u00a0 \/\/ Minimum servo position<\/p>\n<p>int maxPulse = 2500;\u00a0 \/\/ Maximum servo position<\/p>\n<p>int pulse = 0;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ Amount to pulse the servo<\/p>\n<p>int increment = 50; \/\/there are 40 gear teeth of planar movement<\/p>\n<p>\/\/the servo has 2000 explicit values<\/p>\n<p>\/\/this means 1 tooth is our greatest resolution of movement<\/p>\n<p>\/\/ergo, pulse50 = 1 tooth<\/p>\n<p>\/\/so if we move 5 times\/sec, which is 250pulse\/sec<\/p>\n<p>\/\/the total render time is 8 seconds<\/p>\n<p>int movePerSec = 5; \/\/ how quickly we are rendering the model<\/p>\n<p>int delayTime = 10000 \/ movePerSec; \/\/determines proper delay<\/p>\n<p>\/\/pixels<\/p>\n<p>int incomingBytes[9]={255,255,255,255,255,255,255,255,255}; \/\/set all pins to white<\/p>\n<p>int currentPinVal[9];<\/p>\n<p>int pixelPin=9; \/\/set pixel\u00a0 pin<\/p>\n<p>long lastPulse = 0;\u00a0\u00a0\u00a0 \/\/ the time in milliseconds of the last pulse<\/p>\n<p>int refreshTime = 20; \/\/ the time needed in between pulses<\/p>\n<p>int analogValue = 0;\u00a0 \/\/ the value returned from the analog sensor<\/p>\n<p>int analogPin = 0;\u00a0\u00a0\u00a0 \/\/ the analog pin that the sensor&#8217;s on<\/p>\n<p>void setup(){<\/p>\n<p>pinMode(servoPin, OUTPUT);\u00a0 \/\/ Set servo pin as an output pin<\/p>\n<p>pinMode(pixelPin, OUTPUT);<\/p>\n<p>pulse = minPulse;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ Set the motor position value to the minimum<\/p>\n<p>Serial.begin(9600);<\/p>\n<p>}<\/p>\n<p>void loop(){<\/p>\n<p>if(Serial.available() &gt; 0)<\/p>\n<p>{<\/p>\n<p>incomingBytes[8]=Serial.read(); \/\/just read the 9th pixel<\/p>\n<p>\/\/get values &amp; map to usable servo data<\/p>\n<p>for(i=0;i&lt;9;i++)<\/p>\n<p>{<\/p>\n<p>\/\/incomingBytes[i]=Serial.read();\u00a0\u00a0 \/\/get pixel values from Processing<\/p>\n<p>currentPinVal[i] = map(incomingBytes[i], 0, 255, 500, 2500); \/\/change brightness value to depth<\/p>\n<p>Serial.print(&#8220;I received: &#8220;);<\/p>\n<p>Serial.println(incomingBytes[i]);<\/p>\n<p>}<\/p>\n<p>\/\/place servo at first position<\/p>\n<p>digitalWrite(servoPin, HIGH);\u00a0\u00a0 \/\/ Turn the motor on<\/p>\n<p>delayMicroseconds(pulse);\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ Length of the pulse sets the motor position<\/p>\n<p>digitalWrite(servoPin, LOW);\u00a0\u00a0\u00a0 \/\/ Turn the motor off<\/p>\n<p>lastPulse = millis();\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ save the time of the last pulse<\/p>\n<p>}<\/p>\n<p>\/\/delay(100);<\/p>\n<p>\/\/pulse = map(incomingByte, 0, 255, minPulse, maxPulse); \/\/changing brightness value to servo position<\/p>\n<p>\/\/ pulse the servo again if rhe refresh time (20 ms) have passed:<\/p>\n<p>\/\/TO ADD: conditional servo reset to 500 &amp; resetting magnets back on<\/p>\n<p>\/\/ also, check if all magnets are off<\/p>\n<p>if (millis() &#8211; lastPulse &gt;= refreshTime)<\/p>\n<p>{<\/p>\n<p>if(pulse &gt;= currentPinVal[0])\/\/if we are have passed the pin&#8217;s value<\/p>\n<p>{<\/p>\n<p>digitalWrite(pixelPin, LOW)\/\/turn off magnet through transistor<\/p>\n<p>}<\/p>\n<p>else<\/p>\n<p>{<\/p>\n<p>digitalWrite(servoPin, HIGH);\u00a0\u00a0 \/\/ Turn the motor on<\/p>\n<p>delayMicroseconds(pulse);\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ Length of the pulse sets the motor position<\/p>\n<p>digitalWrite(servoPin, LOW);\u00a0\u00a0\u00a0 \/\/ Turn the motor off<\/p>\n<p>lastPulse = millis();\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ save the time of the last pulse<\/p>\n<p>pulse += increment;<\/p>\n<p>delay(delayTime);<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>It&#8217;s 8:08 AM&#8230; yes people, 808. and i did consume 8+8 caffeinated beverages over the course of the last 22 hours I&#8217;ve been P-Comping. I&#8217;m not great on documentation after I crash out, but here&#8217;s some Arduino code. int incomingByte = 0; \/\/servo variables int servoPin = 2;\u00a0\u00a0\u00a0\u00a0 \/\/ Control pin for servo motor int [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18,1],"tags":[12,14,322,16],"class_list":["post-141","post","type-post","status-publish","format-standard","hentry","category-physical-computing","category-uncategorized","tag-itp","tag-magnet","tag-physical-computing","tag-pin-model"],"_links":{"self":[{"href":"http:\/\/mikelberman.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/141","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/mikelberman.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/mikelberman.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/mikelberman.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/mikelberman.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=141"}],"version-history":[{"count":2,"href":"http:\/\/mikelberman.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/141\/revisions"}],"predecessor-version":[{"id":143,"href":"http:\/\/mikelberman.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/141\/revisions\/143"}],"wp:attachment":[{"href":"http:\/\/mikelberman.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=141"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/mikelberman.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=141"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/mikelberman.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=141"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}