<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-8077223744586062132</id><updated>2012-02-15T22:57:27.661-08:00</updated><category term='Make'/><category term='Web Cam'/><category term='LadyAda'/><category term='Attiny45'/><category term='Dremel'/><category term='plank'/><category term='RBB'/><category term='CNC'/><category term='FTDI'/><category term='Attiny85'/><category term='MIT'/><category term='Duemilanova'/><category term='C#'/><category term='Power Switch Tail'/><category term='g-code'/><category term='Radio Shack'/><category term='Arduino'/><category term='Halloween'/><category term='Stepper'/><category term='Servo'/><category term='Adafruit'/><category term='PC'/><category term='Motor Shield'/><category term='Attiny2313'/><category term='.NET'/><title type='text'>Jim Wink's Make Blog</title><subtitle type='html'>My blog on making things, mostly electronics fun with Arduino. Plus probably some observations on other cool stuff I see people making.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://winkmake.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8077223744586062132/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://winkmake.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Jwink</name><uri>http://www.blogger.com/profile/07356738572886578752</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://1.bp.blogspot.com/_LHP9sz9ANuQ/SWrQ95K1ecI/AAAAAAAAADw/Y3VUIKi1xy0/S220/DSCF4218_face.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>20</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-8077223744586062132.post-6094313102555915609</id><published>2011-10-16T21:03:00.000-07:00</published><updated>2011-10-16T21:08:52.924-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MIT'/><category scheme='http://www.blogger.com/atom/ns#' term='Attiny85'/><category scheme='http://www.blogger.com/atom/ns#' term='Attiny2313'/><category scheme='http://www.blogger.com/atom/ns#' term='Attiny45'/><category scheme='http://www.blogger.com/atom/ns#' term='Arduino'/><category scheme='http://www.blogger.com/atom/ns#' term='Adafruit'/><title type='text'>Atiny85</title><content type='html'>&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;A while back I ordered an &lt;a href="http://www.atmel.com/dyn/products/product_card.asp?part_id=3229"&gt;Attiny 2313&lt;/a&gt; from &lt;a href="http://adafruit.com/"&gt;Adafruit&lt;/a&gt;. Along with it I ordered a &lt;a href="http://www.adafruit.com/products/46"&gt;USBtinyISP&lt;/a&gt; to program it. For whatever reason I could never get the thing working.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;The process involved downloading &lt;a href="http://tinkerlog.com/2007/07/15/avrdude-54-for-windows/"&gt;AVRDude&lt;/a&gt;, &lt;a href="http://winavr.sourceforge.net/"&gt;WinAVR&lt;/a&gt;, and various steps of setup. After getting everything installed &amp;amp; following the instructions carefully, I still couldn't get it to work. I did submit some questions on &lt;a href="http://forums.adafruit.com/viewforum.php?f=20&amp;amp;sid=d8401655409b4f0f82d27a206e531b10"&gt;Adafruit's&lt;/a&gt; forum &amp;amp; got some answers, but I suspect the problem was either I'd made a mistake in assembling the&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&amp;nbsp;&lt;a href="http://www.adafruit.com/products/46"&gt;USBtinyISP&lt;/a&gt;&amp;nbsp;or just my general lack of understanding of what was going on. It was also possible I'd wrecked the chip, so I gave up after a while.&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;Later I decided it might have been better to take myself out of the equation, so again I ordered another programmer and some chips, this time from Sparkfun: a &lt;a href="http://www.sparkfun.com/products/9825"&gt;Pocket AVR programmer&lt;/a&gt;, another &lt;a href="http://www.sparkfun.com/products/212"&gt;Attiny 2313&lt;/a&gt; and an &lt;a href="http://www.sparkfun.com/products/9378"&gt;Attiny85&lt;/a&gt;. So far I've not gotten around to trying out their AVR programmer &amp;amp; until recently the chips stayed in their wrapping.&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;Recently I ran across an &lt;a href="http://hlt.media.mit.edu/?p=1229"&gt;article from MIT&lt;/a&gt; outlining how to program the Attiny85 with an &lt;a href="http://www.arduino.cc/"&gt;Arduino&lt;/a&gt;. I'd heard about people doing this before, but never really looked into it. After reading this article, though, it seemed easy. So I tried it.&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-BA8Zn2nZRTU/Tpuc-QI1BNI/AAAAAAAAAVU/zWrUA5lZgTY/s1600/DSCF4262.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="240" src="http://3.bp.blogspot.com/-BA8Zn2nZRTU/Tpuc-QI1BNI/AAAAAAAAAVU/zWrUA5lZgTY/s320/DSCF4262.JPG" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;It worked, though there was one item of confusion from the article. It said I'd need a capacitor between the reset and the ground on the Arduino, but only if I was using an Uno. Not something I'd need on the Duemilanova. Not true. I could not get the thing working right until I dropped a capacitor between the two. It said I'd need a 10 uf capacitor, but since I wasn't sure what exactly I had I just tried something. Worked fine.&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;The article started me off with the basic blink out of the Arduino examples. Instead of using pin 13 you use 0:&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;pre style="border: 1px inset; ext-align: left; font-family: Courier New, monospace; height: 150px; margin: 0px; overflow: auto; padding: 6px; width: 100%;"&gt;/*&lt;br /&gt;  Blink&lt;br /&gt;  Turns on an LED on for one second, then off for one second, repeatedly.&lt;br /&gt; &lt;br /&gt;  This example code is in the public domain.&lt;br /&gt; */&lt;br /&gt;&lt;br /&gt;void setup() {                &lt;br /&gt;  // initialize the digital pin as an output.&lt;br /&gt;  // Pin 13 has an LED connected on most Arduino boards:&lt;br /&gt;  pinMode(0, OUTPUT);     &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void loop() {&lt;br /&gt;  digitalWrite(0, HIGH);   // set the LED on&lt;br /&gt;  delay(1000);              // wait for a second&lt;br /&gt;  digitalWrite(0, LOW);    // set the LED off&lt;br /&gt;  delay(1000);              // wait for a second&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;I'd recorded a video of this but won't post it here because, well, blink? Boring.&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;What I wanted to do with this instead was &lt;a href="http://en.wikipedia.org/wiki/Morse_code"&gt;Morse code&lt;/a&gt;. I'd remembered an idea a friend of mine had about building a simple Christmas tree ornament with something like this. Something that blinks "Happy Holidays" or some such in Morse code. Not only would it be an opportunity to program something&lt;i&gt;&amp;nbsp;other&lt;/i&gt;&amp;nbsp;than an Arduino, but also an excuse to maybe silk screen and etch a circuit board. You know, something that looks like a tree? Or a radio tower?&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;A (very) quick search on Google revealed a simple &lt;a href="http://morsecode.scphillips.com/jtranslator.html"&gt;Java Morse code translator&lt;/a&gt;. A little reading after that revealed International Morse code would probably best with a Farnsworth speed of 20 words per minute. My timings are probably off by more than a bit on this as I was using a watch and some guesswork. But here's code that'd get the LED to blink "Happy Halloween" in Morse code:&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;pre style="border: 1px inset; ext-align: left; font-family: Courier New, monospace; height: 150px; margin: 0px; overflow: auto; padding: 6px; width: 100%;"&gt;/*&lt;br /&gt; * Morse Test 1&lt;br /&gt; * Blinks an LED in Morse code.&lt;br /&gt; */&lt;br /&gt;&lt;br /&gt;void setup() &lt;br /&gt;{&lt;br /&gt;  // initialize the digital pin as an output&lt;br /&gt;  pinMode(0, OUTPUT);     &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void loop() &lt;br /&gt;{&lt;br /&gt;  dit();  // H&lt;br /&gt;  dit();&lt;br /&gt;  dit();&lt;br /&gt;  dit();&lt;br /&gt; &lt;br /&gt;  dit();  // A&lt;br /&gt;  dah();&lt;br /&gt; &lt;br /&gt;  dit();  // P&lt;br /&gt;  dah();&lt;br /&gt;  dah();&lt;br /&gt;  dit();&lt;br /&gt; &lt;br /&gt;  dit();  // P&lt;br /&gt;  dah();&lt;br /&gt;  dah();&lt;br /&gt;  dit();&lt;br /&gt; &lt;br /&gt;  dah();  // Y&lt;br /&gt;  dit();&lt;br /&gt;  dah();&lt;br /&gt;  dah();&lt;br /&gt; &lt;br /&gt;  space();&lt;br /&gt;  space();&lt;br /&gt;  &lt;br /&gt;  dit();  // H&lt;br /&gt;  dit();&lt;br /&gt;  dit();&lt;br /&gt;  dit();&lt;br /&gt; &lt;br /&gt;  dit();  // A&lt;br /&gt;  dah();&lt;br /&gt; &lt;br /&gt;  dit();  // L&lt;br /&gt;  dah();&lt;br /&gt;  dit();&lt;br /&gt;  dit();&lt;br /&gt; &lt;br /&gt;  dit();  // L&lt;br /&gt;  dah();&lt;br /&gt;  dit();&lt;br /&gt;  dit();&lt;br /&gt; &lt;br /&gt;  dah();  // O&lt;br /&gt;  dah();&lt;br /&gt;  dah();&lt;br /&gt; &lt;br /&gt;  dit();  // W&lt;br /&gt;  dah();&lt;br /&gt;  dah();&lt;br /&gt; &lt;br /&gt;  dit();  // E&lt;br /&gt;  &lt;br /&gt;  dit();  // E&lt;br /&gt;  &lt;br /&gt;  dah();  // N&lt;br /&gt;  dit();&lt;br /&gt;&lt;br /&gt;  space();&lt;br /&gt;  space();&lt;br /&gt;  space();&lt;br /&gt;  space();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void dah()&lt;br /&gt;{&lt;br /&gt;  digitalWrite(0, HIGH);&lt;br /&gt;  delay(375);&lt;br /&gt;  digitalWrite(0, LOW);&lt;br /&gt;  delay(125);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void dit()&lt;br /&gt;{&lt;br /&gt;  digitalWrite(0, HIGH);&lt;br /&gt;  delay(125);&lt;br /&gt;  digitalWrite(0, LOW);&lt;br /&gt;  delay(125);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void space()&lt;br /&gt;{&lt;br /&gt;  delay(500);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;code goes="" here=""&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code goes="" here=""&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;And here's a video of that in case: a) anyone's watching, and b) they care to attempt to translate what I coded.&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code goes="" here=""&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;object width="320" height="266" class="BLOG_video_class" id="BLOG_video-336b40594bb6dc15" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"&gt;&lt;param name="movie" value="http://www.youtube.com/get_player"&gt;&lt;param name="bgcolor" value="#FFFFFF"&gt;&lt;param name="allowfullscreen" value="true"&gt;&lt;param name="flashvars" value="flvurl=http://v5.nonxt7.googlevideo.com/videoplayback?id%3D336b40594bb6dc15%26itag%3D5%26app%3Dblogger%26ip%3D0.0.0.0%26ipbits%3D0%26expire%3D1332301254%26sparams%3Did,itag,ip,ipbits,expire%26signature%3D58DAAF824144FA5B9E478C2D32718BE473565B9B.1B75EA8119A3A61FCDE57F15A818285431A5587E%26key%3Dck1&amp;amp;iurl=http://video.google.com/ThumbnailServer2?app%3Dblogger%26contentid%3D336b40594bb6dc15%26offsetms%3D5000%26itag%3Dw160%26sigh%3DZ8CJ7wt2nnsXI6WCzJ8OPApd1RM&amp;amp;autoplay=0&amp;amp;ps=blogger"&gt;&lt;embed src="http://www.youtube.com/get_player" type="application/x-shockwave-flash"width="320" height="266" bgcolor="#FFFFFF"flashvars="flvurl=http://v5.nonxt7.googlevideo.com/videoplayback?id%3D336b40594bb6dc15%26itag%3D5%26app%3Dblogger%26ip%3D0.0.0.0%26ipbits%3D0%26expire%3D1332301254%26sparams%3Did,itag,ip,ipbits,expire%26signature%3D58DAAF824144FA5B9E478C2D32718BE473565B9B.1B75EA8119A3A61FCDE57F15A818285431A5587E%26key%3Dck1&amp;iurl=http://video.google.com/ThumbnailServer2?app%3Dblogger%26contentid%3D336b40594bb6dc15%26offsetms%3D5000%26itag%3Dw160%26sigh%3DZ8CJ7wt2nnsXI6WCzJ8OPApd1RM&amp;autoplay=0&amp;ps=blogger"allowFullScreen="true" /&gt;&lt;/object&gt;&lt;/div&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;code goes="" here=""&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;Here's another video with another message which I'll leave as a mystery for someone to figure out. The message actually plays twice since as I recorded it I didn't catch the first message end separation (about 2 seconds) and turn off the camera in time. So I just let it run through the message again as it repeated. Might have been easier to just put the message in the setup method instead of the loop.&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code goes="" here=""&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;object width="320" height="266" class="BLOG_video_class" id="BLOG_video-da6e33f2ce6bd0ac" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"&gt;&lt;param name="movie" value="http://www.youtube.com/get_player"&gt;&lt;param name="bgcolor" value="#FFFFFF"&gt;&lt;param name="allowfullscreen" value="true"&gt;&lt;param name="flashvars" value="flvurl=http://v23.nonxt7.googlevideo.com/videoplayback?id%3Dda6e33f2ce6bd0ac%26itag%3D5%26app%3Dblogger%26ip%3D0.0.0.0%26ipbits%3D0%26expire%3D1332301254%26sparams%3Did,itag,ip,ipbits,expire%26signature%3D607C55792BA4994062B6CFE01F00EC5582348AAF.1FCF2CED56844E1E2FBF9E7483FB7F0D324B1F7E%26key%3Dck1&amp;amp;iurl=http://video.google.com/ThumbnailServer2?app%3Dblogger%26contentid%3Dda6e33f2ce6bd0ac%26offsetms%3D5000%26itag%3Dw160%26sigh%3Dl7mAI0Znqv0EV4fqVUwdCKvN-p8&amp;amp;autoplay=0&amp;amp;ps=blogger"&gt;&lt;embed src="http://www.youtube.com/get_player" type="application/x-shockwave-flash"width="320" height="266" bgcolor="#FFFFFF"flashvars="flvurl=http://v23.nonxt7.googlevideo.com/videoplayback?id%3Dda6e33f2ce6bd0ac%26itag%3D5%26app%3Dblogger%26ip%3D0.0.0.0%26ipbits%3D0%26expire%3D1332301254%26sparams%3Did,itag,ip,ipbits,expire%26signature%3D607C55792BA4994062B6CFE01F00EC5582348AAF.1FCF2CED56844E1E2FBF9E7483FB7F0D324B1F7E%26key%3Dck1&amp;iurl=http://video.google.com/ThumbnailServer2?app%3Dblogger%26contentid%3Dda6e33f2ce6bd0ac%26offsetms%3D5000%26itag%3Dw160%26sigh%3Dl7mAI0Znqv0EV4fqVUwdCKvN-p8&amp;autoplay=0&amp;ps=blogger"allowFullScreen="true" /&gt;&lt;/object&gt;&lt;/div&gt;&lt;code goes="" here=""&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code goes="" here=""&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;another goes="" here="" video=""&gt;&lt;/another&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code goes="" here=""&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;I should also point out the reason I like this so much is because I can use the Arduino IDE to do all the work. No coding in C or using programmers or command line code. It is much easier. I'm hoping (have not checked) that I can program an Attiny 2313 this way as well. I have also seen some articles outlining how to build a shield to handle this, though I'd probably create one for the 45/85 and another for the 2313.&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code goes="" here=""&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code goes="" here=""&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;Now that I've got this much figured out I may take this a step further &amp;amp; see if I can etch a circuit board for this. It'd also be cool to include some voltage handling to keep the power to something reliable and then get voltage from a light string directly. Kind of like ornaments you can get from Hallmark or wherever that plug right into the string &amp;amp; are lit. Might be cool.&amp;nbsp;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code goes="" here=""&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code goes="" here=""&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;Though if I am smart I should probably also include a switch that either turns the LED off or leaves it on all the time as the intermittent blinking might get on people's nerves after a while...&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code goes="" here=""&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/code&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8077223744586062132-6094313102555915609?l=winkmake.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winkmake.blogspot.com/feeds/6094313102555915609/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://winkmake.blogspot.com/2011/10/atiny85.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8077223744586062132/posts/default/6094313102555915609'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8077223744586062132/posts/default/6094313102555915609'/><link rel='alternate' type='text/html' href='http://winkmake.blogspot.com/2011/10/atiny85.html' title='Atiny85'/><author><name>Jwink</name><uri>http://www.blogger.com/profile/07356738572886578752</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://1.bp.blogspot.com/_LHP9sz9ANuQ/SWrQ95K1ecI/AAAAAAAAADw/Y3VUIKi1xy0/S220/DSCF4218_face.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/-BA8Zn2nZRTU/Tpuc-QI1BNI/AAAAAAAAAVU/zWrUA5lZgTY/s72-c/DSCF4262.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8077223744586062132.post-2785187947545225991</id><published>2010-12-19T12:04:00.000-08:00</published><updated>2010-12-19T12:48:08.907-08:00</updated><title type='text'>Persistence of Vision (PoV)</title><content type='html'>&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_LHP9sz9ANuQ/TQ5qJCkp7II/AAAAAAAAASM/85rKouMFjIM/s1600/PoV_Hello2.jpg"&gt;&lt;img style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;width: 200px; height: 118px;" src="http://2.bp.blogspot.com/_LHP9sz9ANuQ/TQ5qJCkp7II/AAAAAAAAASM/85rKouMFjIM/s200/PoV_Hello2.jpg" border="0" alt="" id="BLOGGER_PHOTO_ID_5552492094136380546" /&gt;&lt;/a&gt;Because it was quick and because I wasn't getting much done on other projects, I decided to look into &lt;a href="http://en.wikipedia.org/wiki/Persistence_of_vision"&gt;Persistence of Vision (PoV)&lt;/a&gt;. &lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;PoV was fairly simple to set up with the &lt;a href="http://shop.moderndevice.com/products/rbbb-kit"&gt;RBBB&lt;/a&gt;. I put the &lt;a href="http://shop.moderndevice.com/products/rbbb-kit"&gt;RBBB&lt;/a&gt; in a breadboard, ran a patch to the ground rail and added in five blue LEDs. I started with a sketch of my own that sort of worked, but not well.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;img src="http://1.bp.blogspot.com/_LHP9sz9ANuQ/TQ5tYPh8ePI/AAAAAAAAAS8/sH9K6U7vkaI/s200/PoV_WOW.jpg" style="float:right; margin:0 0 10px 10px;cursor:pointer; cursor:hand;width: 200px; height: 82px;" border="0" alt="" id="BLOGGER_PHOTO_ID_5552495653847595250" /&gt;&lt;/div&gt;&lt;div&gt;So I figured I'd have more luck looking on the &lt;a href="http://www.arduino.cc/playground/"&gt;Arduino playground&lt;/a&gt;. There I clicked on &lt;a href="http://www.arduino.cc/playground/Main/InterfacingWithHardware"&gt;Interfacing with Hardware&lt;/a&gt; and searched on PoV. There I found a link to an &lt;a href="http://i.document.m05.de/?p=127"&gt;art&lt;/a&gt;&lt;a href="http://i.document.m05.de/?p=127"&gt;icle&lt;/a&gt; written in German by someone named Michael Zoellner. I didn't understand the German but the sketch that was linked had comments in English. I made some tweaks to the code to allow for adjustments and ran it.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;img src="http://4.bp.blogspot.com/_LHP9sz9ANuQ/TQ5q7-r0szI/AAAAAAAAASc/uovgFSsfTZY/s200/PoV_Setup.jpg" style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;width: 200px; height: 168px;" border="0" alt="" id="BLOGGER_PHOTO_ID_5552492969266033458" /&gt;&lt;div&gt;It worked fairly well so I updated the setup so I didn't have to run it off of the USB cable &amp;amp; added battery power. This made it easier to hold it in my hand and wave it in front of a camera. I set up a camera on a tripod, lowered the ISO to 100 and turned down the lights. The camera is only a small point and shoot, so it didn't have much for time exposure settings. It did have a "long exposure" night setting, which I assume sets the F stop lower.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I used the 2 second timer and then just started waving my PoV setup in front of the camera with one hand furiously. This generally didn't catch anything or the letters were reversed. Some of the shots came out okay though.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;img src="http://3.bp.blogspot.com/_LHP9sz9ANuQ/TQ5sH7v_7VI/AAAAAAAAASk/kfhCrRuqTNI/s200/PoV_HelloWorld.jpg" style="float:right; margin:0 0 10px 10px;cursor:pointer; cursor:hand;width: 200px; height: 110px;" border="0" alt="" id="BLOGGER_PHOTO_ID_5552494274148298066" /&gt;&lt;/div&gt;&lt;div&gt;I did have to try the basic "Hello World", but couldn't get a shot much better than this. There's probably a lot of work that could be done to this set up with either some tweaks to the timing or to flip the letters when waved one way or the other. To do that I'd probably need to add an accelerometer to determine which way the swing is moving. At this stage, more work than it's worth. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;img src="http://1.bp.blogspot.com/_LHP9sz9ANuQ/TQ5tCKz0onI/AAAAAAAAAS0/SeKgrC7z0OY/s200/PoV_Alphabet.jpg" style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;width: 200px; height: 102px;" border="0" alt="" id="BLOGGER_PHOTO_ID_5552495274623279730" /&gt;&lt;div&gt;Here's another shot with me attempting to show the entire alphabet. Some of the letters - like the W - aren't well formed. Another thing that might help the legibility a bit would be to have more than 3 vertical lines.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;As usual, here is the source code. I've left the header comments mostly as they were to give credit to the original writer, Michael Zoellner, but I've added in a few more comments with "JTW" to indicate some changes of my own.&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;pre style="margin: 0px; padding: 6px; border: 1px inset; width: 100%; height: 150px; text-align: left; font-family: Courier New, monospace; overflow: auto"&gt;&lt;br /&gt;/*&lt;br /&gt;¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡&lt;br /&gt;persistence of vision typography with arduino&lt;br /&gt;michael zoellner - march 2006&lt;br /&gt;http://i.document.m05.de&lt;br /&gt;&lt;br /&gt;connect anodes (+) of 5 leds to digital ports of the arduino board&lt;br /&gt;and put 20-50 ohm resistors from the cathode (-) to ground.&lt;br /&gt;&lt;br /&gt;the letters are lookup tables consisting arrays width the dot status in y rows.&lt;br /&gt;¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;// JTW: pins running LEDs - added this as an array so I could change pins or positions&lt;br /&gt;// int pins[] = { 2, 3, 4, 5, 6 };&lt;br /&gt;int pins[] = { 6, 5, 4, 3, 2 };&lt;br /&gt;// JTW: inverted pins so I could hold it upside down &lt;br /&gt;&lt;br /&gt;// defining the alphabet&lt;br /&gt;int _[] = {0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0};&lt;br /&gt;int A[] = {0,1,1,1,1, 1,0,1,0,0, 0,1,1,1,1};&lt;br /&gt;int B[] = {1,1,1,1,1, 1,0,1,0,1, 0,1,0,1,0};&lt;br /&gt;int C[] = {0,1,1,1,0, 1,0,0,0,1, 1,0,0,0,1};&lt;br /&gt;int D[] = {1,1,1,1,1, 1,0,0,0,1, 0,1,1,1,0};&lt;br /&gt;int E[] = {1,1,1,1,1, 1,0,1,0,1, 1,0,1,0,1};&lt;br /&gt;int F[] = {1,1,1,1,1, 1,0,1,0,0, 1,0,1,0,0};&lt;br /&gt;int G[] = {0,1,1,1,0, 1,0,1,0,1, 0,0,1,1,0};&lt;br /&gt;int H[] = {1,1,1,1,1, 0,0,1,0,0, 1,1,1,1,1};&lt;br /&gt;int I[] = {0,0,0,0,1, 1,0,1,1,1, 0,0,0,0,1};&lt;br /&gt;int J[] = {1,0,0,0,0, 1,0,0,0,1, 1,1,1,1,1};&lt;br /&gt;int K[] = {1,1,1,1,1, 0,0,1,0,0, 0,1,0,1,1};&lt;br /&gt;int L[] = {1,1,1,1,1, 0,0,0,0,1, 0,0,0,0,1};&lt;br /&gt;int M[] = {1,1,1,1,1, 0,1,1,0,0, 0,1,1,1,1};&lt;br /&gt;int N[] = {1,1,1,1,1, 1,0,0,0,0, 0,1,1,1,1};&lt;br /&gt;int O[] = {0,1,1,1,0, 1,0,0,0,1, 0,1,1,1,0};&lt;br /&gt;int P[] = {1,1,1,1,1, 1,0,1,0,0, 0,1,0,0,0};&lt;br /&gt;int Q[] = {0,1,1,1,1, 1,0,0,1,1, 0,1,1,1,1};&lt;br /&gt;int R[] = {1,1,1,1,1, 1,0,1,0,0, 0,1,0,1,1};&lt;br /&gt;int S[] = {0,1,0,0,1, 1,0,1,0,1, 1,0,0,1,0};&lt;br /&gt;int T[] = {1,0,0,0,0, 1,1,1,1,1, 1,0,0,0,0};&lt;br /&gt;int U[] = {1,1,1,1,1, 0,0,0,0,1, 1,1,1,1,1};&lt;br /&gt;int V[] = {1,1,1,1,0, 0,0,0,0,1, 1,1,1,1,0};&lt;br /&gt;int W[] = {1,1,1,1,0, 0,0,1,1,0, 1,1,1,1,0};&lt;br /&gt;int X[] = {1,1,0,1,1, 0,0,1,0,0, 1,1,0,1,1};&lt;br /&gt;int Y[] = {1,1,0,0,0, 0,0,1,0,0, 1,1,1,1,1};&lt;br /&gt;int Z[] = {1,0,0,1,1, 1,0,1,0,1, 1,1,0,0,1};&lt;br /&gt;&lt;br /&gt;// defining the time dots appear (ms)&lt;br /&gt;int dotTime = 3;  &lt;br /&gt;&lt;br /&gt;// defining the space between the letters (ms)&lt;br /&gt;int letterSpace = 6;&lt;br /&gt;&lt;br /&gt;/*&lt;br /&gt; * Run once method - set up pins&lt;br /&gt; */&lt;br /&gt;void setup()&lt;br /&gt;{&lt;br /&gt;  // setting the ports of the leds to OUTPUT&lt;br /&gt;  for (int y = 0; y &lt; 5; y++) { pinMode(pins[y], OUTPUT); }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/*&lt;br /&gt; * Continual running method&lt;br /&gt; */&lt;br /&gt;void loop()&lt;br /&gt;{&lt;br /&gt;  // printing some letters&lt;br /&gt;  printLetter(H);&lt;br /&gt;  printLetter(E);&lt;br /&gt;  printLetter(L);&lt;br /&gt;  printLetter(L);&lt;br /&gt;  printLetter(O);&lt;br /&gt;  printLetter(_);&lt;br /&gt;  printLetter(W);&lt;br /&gt;  printLetter(O);&lt;br /&gt;  printLetter(R);&lt;br /&gt;  printLetter(L);&lt;br /&gt;  printLetter(D);&lt;br /&gt;  printLetter(_);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/*&lt;br /&gt; * Show a passed in letter array &lt;br /&gt; * JTW: altered slightly to use pin array&lt;br /&gt; */&lt;br /&gt;void printLetter(int letter[])&lt;br /&gt;{ &lt;br /&gt;  // printing the first y row of the letter&lt;br /&gt;  for (int y = 0; y &lt; 5; y++) { digitalWrite(pins[y], letter[y]); }&lt;br /&gt;  delay(dotTime);&lt;br /&gt;  &lt;br /&gt;  // printing the second y row of the letter&lt;br /&gt;  for (int y = 0; y &lt; 5; y++) { digitalWrite(pins[y], letter[y + 5]); }&lt;br /&gt;  delay(dotTime);&lt;br /&gt;  &lt;br /&gt;  // printing the third y row of the letter&lt;br /&gt;  for (int y = 0; y &lt; 5; y++) { digitalWrite(pins[y], letter[y + 10]); }&lt;br /&gt;  delay(dotTime);&lt;br /&gt;  &lt;br /&gt;  // printing the sspace between the letters&lt;br /&gt;  for (int y = 0; y &lt; 5; y++) { digitalWrite(pins[y], 0); }&lt;br /&gt;  delay(letterSpace);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8077223744586062132-2785187947545225991?l=winkmake.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winkmake.blogspot.com/feeds/2785187947545225991/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://winkmake.blogspot.com/2010/12/persistence-of-vision-pov.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8077223744586062132/posts/default/2785187947545225991'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8077223744586062132/posts/default/2785187947545225991'/><link rel='alternate' type='text/html' href='http://winkmake.blogspot.com/2010/12/persistence-of-vision-pov.html' title='Persistence of Vision (PoV)'/><author><name>Jwink</name><uri>http://www.blogger.com/profile/07356738572886578752</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://1.bp.blogspot.com/_LHP9sz9ANuQ/SWrQ95K1ecI/AAAAAAAAADw/Y3VUIKi1xy0/S220/DSCF4218_face.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_LHP9sz9ANuQ/TQ5qJCkp7II/AAAAAAAAASM/85rKouMFjIM/s72-c/PoV_Hello2.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8077223744586062132.post-5603958934134461283</id><published>2010-09-21T20:46:00.000-07:00</published><updated>2010-09-29T13:15:30.644-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='FTDI'/><category scheme='http://www.blogger.com/atom/ns#' term='Arduino'/><category scheme='http://www.blogger.com/atom/ns#' term='RBB'/><title type='text'>New 'duinos</title><content type='html'>I haven't posted in a while. I have &lt;i&gt;still&lt;/i&gt; been busy tinkering, but for one reason or another haven't gotten around to posting. I have made some progress on my design for a color fading juggling ball, and have started some other projects, but I think I will save them for another post. Instead, I'll say a word or two about some new purchases.&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;When I built the &lt;a href="http://winkmake.blogspot.com/2010/07/web-cam-pan.html"&gt;web cam pan&lt;/a&gt; this summer, I sent with it my one and only Arduino. It was an older one with an Atmega 168 and 16 k of memory so I was looking to upgrade. Prior to sending it off, I first bought an &lt;a href="http://www.sparkfun.com/commerce/product_info.php?products_id=9218"&gt;Arduino Pro Mini 5.5v / 328&lt;/a&gt; from &lt;a href="http://www.sparkfun.com/"&gt;Sparkfun&lt;/a&gt;. I also had to get an &lt;a href="http://www.sparkfun.com/commerce/product_info.php?products_id=9115"&gt;FTDI breakout board&lt;/a&gt; for it as it doesn't have on-board USB communications.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Man, that thing is &lt;i&gt;tiny!&lt;/i&gt; It's about the size two postage stamps! Pictured here is what it looks like after putting pins all over it so I can snap it into a breadboard. &lt;/div&gt;&lt;div&gt;&lt;img src="http://3.bp.blogspot.com/_LHP9sz9ANuQ/TJmDHP5nhJI/AAAAAAAAARk/hor-XBN3e7c/s200/ProMini5v_35per.jpg" style="float:right; margin:0 0 10px 10px;cursor:pointer; cursor:hand;width: 200px; height: 112px;" border="0" alt="" id="BLOGGER_PHOTO_ID_5519586978869773458" /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I did learn one thing with it - solder carefully. The picture you see here is actually my &lt;i&gt;second&lt;/i&gt; Pro Mini. With the first I had put straight male headers facing up - and then later decided I didn't like them, so I tried to remove them with an iron and de-solder gun. I got the right angle header on only to learn it wouldn't communicate any more. It still ran the last script I had on it, but that's not a lot of good. So I ordered another and hung my head in shame.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;img src="http://3.bp.blogspot.com/_LHP9sz9ANuQ/TJmC30Z49gI/AAAAAAAAARc/K18Xeq0zTC4/s200/Duemilanova328_25per.jpg" style="float:left; margin:0 10px 10px 10px;cursor:pointer; cursor:hand;width: 200px; height: 145px;" border="0" alt="" id="BLOGGER_PHOTO_ID_5519586713790903810" /&gt;&lt;/div&gt;&lt;div&gt;Not long after that I decided I needed a &lt;a href="http://www.sparkfun.com/commerce/product_info.php?products_id=9282"&gt;screw-shield&lt;/a&gt; for my project, so I used the opportunity to get another &lt;a href="http://www.sparkfun.com/commerce/product_info.php?products_id=666"&gt;Duemilanova&lt;/a&gt;. It's pretty much the same deal as the other but with twice the processor speed and twice the memory.&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;It also has a nifty sticker up in the corner indicating Italy or some such. &lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Once I was done with the web cam pan and had sent it up north I started looking into next projects. The Pro Mini I decided would be dedicated to my lighted juggling ball project. The Duemilanova would have to run the &lt;a href="http://www.adafruit.com/index.php?main_page=product_info&amp;amp;cPath=17_21&amp;amp;products_id=81"&gt;motor-shield&lt;/a&gt; for my plotter project. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;That left no spares for just messing around, so I ordered a "&lt;a href="http://www.moderndevice.com/products/rbbb-kit"&gt;Really Bare Bones Board&lt;/a&gt;" from &lt;a href="http://www.moderndevice.com/"&gt;Modern Device&lt;/a&gt;. At $12.50, this is has to be the cheapest Arduino out there. I ordered the kit (of course) so I could assemble it myself. Like the Pro Mini, it doesn't have an FTDI/USB chip on it, so you need a converter - which I already had purchased for the Pro-mini and could use with this one. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I like this board. It plugs directly into a bread board and is actually slightly more narrow than the Pro Mini, freeing up one more row of slots on the board. It is, of course, also an Atmega 328, so its faster and has more memory. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;It is, however, very long. If I were to use this in a juggling ball, the ball would probably end up rather big. You &lt;i&gt;can&lt;/i&gt; chop it down to almost the length of the chip itself as long as you are willing to provide very clean power to the thing.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;A big juggling ball is not impossible for a good juggler, but I do, for some reason, have a desire for a fairly compact ball. We'll see what I end up with. The RBBB is definitely in the running for the main unit anyway because of it's price. If I want to make 3 of these - and possibly more later if this works out - then I'll want the cheapest components I can get. And that means RBBB. If I order 5 they're only $10.50! &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Though I do fear this will mean I have to learn to solder an accelerometer "surface mount" chip directly. Sparkfun has &lt;a href="http://www.sparkfun.com/commerce/product_info.php?products_id=9605"&gt;one&lt;/a&gt; for $7.95, but a quick spin through &lt;a href="http://www.digikey.com/"&gt;Digikey&lt;/a&gt; reveals some cheaper options.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I do have a photo of this one, really. I didn't have at the time of writing this, though. I also have a video of a little test jig I worked up, but have that either. I'll add them both at a later time.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8077223744586062132-5603958934134461283?l=winkmake.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winkmake.blogspot.com/feeds/5603958934134461283/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://winkmake.blogspot.com/2010/09/new-duinos.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8077223744586062132/posts/default/5603958934134461283'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8077223744586062132/posts/default/5603958934134461283'/><link rel='alternate' type='text/html' href='http://winkmake.blogspot.com/2010/09/new-duinos.html' title='New &apos;duinos'/><author><name>Jwink</name><uri>http://www.blogger.com/profile/07356738572886578752</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://1.bp.blogspot.com/_LHP9sz9ANuQ/SWrQ95K1ecI/AAAAAAAAADw/Y3VUIKi1xy0/S220/DSCF4218_face.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_LHP9sz9ANuQ/TJmDHP5nhJI/AAAAAAAAARk/hor-XBN3e7c/s72-c/ProMini5v_35per.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8077223744586062132.post-1410581247557037666</id><published>2010-07-28T23:00:00.001-07:00</published><updated>2010-07-29T08:36:29.835-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='plank'/><category scheme='http://www.blogger.com/atom/ns#' term='.NET'/><category scheme='http://www.blogger.com/atom/ns#' term='Web Cam'/><category scheme='http://www.blogger.com/atom/ns#' term='Power Switch Tail'/><category scheme='http://www.blogger.com/atom/ns#' term='PC'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='Servo'/><category scheme='http://www.blogger.com/atom/ns#' term='Arduino'/><title type='text'>Web Cam Pan</title><content type='html'>&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_LHP9sz9ANuQ/TFEZF7TgCiI/AAAAAAAAAP8/r2BCS0T9wZo/s1600/WCP_Intro.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5499204209605610018" style="FLOAT: left; MARGIN: 0px 10px 10px 0px; WIDTH: 200px; CURSOR: hand; HEIGHT: 148px" alt="" src="http://3.bp.blogspot.com/_LHP9sz9ANuQ/TFEZF7TgCiI/AAAAAAAAAP8/r2BCS0T9wZo/s200/WCP_Intro.jpg" border="0" /&gt;&lt;/a&gt;Here is a photo of a project I started a while back. I took an old Logitech web camera we had sitting around, removed it from it's case and sandwiched it between two small sheets of Acryllic. My reasoning here is it would be easier to attach that to a servo than the weird sphere casing it was originally in. Really, I think it just looks cooler that way.&lt;br /&gt;&lt;br /&gt;The servo is bolted to - well through - a plank I had in the garage. I think it's left over from building the deck. A plank, yes. Probably green-treat or some such. If I could've figured out a way to get duct tap on it, I probably would have.&lt;br /&gt;&lt;br /&gt;Anyway, behind the web camera is an Arduino Duemilanova (168) - the original/first one I got. It's connected with some simple wood screws through the board.&lt;br /&gt;&lt;br /&gt;Underneath all this, on the other side of the plank is a &lt;a href="http://powerswitchtail.com/default.aspx"&gt;Power Switch Tail&lt;/a&gt;. &lt;img id="BLOGGER_PHOTO_ID_5499205707706629698" style="FLOAT: right; MARGIN: 0px 0px 10px 10px; WIDTH: 200px; CURSOR: hand; HEIGHT: 82px" alt="" src="http://3.bp.blogspot.com/_LHP9sz9ANuQ/TFEadIKnfkI/AAAAAAAAAQE/vuLK9O6e_G8/s200/PowerSwitchTail.jpg" border="0" /&gt;&lt;br /&gt;This nifty little device is a bit like a really short extension cord with a switch. Regular 120 volt house current goes in one end and comes out the other. Except when it doesn't. Wired to the tail are two wires - 5 volts and ground to the Arduino. Inside the tail is a relay. When 5 volts go through the two wires, 120 volts can pass through the main part of the tail. When 5 volts aren't going hrough the tail, no 120 volts.&lt;br /&gt;&lt;br /&gt;The Arduino is running a simple sketch. It receives commands from a PC to do one of two things: turn on and off the tail, and move the servo. On the PC is a .NET/C# WinForm app that does a number of things:&lt;br /&gt;&lt;br /&gt;&lt;img id="BLOGGER_PHOTO_ID_5499207324143439042" style="FLOAT: left; MARGIN: 0px 10px 10px 0px; WIDTH: 200px; CURSOR: hand; HEIGHT: 152px" alt="" src="http://3.bp.blogspot.com/_LHP9sz9ANuQ/TFEb7N3LzMI/AAAAAAAAAQU/NcnXDhwBxAU/s200/AppAtCabin.jpg" border="0" /&gt;- Turns on and off a preview of what the web camera is looking at&lt;br /&gt;- Via the Arduino, turns on and off the tail&lt;br /&gt;- Also via the Arduino, moves the servo (and also the web ca&lt;br /&gt;mera) left and right&lt;br /&gt;- Takes snapshots of whatever the web camera is looking at&lt;br /&gt;&lt;br /&gt;What's the point of all this you ask? Well, at my parent's cabin in northern Wisconsin is an internet connection. On that connection is a router instructed to route remote desktop requests to a PC running Windows XP pro. With this setup connected - and I connect to that PC via Remote Desktop - I can turn on a light an look around.&lt;br /&gt;&lt;br /&gt;What do I want to look at? Well, in this case, the utility room. This is where the water heater, furnace, floor drain, and other odds and ends are. We wanted to be able to look in this room where things could break down&lt;img id="BLOGGER_PHOTO_ID_5499208995528755122" style="FLOAT: right; MARGIN: 0px 0px 10px 10px; WIDTH: 182px; CURSOR: hand; HEIGHT: 200px" alt="" src="http://1.bp.blogspot.com/_LHP9sz9ANuQ/TFEdcgQfx7I/AAAAAAAAAQc/IEgsMqayKEk/s200/AsInstalled.jpg" border="0" /&gt; - freeze in the winter, or flood, or whatever,&lt;br /&gt;when no one is physically there. Now we can.&lt;br /&gt;&lt;br /&gt;Here is a photo of the setup as installed in the room. We drilled a hole through the side of the board and then screwed it into one of the bare studs in the room. It is just leaning on the UPS and cords hanging from the bottom of it. The camera is deliberately pointed at the floor where flooding or water leakage is likely to occur.&lt;br /&gt;&lt;br /&gt;We had to hang it close to the PC so the Arduino and web camera could be connected directly to the PC. That spot, however, isn't the most ideal in the room. I think for version 2 I might consider a second Arduino communicating to the first via wireless (Xbee?) or some other form of communication.&lt;br /&gt;&lt;br /&gt;The downside of this setup is while it works great in the local network, it's fairly slow over the internet. The DSL at the cabin isn't the fastest, and previewing images through the remote desktop connection isn't the best.&lt;br /&gt;&lt;br /&gt;I am using Avicap32.dll through .NET and C#. This wasn't the most intuitive and easy to use methods, but it got the job done. I may update the code to have a "manual" mode that snaps a photo and posts it to the preview screen whenever something changes: light on/off, or panning.&lt;br /&gt;&lt;br /&gt;I will post code here eventually. I had installed the thing on July 4th and had just never gotten around to posting anything about it until now.&lt;br /&gt;&lt;br /&gt;One other thing I will mention: this has been done before. There are probably commercial products out there to do what I did for nearly as cheap. The reason I started doing this was, well, why I do any of this: because I wanted to see if it was possible.&lt;br /&gt;&lt;br /&gt;I did also want to see how cheaply I could do it. I tried to use parts I already had sunk money into long ago and weren't currently in use for anything else. The web cam is one of many I have gathering dust on my shelf. These days they are smaller than that and cheap, but using this one required no extra cost.&lt;br /&gt;&lt;br /&gt;The servo was an extra from an RC car kit my dad gave me for my birthday a while back. The kit came with two, one for controlling steering of the front wheels and the second for handling speed control. Except the kit also came with a control board that did electronic speed control, so the second servo was not needed. After this project was done, I did break down and buy another one just like it from a local hobby store. You never know when you'll need one, right?&lt;br /&gt;&lt;br /&gt;The Arduino wasn't gathering dust - it was my only one until I started this project. I had, however, been wanting an updated one with an Atmega 328 chip instead of the 168. So I got another full Duemilanova as well as a mini from Sparkfun.&lt;br /&gt;&lt;br /&gt;The &lt;a href="http://powerswitchtail.com/default.aspx"&gt;Power Switch Tail&lt;/a&gt; wasn't sitting around. I had to order it and it cost a bout $15 bucks. A bit more than I really wanted to spent, but I wanted something sealed and well tested. I could have built something - there are plenty of instructions on how to do so on the web - but when you're dealing with full house current, I really didn't want to mess around. I'd rather not burn down the cabin.&lt;br /&gt;&lt;br /&gt;The plank, well, I have stacks of wood left over from when we built the deck in, what, 2002? Expect more planks in future projects.&lt;br /&gt;&lt;br /&gt;The code I wrote myself. As usual. But with lots of help from many excellent people on the web.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8077223744586062132-1410581247557037666?l=winkmake.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winkmake.blogspot.com/feeds/1410581247557037666/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://winkmake.blogspot.com/2010/07/web-cam-pan.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8077223744586062132/posts/default/1410581247557037666'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8077223744586062132/posts/default/1410581247557037666'/><link rel='alternate' type='text/html' href='http://winkmake.blogspot.com/2010/07/web-cam-pan.html' title='Web Cam Pan'/><author><name>Jwink</name><uri>http://www.blogger.com/profile/07356738572886578752</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://1.bp.blogspot.com/_LHP9sz9ANuQ/SWrQ95K1ecI/AAAAAAAAADw/Y3VUIKi1xy0/S220/DSCF4218_face.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_LHP9sz9ANuQ/TFEZF7TgCiI/AAAAAAAAAP8/r2BCS0T9wZo/s72-c/WCP_Intro.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8077223744586062132.post-5419164422175632294</id><published>2010-04-25T20:09:00.000-07:00</published><updated>2010-04-25T21:32:51.280-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='g-code'/><category scheme='http://www.blogger.com/atom/ns#' term='Dremel'/><category scheme='http://www.blogger.com/atom/ns#' term='CNC'/><category scheme='http://www.blogger.com/atom/ns#' term='Stepper'/><category scheme='http://www.blogger.com/atom/ns#' term='Servo'/><category scheme='http://www.blogger.com/atom/ns#' term='Arduino'/><category scheme='http://www.blogger.com/atom/ns#' term='Motor Shield'/><title type='text'>Steppers and the Motor Shield</title><content type='html'>&lt;a href="http://www.ax-man.com/"&gt;Axman Surplus&lt;/a&gt; is awesome.&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I've been thinking of building a &lt;a href="http://en.wikipedia.org/wiki/CNC"&gt;CNC&lt;/a&gt;. There are a number of articles on the web that'll walk you through building a CNC, including this one on how to build a &lt;a href="http://www.instructables.com/id/Easy-to-Build-Desk-Top-3-Axis-CNC-Milling-Machine/"&gt;desktop CNC&lt;/a&gt;. That one, in particular, could use a tool I already have - a Dremel.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Anyway, a CNC is complicated. There's a whole language used for communicating with CNC's called &lt;a href="http://en.wikipedia.org/wiki/G-code"&gt;g-code&lt;/a&gt;, that is pretty much a complete mystery to me. Then there's taking 3-d models and converting them to g-code, and probably any number of details I don't have figured out. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;It'd be a bigger project than I've tackled so far. But like anything, I've got to start somewhere, so I figured I'd start with equipment I already have. In this case I'm referring to the &lt;a href="http://www.ladyada.net/make/mshield/"&gt;Motor Shield&lt;/a&gt; I got from &lt;a href="http://www.adafruit.com/"&gt;Adafruit&lt;/a&gt;. I built it a while back and then set it aside and never used it. So I figured this was a good time.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I'd already figured out how to &lt;a href="http://winkmake.blogspot.com/2009/02/servo-control.html"&gt;run a servo&lt;/a&gt; on the Arduino, but the Motor Shield has pins set aside to do this. It used to have a specific library too, but it looks like the folks at Arduino came up with their own. Anyway, using the example in Layada's &lt;a href="http://www.ladyada.net/make/mshield/"&gt;tutorial&lt;/a&gt; worked right away, no troubles.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The real power in a CNC are the &lt;a href="http://en.wikipedia.org/wiki/Stepper_motor"&gt;stepper motors&lt;/a&gt;. These are specialized motors that can spin in very small, descrete movements in either directions. Two steppers set opposite each over can control X and Y axis. A third stepper - or a servo - can control up an down. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I really don't understand how servo motors work, but I sort of don't need to. I hook it up and tell it where to go in code. With steppers, though - it's sort of different. Different steppers hook up different ways. There are unipolar and bipolar, 5-lead, 6-lead, and 8-lead. How you hook it up - even to something like the Motor Shield, which goes out of it's way to make it easier on you - makes a difference.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;So needed to get some stepper motors. I could have ordered some online, but that'd mean waiting a bit and possibly paying more than I really want. Instead, I called the good folks at Axman surplus and asked them whether they sold stepper motors. They said they did and had a selection. Beyond that they couldn't say anything about what kind of steppers they had. Not surprising if you've ever been to Axman. It's a unique experience.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;My friend Chad was up from Rochester for the weekend so I dragged him and my son over to the Axman in St. Paul off of University Avenue. After 30 minutes or so of just wandering the aisles - a process the cannot be avoided in such a place - we made it to area where all the motors were. There I found quite a few stepper motors, including some very similar to what is &lt;a href="http://www.adafruit.com/index.php?main_page=product_info&amp;amp;products_id=168"&gt;suggested&lt;/a&gt; on Adafruit's site: an Airpax C82290-M2. It's a 5 volt, 7.5 degree stepper motor - again, very similar to the examples. I bought 3.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The trick with these steppers is that they have 8 wires - more than the examples in the tutorial. The eight wires came in pairs: two red, two black, two yellow, and two grey. I tried first by tying together the pairs an hooking them up to the shield. Running the code didn't have the results I'd expected - the motor just shifted clock-wise and counter.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;So followed some links suggested by the tutorial and eventually ran into one that talked about how to reverse engineer the purpose of the wires. And this &lt;a href="http://www.piclist.com/techref/io/stepper/wires.htm"&gt;link &lt;/a&gt;is pretty much the whole reason I posted today. It helped me figure how that the two red and two gray wires can be joined and then the black and yellow's mixed. I hooked these up to the motor shield and ran the example code as was. And now that link is here in the cloud for the next stepper I can't figure out.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Eventually I hope to create a simple plotter with all this. Probably a fixed pen or pencil over a moving platform that'll hold a sheet of paper. I'm not sure whether this little steppers are powerful enough for that, but I'll find out soon enough.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;That's all I've got for now. No code since anything I used is available in the tutorial. More, hopefully, as I continue building something.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8077223744586062132-5419164422175632294?l=winkmake.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winkmake.blogspot.com/feeds/5419164422175632294/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://winkmake.blogspot.com/2010/04/steppers-and-motor-shield.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8077223744586062132/posts/default/5419164422175632294'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8077223744586062132/posts/default/5419164422175632294'/><link rel='alternate' type='text/html' href='http://winkmake.blogspot.com/2010/04/steppers-and-motor-shield.html' title='Steppers and the Motor Shield'/><author><name>Jwink</name><uri>http://www.blogger.com/profile/07356738572886578752</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://1.bp.blogspot.com/_LHP9sz9ANuQ/SWrQ95K1ecI/AAAAAAAAADw/Y3VUIKi1xy0/S220/DSCF4218_face.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8077223744586062132.post-6440214589292079898</id><published>2010-03-06T18:01:00.000-08:00</published><updated>2010-03-06T21:10:53.137-08:00</updated><title type='text'>Still on XYZ and RGB</title><content type='html'>It should come as no surprise that I am still somewhat obsessed with my accelerometer. I've stated earlier that I'd like to create a lighted juggling ball that changes color as it rotates. This &lt;i&gt;should&lt;/i&gt; be a simple task with an accelerometer - three axis, three colors, mix 'em and you're done, right? Maybe not so much.&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I won't rehash previous posts, but I will say I am really close. I should, however, explain my criteria:&lt;/div&gt;&lt;div&gt;&lt;ul&gt;&lt;li&gt;Rotation should change color of the light, obviously&lt;/li&gt;&lt;li&gt;At a minimum, there should be shifting between the 3 basic colors: red, green, blue&lt;/li&gt;&lt;li&gt;I'd prefer 6 colors total, with the other 3 being mixes: yellow (red/green), aqua (green/blue), and purple (blue/red)&lt;/li&gt;&lt;li&gt;I'd &lt;i&gt;like&lt;/i&gt; to get some nice fading as it switches between colors, but as I'll point out later, this is somewhat hard&lt;/li&gt;&lt;li&gt;The light intensity should never change - all on, and never off&lt;/li&gt;&lt;li&gt;I'd prefer it if there wasn't much white - all colors on - showing &lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_LHP9sz9ANuQ/S5MXf1-286I/AAAAAAAAAOs/qYOGsJA_fT0/s1600-h/DSCF8606_small.jpg"&gt;&lt;img style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;width: 320px; height: 261px;" src="http://3.bp.blogspot.com/_LHP9sz9ANuQ/S5MXf1-286I/AAAAAAAAAOs/qYOGsJA_fT0/s320/DSCF8606_small.jpg" border="0" alt="" id="BLOGGER_PHOTO_ID_5445722210255172514" /&gt;&lt;/a&gt;I already have code on the Arduino that'll produce 6 distinct colors. Based on the above criteria, I've succeeded.  I've wired up the prototyping shield, the accelerometer, an RBG LED, &lt;i&gt;and&lt;/i&gt; a seven segment display. The last is so I can display the digit of the color currently showing. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;That setup (shown left) is seriously prototype. It's nothing I'd really use in an actual juggling ball. It's too big, it only has one LED, I probably wouldn't include the 7-seg display - but it helped me understand what I was up against.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;It was a bit of a stretch to come up with the 6 basic colors out of 3 axis. Here's how I did it:&lt;/div&gt;&lt;div&gt;&lt;ul&gt;&lt;li&gt;The accelerometer produces values from 0 to 692 (roughly)&lt;/li&gt;&lt;li&gt;There are 3 values coming from the X, Y, and Z axis&lt;/li&gt;&lt;li&gt;To get 6 distinct numbers I split each axis down the middle and then checked which side of middle it was on&lt;/li&gt;&lt;li&gt;If the value was lower than the mid-point it was one number, if higher than the mid-point it was another number&lt;/li&gt;&lt;li&gt;Two colors were assigned to each axis, and as such only one color could show at a time, again if less than mid-point one color, higher, another color&lt;/li&gt;&lt;li&gt;For example, the X axis lower than 346 is red, higher than that its aqua&lt;/li&gt;&lt;li&gt;At any given time the position of the three axis indicates 3 numbers and colors at once - to pick only one, we take the highest of the three&lt;/li&gt;&lt;li&gt;The axis values are split in half so they are from 0 to 346 and altered so they always increase the more the accelerometer is leaned in a particular direction, i.e. from 0 to 346 is actually flipped so at the zero value we'd be returning 346 and vice versa as we approach middle. From 346 to 692 we just subtract 346.&lt;/li&gt;&lt;li&gt;These "half" values are shoved into an array and bubble sorted so we know which one is highest. The array is multidimensional and also contains the index we assigned to that number. When we know which value is highest, we also know which index is highest. &lt;/li&gt;&lt;li&gt;Since we know which color is assigned to that index, we show that color. &lt;/li&gt;&lt;/ul&gt;&lt;div&gt;The code in this situation might make more sense than that explanation. As usual you will find that code at the bottom of the post. Before that, though, I have a few more things to mention.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;One is another notion I introduced with this code: smoothing. The values that come streaming out of the accelerometer are... not consistent. The sort of jump all over the place. If you were to watch the values on the serial output you'd see something like this:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;373, 349, 536&lt;/div&gt;&lt;div&gt;372, 348, 532&lt;/div&gt;&lt;div&gt;371, 347, 548&lt;/div&gt;&lt;div&gt;378, 355, 554&lt;/div&gt;&lt;div&gt;372, 352, 539&lt;/div&gt;&lt;div&gt;365, 346, 531&lt;/div&gt;&lt;div&gt;371, 351, 542&lt;/div&gt;&lt;div&gt;371, 348, 541&lt;/div&gt;&lt;div&gt;371, 352, 544&lt;/div&gt;&lt;div&gt;374, 352, 544&lt;/div&gt;&lt;div&gt;And so on...&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The first value is X, the second Y, and the third Z. X and Y are roughly middle, i.e. there's little pulling them one way or another. Z is pointing down, so it's higher than the other two. At it's current setting the accelerometer is measuring 1.5 g's, so at rest the Z values is somewhere lower than it's max. I'd have to shake it a bit to see it hit 692.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I started trying to figure out how fast the Arduino could sample the output of the accelerometer and between running at 16 mhz and returning those values out of serial at 9600 baud I gave up. It's pretty fast - there's a lot of sampling going on each second. And as you can see above, there's a lot of variation going on in a really short period of time. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;That variation is not due to vibration. I'm not sure whether it's noise on the analog inputs (likely) or inaccuracy on the accelerometer (possible) or something else I don't know (also likely). Whatever the case, it's annoying and it causes the light of the LED to blink between colors when it's at a boundary between them. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_LHP9sz9ANuQ/S5MkJARiZ9I/AAAAAAAAAO0/POrmoVz3wv4/s1600-h/AccelTest2.jpg"&gt;&lt;img style="float:right; margin:0 0 10px 10px;cursor:pointer; cursor:hand;width: 300px; height: 320px;" src="http://4.bp.blogspot.com/_LHP9sz9ANuQ/S5MkJARiZ9I/AAAAAAAAAO0/POrmoVz3wv4/s320/AccelTest2.jpg" border="0" alt="" id="BLOGGER_PHOTO_ID_5445736111532042194" /&gt;&lt;/a&gt;So I figured out smoothing. What this is basically is shoving the values coming off the accelerometer into an array and then taking the average of a set of values (like 30) and using that value instead. It worked fairly well, though if I made the array too large it had some interesting effects. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I actually went back to some old .NET code I'd written in April of '09 (that post &lt;a href="http://winkmake.blogspot.com/2009/04/back-to-accelerometer.html"&gt;here&lt;/a&gt;) to test it. The app was designed to that just the X and Y and paint dots on a screen. Without smoothing the dots scatter and draw something that looks a bit like spray paint. With the smoothing it draws something closer to lines. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;It was actually kind of pretty and fun to play with. I updated the app to use the Z axis to determine color. I ended up spending a lot of time with the kids playing with it. If I ever get into wireless I may consider creating a hardware interface that's a bit more user friendly that my current rig. I'm not sure how practical it'd be as a drawing interface, but still - fun to play with.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;So I had smoothing. What I didn't have was fading between the 6 colors. I spent some time trying to figure this out on the Arduino, but this was frustrating at best. There's no debugger and using Serial.println has it's limits. So I took that job into .NET and wrote a simple Arduino sketch that'd just dump out to serial the values it fetches from the Accelerometer.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;What I came up with was what you see in this video: &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;object width="410" height="329"&gt;&lt;param name="movie" value="http://www.youtube.com/v/jm59n6nJvTQ&amp;amp;hl=en_US&amp;amp;fs=1&amp;amp;"&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;param name="allowscriptaccess" value="always"&gt;&lt;embed src="http://www.youtube.com/v/jm59n6nJvTQ&amp;amp;hl=en_US&amp;amp;fs=1&amp;amp;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="410" height="329"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;Before I move on I want to mention the software I used to get that video: &lt;a href="http://camstudio.org/"&gt;CamStudio&lt;/a&gt;. It's got a free version that does well getting the basic AVI I have above.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;The video starts out with me selecting read. From that point onward it's taking values in from the Arduino and doing the following:&lt;/div&gt;&lt;div&gt;&lt;ul&gt;&lt;li&gt;Showing them on the sliders that depict the full range of 0 to 692&lt;/li&gt;&lt;li&gt;Splitting the values in half and showing the top 3&lt;/li&gt;&lt;li&gt;Showing the dominant color on a visual representation of three axis split&lt;/li&gt;&lt;li&gt;Showing the RGB value it came up with, both in numbers and in color&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;The mixing is achieved by determining &lt;i&gt;how close&lt;/i&gt; the second and third picks are to the first. The first pick is always the dominant color, but if the second pick is within a certain percentage (as determined by the tolerance slider - usually 30%) then how large that second pick is in relation to the first will determine how much of that color bleeds into the primary color. The same calculation is used with the third pick in relation to the first.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Once I got all that sorted out it worked &lt;i&gt;really&lt;/i&gt; well. In the video I am rolling the unit one way slowly, then the other, and finally all over the place quickly. It's fairly responsive and kind of cool to watch. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;It was this idea, how this mixing worked, that had me wondering whether I'd post &lt;i&gt;anything&lt;/i&gt; about any of this. I have scoured the web on several occasions looking for whether anyone else has figured this out. I've found little or no examples. Where I did find examples either they made no sense to me, or they didn't have enough information. When I eventually did come up with a solution - and I'm not saying this is the best/only way of doing this - I honestly didn't want to share it. Partially because no one else did and I felt a little like I wanted to hold onto this secret, but also partially because I'm not sure whether I want to build and sell juggling balls (or other products) using this technology. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Eventually - and obviously - I gave in and posted everything. What I came up with isn't really all that complicated or hard to figure out, though it did take me a while. I also feel like I need to pay some of this forward. I've gotten so many other good ideas and just raw reference - how to - from the inter-toobz that I think I should put some quasi-useful stuff out there myself. This is one of the reasons why I almost ALWAYS post code - and put lots of comments in said code.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Anyway, as usual, I'm not going to post &lt;i&gt;all &lt;/i&gt;the .NET code here, though. It's fairly big and I'm feeling somewhat lazy at this point. The core of what you'd need to see is in the MainForm.cs, which is posted below:&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;br /&gt;&lt;pre style="margin: 0px; padding: 6px; border: 1px inset; width: 100%; height: 150px; text-align: left; font-family: Courier New, monospace; overflow: auto"&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.Collections.Generic;&lt;br /&gt;using System.ComponentModel;&lt;br /&gt;using System.Configuration;&lt;br /&gt;using System.Data;&lt;br /&gt;using System.Drawing;&lt;br /&gt;using System.IO.Ports;&lt;br /&gt;using System.Text;&lt;br /&gt;using System.Windows.Forms;&lt;br /&gt;&lt;br /&gt;namespace XYZtoRGB_PointFade&lt;br /&gt;{&lt;br /&gt;public partial class MainForm : Form&lt;br /&gt;{&lt;br /&gt;#region Members&lt;br /&gt;&lt;br /&gt;// full length of each axis&lt;br /&gt;private const int conMax = 692;&lt;br /&gt;&lt;br /&gt;// mid point of the axis&lt;br /&gt;private const int conMid = 346;&lt;br /&gt;&lt;br /&gt;// points picked - can only be 3 of 6 at a time&lt;br /&gt;private int[,] picks = { { 0, 0 }, { 0, 0 }, { 0, 0 } };&lt;br /&gt;&lt;br /&gt;// blue, red, violet, green, yellow, aqua&lt;br /&gt;private int[,] colors = {&lt;br /&gt;   { 255, 255, 0 },&lt;br /&gt;   { 255, 0, 0 },&lt;br /&gt;   { 0, 255, 0 },&lt;br /&gt;   { 0, 255, 255 },&lt;br /&gt;   { 255, 0, 255 },&lt;br /&gt;   { 0, 0, 255 }&lt;br /&gt;   };&lt;br /&gt;&lt;br /&gt;// the serial port we'll read from&lt;br /&gt;private SerialPort arduino = null;&lt;br /&gt;&lt;br /&gt;// read from the serial input - by default, don't&lt;br /&gt;private bool readSerial = false;&lt;br /&gt;&lt;br /&gt;// places to put port and rate&lt;br /&gt;string comPort = string.Empty;&lt;br /&gt;int baudRate = 0;&lt;br /&gt;&lt;br /&gt;// smoothing arrays&lt;br /&gt;int[] xList = new int[50];&lt;br /&gt;int[] yList = new int[50];&lt;br /&gt;int[] zList = new int[50];&lt;br /&gt;&lt;br /&gt;// watch values of the smooth loops&lt;br /&gt;int wsx = 0, wsy = 0, wsz = 0;&lt;br /&gt;&lt;br /&gt;#endregion Members&lt;br /&gt;&lt;br /&gt;#region Events&lt;br /&gt;&lt;br /&gt;public MainForm()&lt;br /&gt;{&lt;br /&gt;   InitializeComponent();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;private void MainForm_Load(object sender, EventArgs e)&lt;br /&gt;{&lt;br /&gt;   // init our smoothing arrays?&lt;br /&gt;   for (int i = 0; i &lt; comport =" ConfigurationManager.AppSettings[" baudrate =" int.Parse(ConfigurationManager.AppSettings[" text =" tbSmoothing.Value" text =" tbTolerance.Value" readserial =" false;" text = "Read" readserial =" true;" text = "Stop"&gt;&lt;br /&gt;/// What to do when one or all of the axis are changed,&lt;br /&gt;/// namely update the color displayed.&lt;br /&gt;///&lt;br /&gt;private void AxisUpdate()&lt;br /&gt;{&lt;br /&gt;   // fetch and display the axis values&lt;br /&gt;   txtXaxis.Text = tbXaxis.Value + "";&lt;br /&gt;   txtYaxis.Text = tbYaxis.Value + "";&lt;br /&gt;   txtZaxis.Text = tbZaxis.Value + "";&lt;br /&gt;&lt;br /&gt;   // mix these values into colors&lt;br /&gt;   MixPicks(tbXaxis.Value, tbYaxis.Value, tbZaxis.Value);&lt;br /&gt;&lt;br /&gt;   // then draw the map&lt;br /&gt;   DrawAxisMap();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/// &lt;summary&gt;&lt;br /&gt;/// More complicated color computation based on three&lt;br /&gt;/// points of dominance, ranked in order&lt;br /&gt;/// &lt;/summary&gt;&lt;br /&gt;///&lt;br /&gt;///&lt;br /&gt;///&lt;br /&gt;private void MixPicks(int xVal, int yVal, int zVal)&lt;br /&gt;{&lt;br /&gt;   FindPicks(xVal, yVal, zVal);&lt;br /&gt;&lt;br /&gt;   //txtPoint1.Text = picks[0, 0] + "";&lt;br /&gt;   txtStep1.Text = picks[0, 1] + "";&lt;br /&gt;&lt;br /&gt;   //txtPoint2.Text = picks[1, 0] + "";&lt;br /&gt;   txtStep2.Text = picks[1, 1] + "";&lt;br /&gt;&lt;br /&gt;   //txtPoint3.Text = picks[2, 0] + "";&lt;br /&gt;   txtStep3.Text = picks[2, 1] + "";&lt;br /&gt;&lt;br /&gt;   // an array to hold the chosen color&lt;br /&gt;   int[] choice = { 0, 0, 0 };&lt;br /&gt;   int idx = picks[0, 0];&lt;br /&gt;&lt;br /&gt;   // set the primary color&lt;br /&gt;   choice[0] = colors[idx, 0];&lt;br /&gt;   choice[1] = colors[idx, 1];&lt;br /&gt;   choice[2] = colors[idx, 2];&lt;br /&gt;&lt;br /&gt;   if (tbTolerance.Value &lt; perf =" ((float)tbTolerance.Value" per2 =" ((float)picks[1," per3 =" ((float)picks[2,"&gt; perF)&lt;br /&gt;       {&lt;br /&gt;           idx = picks[1, 0];&lt;br /&gt;           choice[0] = AdjustColor(choice[0], colors[idx, 0], per2);&lt;br /&gt;           choice[1] = AdjustColor(choice[1], colors[idx, 1], per2);&lt;br /&gt;           choice[2] = AdjustColor(choice[2], colors[idx, 2], per2);&lt;br /&gt;       }&lt;br /&gt;&lt;br /&gt;       // if color 3 is above tolerance&lt;br /&gt;       if (per3 &gt; perF)&lt;br /&gt;       {&lt;br /&gt;           idx = picks[2, 0];&lt;br /&gt;           choice[0] = AdjustColor(choice[0], colors[idx, 0], per3);&lt;br /&gt;           choice[1] = AdjustColor(choice[1], colors[idx, 1], per3);&lt;br /&gt;           choice[2] = AdjustColor(choice[2], colors[idx, 2], per3);&lt;br /&gt;       }&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   ShowColor(choice[0], choice[1], choice[2]);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/// &lt;summary&gt;&lt;br /&gt;/// More compact method that returns a multidimensional&lt;br /&gt;/// array of the accelerometer values along with the points&lt;br /&gt;/// they represent.&lt;br /&gt;/// &lt;/summary&gt;&lt;br /&gt;///&lt;br /&gt;///&lt;br /&gt;///&lt;br /&gt;/// &lt;returns&gt;&lt;/returns&gt;&lt;br /&gt;private void FindPicks(int xVal, int yVal, int zVal)&lt;br /&gt;{&lt;br /&gt;   // supporting cast&lt;br /&gt;   int pnt = 0, val = 0;&lt;br /&gt;&lt;br /&gt;   // clear the text boxes&lt;br /&gt;   //txtXplus.Text = "0";&lt;br /&gt;   //txtXminus.Text = "0";&lt;br /&gt;   //txtYplus.Text = "0";&lt;br /&gt;   //txtYminus.Text = "0";&lt;br /&gt;   //txtZplus.Text = "0";&lt;br /&gt;   //txtZminus.Text = "0";&lt;br /&gt;&lt;br /&gt;   // blue, red, violet, green, yellow, aqua&lt;br /&gt;&lt;br /&gt;   // x plus/minus or red/green&lt;br /&gt;   if (xVal &lt; text =" picks[0,"&gt; conMax) { xVal = conMax; }&lt;br /&gt;       picks[0, 1] = xVal - conMid;&lt;br /&gt;       //txtXminus.Text = picks[0, 1] + "";&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   // y plus/minus or violet/yellow&lt;br /&gt;   if (yVal &lt; text =" picks[1,"&gt; conMax) { yVal = conMax; }&lt;br /&gt;       picks[1, 1] = yVal - conMid;&lt;br /&gt;       //txtYminus.Text = picks[1, 1] + "";&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   // z plus/minus or aqua/blue&lt;br /&gt;   if (zVal &lt; text =" picks[2,"&gt; conMax) { zVal = conMax; }&lt;br /&gt;       picks[2, 1] = zVal - conMid;&lt;br /&gt;       //txtZminus.Text = picks[2, 1] + "";&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   int limit = 2;&lt;br /&gt;&lt;br /&gt;   do&lt;br /&gt;   {&lt;br /&gt;       int last = 0;&lt;br /&gt;&lt;br /&gt;       for (int i = 0; i &lt; j =" i" pnt =" picks[i," val =" picks[i," last =" i;" limit =" last;"&gt; 0);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/// &lt;summary&gt;&lt;br /&gt;/// Separate method to make the determination of whether to&lt;br /&gt;/// use a new possible color or to keep the current color.&lt;br /&gt;///&lt;br /&gt;/// This is core to the whole method because it allows us to&lt;br /&gt;/// first put in a core color and then later to introduce seconday&lt;br /&gt;/// and tertiary colors if they do not over power the dominant&lt;br /&gt;/// color.&lt;br /&gt;/// &lt;/summary&gt;&lt;br /&gt;///&lt;br /&gt;///&lt;br /&gt;///&lt;br /&gt;/// &lt;returns&gt;&lt;/returns&gt;&lt;br /&gt;private static int AdjustColor(int current, int possible, float percent)&lt;br /&gt;{&lt;br /&gt;   // reduce the possible color by the given percent&lt;br /&gt;   int test = (int)(possible * percent);&lt;br /&gt;&lt;br /&gt;   // default our adjusted color to the current&lt;br /&gt;   int adjusted = current;&lt;br /&gt;&lt;br /&gt;   // if the test color is larger, use it&lt;br /&gt;   if (test &gt; adjusted) { adjusted = test; }&lt;br /&gt;&lt;br /&gt;   // return the adjusted color&lt;br /&gt;   return adjusted;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/// &lt;summary&gt;&lt;br /&gt;/// Display RGB value to view panel&lt;br /&gt;/// &lt;/summary&gt;&lt;br /&gt;///&lt;br /&gt;///&lt;br /&gt;///&lt;br /&gt;private void ShowColor(int rVal, int gVal, int bVal)&lt;br /&gt;{&lt;br /&gt;   // first show the numeric values in text boxes&lt;br /&gt;   txtRed.Text = rVal + "";&lt;br /&gt;   txtGreen.Text = gVal + "";&lt;br /&gt;   txtBlue.Text = bVal + "";&lt;br /&gt;&lt;br /&gt;   // then set the color&lt;br /&gt;   pnlColor.BackColor = Color.FromArgb(rVal, gVal, bVal);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;///&lt;br /&gt;/// Does the work of fetching serial data from the Arduino&lt;br /&gt;/// and displaying it - in various ways - to the form.&lt;br /&gt;///&lt;br /&gt;private void ReadArduino()&lt;br /&gt;{&lt;br /&gt;   // working variables&lt;br /&gt;   char[] delim = { ',' };&lt;br /&gt;   string line = "";&lt;br /&gt;   string[] axis = null;&lt;br /&gt;   int tmpX = -1, tmpY = -1, tmpZ = -1;&lt;br /&gt;   int count = 0;&lt;br /&gt;&lt;br /&gt;   // if we haven't already connected&lt;br /&gt;   if (arduino == null)&lt;br /&gt;   {&lt;br /&gt;       // connect to the Arduino&lt;br /&gt;       arduino = new SerialPort(comPort, baudRate);&lt;br /&gt;       arduino.ReadTimeout = 5000;&lt;br /&gt;       arduino.WriteTimeout = 5000;&lt;br /&gt;       arduino.Open();&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   // while flagged to read&lt;br /&gt;   while (readSerial)&lt;br /&gt;   {&lt;br /&gt;       count++;&lt;br /&gt;&lt;br /&gt;       // fetch one line of serial data from the Arduino&lt;br /&gt;       line = arduino.ReadLine();&lt;br /&gt;&lt;br /&gt;       // remove the return at the end of the line&lt;br /&gt;       if (line.LastIndexOf("\r") &gt; -1)&lt;br /&gt;       {&lt;br /&gt;           line = line.Substring(0, line.Length - 1);&lt;br /&gt;       }&lt;br /&gt;&lt;br /&gt;       // if there was nothing read, just skip this iteration&lt;br /&gt;       if (string.IsNullOrEmpty(line.Trim())) { continue; }&lt;br /&gt;&lt;br /&gt;       // implicit else - split the line to an array of strings&lt;br /&gt;       axis = line.Split(delim);&lt;br /&gt;&lt;br /&gt;       // if we got an array&lt;br /&gt;       if (axis != null &amp;amp;&amp;amp; axis.Length == 3)&lt;br /&gt;       {&lt;br /&gt;           // if we can't parse the values, set them low&lt;br /&gt;           if (!int.TryParse(axis[0], out tmpX)) { tmpX = -1; }&lt;br /&gt;           if (!int.TryParse(axis[1], out tmpY)) { tmpY = -1; }&lt;br /&gt;           if (!int.TryParse(axis[2], out tmpZ)) { tmpZ = -1; }&lt;br /&gt;&lt;br /&gt;           // if values are good, smooth them&lt;br /&gt;           if (tmpX &gt; -1) { tmpX = SmoothVal(tmpX, ref wsx, xList); }&lt;br /&gt;           if (tmpY &gt; -1) { tmpY = SmoothVal(tmpY, ref wsy, yList); }&lt;br /&gt;           if (tmpZ &gt; -1) { tmpZ = SmoothVal(tmpZ, ref wsz, zList); }&lt;br /&gt;&lt;br /&gt;           // finally try and set the value&lt;br /&gt;           tbXaxis.Value = (tmpX &gt; conMax) ? conMax : tmpX;&lt;br /&gt;           tbYaxis.Value = (tmpY &gt; conMax) ? conMax : tmpY;&lt;br /&gt;           tbZaxis.Value = (tmpZ &gt; conMax) ? conMax : tmpZ;&lt;br /&gt;&lt;br /&gt;           AxisUpdate();&lt;br /&gt;       }&lt;br /&gt;&lt;br /&gt;       // pump the windows message loop&lt;br /&gt;       Application.DoEvents();&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/// &lt;summary&gt;&lt;br /&gt;/// Chucks a value into one of the lists and then&lt;br /&gt;/// sends back out the caller an averaged value.&lt;br /&gt;/// &lt;/summary&gt;&lt;br /&gt;///&lt;br /&gt;/// &lt;returns&gt;&lt;/returns&gt;&lt;br /&gt;private int SmoothVal(int value, ref int ws, int[] axList)&lt;br /&gt;{&lt;br /&gt;   int smax = tbSmoothing.Value;&lt;br /&gt;   int avg = 0;&lt;br /&gt;&lt;br /&gt;   // if no smoothing, return what ya got&lt;br /&gt;   if (smax &lt;= 0) { return value; }              // add to our watch index             ws++;              // shift index back to zero if greater than smoothing limit             if (ws &gt;= smax) { ws = 0; }&lt;br /&gt;&lt;br /&gt;   // put it in the array&lt;br /&gt;   axList[ws] = value;&lt;br /&gt;&lt;br /&gt;   // next, get the average&lt;br /&gt;   for (int i = 0; i &lt; value =" ((int)avg" value =" (value"&gt; conMax) ? conMax : value;&lt;br /&gt;&lt;br /&gt;   // return the average&lt;br /&gt;   return value;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/// &lt;summary&gt;&lt;br /&gt;/// Draw the axis map with emphasis on given axis that are&lt;br /&gt;/// currently influencing the colors&lt;br /&gt;/// &lt;/summary&gt;&lt;br /&gt;private void DrawAxisMap()&lt;br /&gt;{&lt;br /&gt;   // clear what was there first&lt;br /&gt;   Graphics gfx = pbAxisMap.CreateGraphics();&lt;br /&gt;   gfx.Clear(Color.DimGray);&lt;br /&gt;   gfx.Dispose();&lt;br /&gt;&lt;br /&gt;   // get some numbers&lt;br /&gt;   int w = pbAxisMap.Width;&lt;br /&gt;   int h = pbAxisMap.Height;&lt;br /&gt;   int cx = ((int)w / 2);&lt;br /&gt;   int cy = ((int)h / 2);&lt;br /&gt;&lt;br /&gt;   // blue, red, violet, green, yellow, aqua&lt;br /&gt;&lt;br /&gt;   // draw the lines&lt;br /&gt;   DrawLine(0, PickWidth(0), cx, cy, cx, h);&lt;br /&gt;   DrawLine(1, PickWidth(1), cx, cy, 0, cy + cy / 2);&lt;br /&gt;   DrawLine(2, PickWidth(2), cx, cy, w, cy + cy / 2);&lt;br /&gt;   DrawLine(3, PickWidth(3), cx, cy, w, cy / 2);&lt;br /&gt;   DrawLine(4, PickWidth(4), cx, cy, 0, cy / 2);&lt;br /&gt;   DrawLine(5, PickWidth(5), cx, cy, cx, 0);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/// &lt;summary&gt;&lt;br /&gt;/// Picks the width of a given color line.&lt;br /&gt;/// &lt;/summary&gt;&lt;br /&gt;///&lt;br /&gt;/// &lt;returns&gt;&lt;/returns&gt;&lt;br /&gt;private int PickWidth(int idx)&lt;br /&gt;{&lt;br /&gt;   int g = 1;&lt;br /&gt;&lt;br /&gt;   if (idx == picks[0, 0]) { g = 9; }&lt;br /&gt;   else if (idx == picks[1, 0]) { g = 6; }&lt;br /&gt;   else if (idx == picks[2, 0]) { g = 3; }&lt;br /&gt;&lt;br /&gt;   return g;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/// &lt;summary&gt;&lt;br /&gt;/// Draw a single line of a given color&lt;br /&gt;/// &lt;/summary&gt;&lt;br /&gt;///&lt;br /&gt;///&lt;br /&gt;///&lt;br /&gt;///&lt;br /&gt;///&lt;br /&gt;///&lt;br /&gt;private void DrawLine(int idx, int girth, int x1, int y1, int x2, int y2)&lt;br /&gt;{&lt;br /&gt;   Color color = Color.FromArgb(colors[idx,0], colors[idx, 1], colors[idx, 2]);&lt;br /&gt;   Point point1 = new Point(x1, y1);&lt;br /&gt;   Point point2 = new Point(x2, y2);&lt;br /&gt;   Pen pen = new Pen(color, girth);&lt;br /&gt;   Graphics gfx = pbAxisMap.CreateGraphics();&lt;br /&gt;&lt;br /&gt;   gfx.DrawLine(pen, point1, point2);&lt;br /&gt;&lt;br /&gt;   pen.Dispose();&lt;br /&gt;   gfx.Dispose();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;#endregion Supporting&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Once I got this working SO well in .NET I thought it'd be a cinch to get it working the same in the Arduino, right? Not so much. The language is MUCH simpler and has less to support what I wanted to do. I tried in .NET to use simple concepts and "do the work" where I should. For example I sorted the top 3 values myself using a bubble sort instead of just calling the "sort" on a collection.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;What I got in the Arduino sort of worked, but not nearly as well. Here's a video I hope will help explain what I mean:&lt;/div&gt;&lt;div&gt;&lt;object width="410" height="329"&gt;&lt;param name="movie" value="http://www.youtube.com/v/jsSZS0b6Zcc&amp;amp;hl=en_US&amp;amp;fs=1&amp;amp;"&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;param name="allowscriptaccess" value="always"&gt;&lt;embed src="http://www.youtube.com/v/jsSZS0b6Zcc&amp;amp;hl=en_US&amp;amp;fs=1&amp;amp;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="410" height="329"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;It's not smooth like the .NET app. For that matter there's not really much distinct "mid" color at all. It's like there's one middle color between the two major colors. I do have a &lt;a href="http://www.sparkfun.com/commerce/product_info.php?products_id=8579"&gt;BlinkM&lt;/a&gt; somewhere that I should really consider trying before I dismantle this whole thing. It may simplify the handling of colors, but it does have one considerable drawback - it's expensive. The RGB LED's cost about $2, and the BlinkM was $12. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I fiddled with this set up for a bit before deciding to post. It's close, but I'm kind of out of patience for it at this stage. My first juggle-able prototype will probably be just the 6 basic colors. This is easy to achieve and, to be honest, when juggling no one is going to notice the lack of fades as much. Here's a similar video with no fading:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;object width="419" height="329"&gt;&lt;param name="movie" value="http://www.youtube.com/v/_Se1Oa-kzKg&amp;hl=en_US&amp;fs=1&amp;"&gt;&lt;/param&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;/param&gt;&lt;param name="allowscriptaccess" value="always"&gt;&lt;/param&gt;&lt;embed src="http://www.youtube.com/v/_Se1Oa-kzKg&amp;hl=en_US&amp;fs=1&amp;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="410" height="329"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;I think for my first "throwable" prototype I'll just stick with the basic 6 colors. I intend to get a &lt;a href="http://www.moderndevice.com/products/rbbb-kit"&gt;Really Bare Bones Board&lt;/a&gt; kit from Modern Device for this. It's small and really cheap. If I eventually figure out fading and I think I've got something like a real product on my hands I may consider creating a custom PCB that puts the accelerometer and the smaller form-factor ATmega328 directly on board along with LEDs. Possible a circular PCB that could be bolted directly into a ball, though some shock absorption of some sort may be in order.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Now that I've got this project in the cloud and off my chest, as it were, I can move on to another idea. I want to use the Arduino, a web cam, and a servo along with (yet another) custom .NET app to create a panning web cam app. I'll probably point it at my fish tank for now, but this is something I have a practical application for - watching the utility room at my folk's cabin. More on that later...&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;pre style="margin: 0px; padding: 6px; border: 1px inset; width: 100%; height: 150px; text-align: left; font-family: Courier New, monospace; overflow: auto"&gt;&lt;br /&gt;/*&lt;br /&gt;* PointFade3.pde&lt;br /&gt;*&lt;br /&gt;* Third versiom of fading colors between 6 points&lt;br /&gt;* of the accelerometer cross. This should be a&lt;br /&gt;* conversion of the .NET code that I'd got working.&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;// axis analog pins&lt;br /&gt;int xPin = 0, yPin = 1, zPin = 2;&lt;br /&gt;&lt;br /&gt;// axis value mid and max&lt;br /&gt;int axMax = 692, axMid = 346;&lt;br /&gt;&lt;br /&gt;// pins controlling red/green/blue&lt;br /&gt;int rPin = 3, gPin = 6, bPin = 5;&lt;br /&gt;&lt;br /&gt;// values from those pins&lt;br /&gt;int xVal = 0, yVal = 0, zVal = 0;&lt;br /&gt;&lt;br /&gt;// smoothing&lt;br /&gt;int xLst[50], yLst[50], zLst[50];&lt;br /&gt;int sTrk = 0, sMax = 10;&lt;br /&gt;boolean full = false;&lt;br /&gt;&lt;br /&gt;// array to store top 3 picks&lt;br /&gt;int picks[][3] = {{ 0, 0 }, { 0, 0 }, { 0, 0 }};&lt;br /&gt;&lt;br /&gt;// array to store positions and values of colors&lt;br /&gt;int colors[][6] = {&lt;br /&gt;{ 102, 163, 0 },&lt;br /&gt;{ 102, 0, 0 },&lt;br /&gt;{ 0, 163, 0 },&lt;br /&gt;{ 0, 163, 163 },&lt;br /&gt;{ 102, 0, 163 },&lt;br /&gt;{ 0, 0, 163 }&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;// tolerance - or how much fade&lt;br /&gt;float tol = 1.00;&lt;br /&gt;&lt;br /&gt;// maximum PWM allowed for each LED&lt;br /&gt;int rMax = 102, gMax = 163, bMax = 163;&lt;br /&gt;&lt;br /&gt;// power for the 7-segment LED&lt;br /&gt;int segPow = 11;&lt;br /&gt;&lt;br /&gt;// establish an array for our LED pins&lt;br /&gt;int segLed[7] = { 4, 7, 8, 9, 10, 12, 13 };&lt;br /&gt;&lt;br /&gt;// array to store settings for numbers&lt;br /&gt;int numbers[][11] = {&lt;br /&gt;{ LOW,  LOW,  LOW,  LOW,  HIGH, LOW,  LOW  }, // 0&lt;br /&gt;{ LOW,  LOW,  HIGH, HIGH, HIGH, HIGH, HIGH }, // 1&lt;br /&gt;{ HIGH, LOW,  LOW,  HIGH, LOW,  LOW,  LOW  }, // 2&lt;br /&gt;{ LOW,  LOW,  LOW,  HIGH, LOW,  LOW,  HIGH }, // 3&lt;br /&gt;{ LOW,  LOW,  HIGH, LOW,  LOW,  HIGH, HIGH }, // 4&lt;br /&gt;{ LOW,  HIGH, LOW,  LOW,  LOW,  LOW,  HIGH }, // 5&lt;br /&gt;{ LOW,  HIGH, LOW,  LOW,  LOW,  LOW,  LOW  }, // 6&lt;br /&gt;{ LOW,  LOW,  LOW,  HIGH, HIGH, HIGH, HIGH }, // 7&lt;br /&gt;{ LOW,  LOW,  LOW,  LOW,  LOW,  LOW,  LOW  }, // 8&lt;br /&gt;{ LOW,  LOW,  LOW,  LOW,  LOW,  HIGH, HIGH }, // 9&lt;br /&gt;{ HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH }  // off&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/*&lt;br /&gt;* The "run once" setup method&lt;br /&gt;*/&lt;br /&gt;void setup()&lt;br /&gt;{&lt;br /&gt;// set up to communication with serial&lt;br /&gt;Serial.begin(9600);&lt;br /&gt;&lt;br /&gt;// set axis/analog pins to input&lt;br /&gt;pinMode(xPin, INPUT);&lt;br /&gt;pinMode(yPin, INPUT);&lt;br /&gt;pinMode(zPin, INPUT);&lt;br /&gt;&lt;br /&gt;// turn on power for the 7-segment display&lt;br /&gt;analogWrite(segPow, 102);&lt;br /&gt;&lt;br /&gt;// initialize all 7 segment LED pins&lt;br /&gt;for (int idx = 0; idx &lt; xval =" getListVal(xLst);" yval =" getListVal(yLst);" zval =" getListVal(zLst);" xrv =" analogRead(xPin);" yrv =" analogRead(yPin);" zrv =" analogRead(zPin);" strk =" sTrk"&gt;= sMax)&lt;br /&gt;{&lt;br /&gt;// reset to beginning&lt;br /&gt;sTrk = 0;&lt;br /&gt;&lt;br /&gt;// and track that we've filled the arrays at least once&lt;br /&gt;full = true;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/*&lt;br /&gt;* Get a smoothed value from given array&lt;br /&gt;*/&lt;br /&gt;int getListVal(int aLst[50])&lt;br /&gt;{&lt;br /&gt;int idx = 0;&lt;br /&gt;long sum = 0;&lt;br /&gt;&lt;br /&gt;for (idx = 0; idx &lt; idx =" idx" sum =" sum" ret =" sum" pnt =" 0," val =" 0;"&gt; axMax) { xVal = axMax; }&lt;br /&gt;picks[0][1] = xVal - axMid;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;// y plus/minus&lt;br /&gt;if (yVal &lt;&gt; axMax) { yVal = axMax; }&lt;br /&gt;picks[1][1] = yVal - axMid;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;// z plus/minus&lt;br /&gt;if (zVal &lt;&gt; axMax) { zVal = axMax; }&lt;br /&gt;picks[2][1] = zVal - axMid;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;// now sort 'em&lt;br /&gt;&lt;br /&gt;int limit = 2;&lt;br /&gt;&lt;br /&gt;do&lt;br /&gt;{&lt;br /&gt;int last = 0;&lt;br /&gt;&lt;br /&gt;for (int i = 0; i &lt; j =" i" pnt =" picks[i][0];" val =" picks[i][1];" last =" i;" limit =" last;"&gt; 0);&lt;br /&gt;&lt;br /&gt;//showPicks(picks[0][0], picks[0][1],&lt;br /&gt;//picks[1][0], picks[1][1], picks[2][0], picks[2][1]);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/*&lt;br /&gt;* We should have our top 3 colors. Now&lt;br /&gt;* we need to mix them in relation to each&lt;br /&gt;* other based on the tolerance.&lt;br /&gt;*/&lt;br /&gt;void MixColors()&lt;br /&gt;{&lt;br /&gt;// create an array to hold the chosen color&lt;br /&gt;int choice[3] = { 0, 0, 0 };&lt;br /&gt;&lt;br /&gt;// get the percentages of the other two colors&lt;br /&gt;float per2 = ((float)picks[1][1] / (float)picks[0][1]);&lt;br /&gt;float per3 = ((float)picks[2][1] / (float)picks[0][1]);&lt;br /&gt;&lt;br /&gt;// find the primary index&lt;br /&gt;int idx = picks[0][0];&lt;br /&gt;&lt;br /&gt;// show the number on the 7-segment&lt;br /&gt;showDigit(idx);&lt;br /&gt;&lt;br /&gt;// set the primary color&lt;br /&gt;choice[0] = colors[idx][0];&lt;br /&gt;choice[1] = colors[idx][1];&lt;br /&gt;choice[2] = colors[idx][2];&lt;br /&gt;&lt;br /&gt;//showChoice(idx, choice[0], choice[1], choice[2]);&lt;br /&gt;&lt;br /&gt;// if we set a usable tolerance&lt;br /&gt;if (tol &lt;&gt; tol)&lt;br /&gt;{&lt;br /&gt;//Serial.println("In per2 adjust");&lt;br /&gt;int i2 = picks[1][0];&lt;br /&gt;if (colors[i2][0] &gt; 0) { choice[0] = AdjustColor(choice[0], colors[i2][0], per2); }&lt;br /&gt;if (colors[i2][1] &gt; 0) { choice[1] = AdjustColor(choice[1], colors[i2][1], per2); }&lt;br /&gt;if (colors[i2][2] &gt; 0) { choice[2] = AdjustColor(choice[2], colors[i2][2], per2); }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;// if color 3 is above tolerance&lt;br /&gt;if (per3 &gt; tol)&lt;br /&gt;{&lt;br /&gt;int i3 = picks[2][0];&lt;br /&gt;if (colors[i3][0] &gt; 0) { choice[0] = AdjustColor(choice[0], colors[i3][0], per3); }&lt;br /&gt;if (colors[i3][1] &gt; 0) { choice[1] = AdjustColor(choice[1], colors[i3][1], per3); }&lt;br /&gt;if (colors[i3][2] &gt; 0) { choice[2] = AdjustColor(choice[2], colors[i3][2], per3); }&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;// show the color on the RGB LEDs&lt;br /&gt;ShowColor(choice[0], choice[1], choice[2]);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/*&lt;br /&gt;* A separate method dedicated to making the determination of whether&lt;br /&gt;* to use a new possible color or to keep the current color. This is&lt;br /&gt;* the core to color mixing because it allows us to first put in a&lt;br /&gt;* core color and then alter to introduce secondary and tertiary colors&lt;br /&gt;* if they do not overpower the dominant color.&lt;br /&gt;*/&lt;br /&gt;int AdjustColor(int current, int possible, float percent)&lt;br /&gt;{&lt;br /&gt;// default our adjusted color to the current&lt;br /&gt;int adjusted = current;&lt;br /&gt;&lt;br /&gt;// if the percent and possible are useful&lt;br /&gt;if (possible &gt; 0 &amp;amp;&amp;amp; percent  &gt; 0)&lt;br /&gt;{&lt;br /&gt;// reduce the possible color by the given percent&lt;br /&gt;int test = possible * percent;&lt;br /&gt;&lt;br /&gt;// if the test color is larger, use it&lt;br /&gt;if (test &gt; adjusted) { adjusted = test; }&lt;br /&gt;&lt;br /&gt;/*&lt;br /&gt;Serial.print("Adjust - curr: ");&lt;br /&gt;Serial.print(current);&lt;br /&gt;Serial.print(", poss: ");&lt;br /&gt;Serial.print(possible, DEC);&lt;br /&gt;Serial.print(", perc: ");&lt;br /&gt;Serial.print(percent, 4);&lt;br /&gt;Serial.print(", test: ");&lt;br /&gt;Serial.print(test, DEC);&lt;br /&gt;Serial.println("");&lt;br /&gt;*/&lt;br /&gt;}&lt;br /&gt;else&lt;br /&gt;{&lt;br /&gt;Serial.println("POSSIBLE IS ZERO!!");&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;// return the adjusted color&lt;br /&gt;return adjusted;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/*&lt;br /&gt;* Finally, after all that, light 'em.&lt;br /&gt;*/&lt;br /&gt;void ShowColor(float rPer, float gPer, float bPer)&lt;br /&gt;{&lt;br /&gt;//showAxis(rPer, gPer, bPer);&lt;br /&gt;&lt;br /&gt;// calulate percentages lit&lt;br /&gt;int rVal = rMax * rPer;&lt;br /&gt;int gVal = gMax * gPer;&lt;br /&gt;int bVal = bMax * bPer;&lt;br /&gt;&lt;br /&gt;// light the LEDs to these percents&lt;br /&gt;analogWrite(rPin, rVal);&lt;br /&gt;analogWrite(gPin, gVal);&lt;br /&gt;analogWrite(bPin, bVal);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/*&lt;br /&gt;* Given specific number pluck out that&lt;br /&gt;* row in the multi-dimensional array to&lt;br /&gt;* show that combination of LOW/HIGH vals&lt;br /&gt;*/&lt;br /&gt;void showDigit(int digit)&lt;br /&gt;{&lt;br /&gt;// loop through LED pins&lt;br /&gt;for (int idx = 0; idx &lt;&gt;&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8077223744586062132-6440214589292079898?l=winkmake.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winkmake.blogspot.com/feeds/6440214589292079898/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://winkmake.blogspot.com/2010/03/still-on-xyz-and-rgb.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8077223744586062132/posts/default/6440214589292079898'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8077223744586062132/posts/default/6440214589292079898'/><link rel='alternate' type='text/html' href='http://winkmake.blogspot.com/2010/03/still-on-xyz-and-rgb.html' title='Still on XYZ and RGB'/><author><name>Jwink</name><uri>http://www.blogger.com/profile/07356738572886578752</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://1.bp.blogspot.com/_LHP9sz9ANuQ/SWrQ95K1ecI/AAAAAAAAADw/Y3VUIKi1xy0/S220/DSCF4218_face.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_LHP9sz9ANuQ/S5MXf1-286I/AAAAAAAAAOs/qYOGsJA_fT0/s72-c/DSCF8606_small.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8077223744586062132.post-6172048744496221267</id><published>2009-12-11T13:14:00.000-08:00</published><updated>2009-12-11T13:35:06.671-08:00</updated><title type='text'>Amusing error messages</title><content type='html'>So far in this blog I have not posted at all about what I do for a living. I've only posted about one of my many hobbies. But today I ran into something I wanted to share. I could go on and on about how I could share it (Facebook, Yammer, emails to hapless co-workers, emails to hapless friends, drone on and on to my wife about it) but I won't. Much.&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Instead, I'll post it here. Here where it can quietly sit where few, if any, will see it. But I can always go back and get a chuckle about it. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Anyway, what I do for a living is write software. I am a software engineer. I've created software in a number of different languages: Pascal, COBOL, C++, Visual Basic, Java, C# - probably others I am forgetting - and I've been doing it for over 17 years now. Strange, but true. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;This blog is about stuff I make. Software is stuff I make, right? Okay, boring stuff I make - I'll try and keep it to a minimum.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Anyway, I'm currently contracting at a company that uses Oracle (10g?) as it's primary database server. The current task I am working on involves creating a seed script to load some values in a database. Seed scripts are an easy way around creating an intelligent user interface to do the same thing. It's what I typically do when I am told not to spend too much time working on a task. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The seed script will load a series of values into the database representing the types of pages users can hit on a particular site. The goal is to eventually create a report that shows - by company, date, etc. - how many users hit what page and when. The table I am loading is used to identify the page and associate a key with it. What I was trying to do was to update the sequence object in Oracle that creates that key.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The sequence is an object within Oracle that, when you ask it, gives you the next sequential number in a sequence. It also remembers what it last gave out so it can give the next number next time it is asked. It's useful in generating keys which is exactly what I was using it for. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;In this company's development environment I had been doing a lot of testing, so the sequence number was abnormally high. I figured I'd reset it to a lower number to make my seed entries show up with same/similar numbers as the other environments. I attempted to run a command that would do this:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;b&gt;&lt;span class="Apple-style-span"  style="color:#330099;"&gt;ALTER SEQUENCE &lt;/span&gt;&lt;/b&gt;ThisTable_SEQ&lt;b&gt; &lt;/b&gt;&lt;span class="Apple-style-span"  style="color:#330099;"&gt;&lt;b&gt;START WITH&lt;/b&gt;&lt;/span&gt; 200;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;This is not allowed in Oracle, but instead of telling me that, they decided to be snide about it. Their responds was:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;Error report:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;SQL Error: ORA-02283: cannot alter starting sequence number&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;02283. 00000 -  "cannot alter starting sequence number"&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;*Cause:    Self-evident.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;*Action:   Don't alter it.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The cause was self-evident? Don't alter it? Translation: You can't do that. Duh! Stop it.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;It seems odd to me when I get answers like this. It seems even odder that they won't allow me to do this when the work-around is so simple:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;b&gt;&lt;span class="Apple-style-span"  style="color:#330099;"&gt;DROP SEQUENCE&lt;/span&gt;&lt;/b&gt; ThisTable_SEQ;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="color:#330099;"&gt;CREATE SEQUENCE&lt;/span&gt; ThisTable_SEQ &lt;b&gt;&lt;span class="Apple-style-span"  style="color:#330099;"&gt;MINVALUE&lt;/span&gt;&lt;/b&gt; 1 &lt;b&gt;&lt;span class="Apple-style-span"  style="color:#330099;"&gt;MAXVALUE&lt;/span&gt;&lt;/b&gt; 999999999999999999999999999 &lt;span class="Apple-style-span"  style="color:#330099;"&gt;&lt;b&gt;INCREMENT BY&lt;/b&gt;&lt;/span&gt;&lt;b&gt; &lt;/b&gt;1 &lt;span class="Apple-style-span"  style="color:#330099;"&gt;&lt;b&gt;START&lt;/b&gt; &lt;b&gt;WITH&lt;/b&gt;&lt;/span&gt;&lt;b&gt; &lt;/b&gt;200 &lt;span class="Apple-style-span"  style="color:#330099;"&gt;&lt;b&gt;CACHE &lt;/b&gt;&lt;/span&gt;10 &lt;b&gt;&lt;span class="Apple-style-span"  style="color:#330099;"&gt;ORDER NOCYCLE&lt;/span&gt;&lt;/b&gt;;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style=" ;font-family:Georgia, serif;"&gt;&lt;div&gt;Anyway, posted here mostly for my own amusement. And so my brain can now forget it because it's here in the cloud, forever and ever...&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8077223744586062132-6172048744496221267?l=winkmake.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winkmake.blogspot.com/feeds/6172048744496221267/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://winkmake.blogspot.com/2009/12/amusing-error-messages.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8077223744586062132/posts/default/6172048744496221267'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8077223744586062132/posts/default/6172048744496221267'/><link rel='alternate' type='text/html' href='http://winkmake.blogspot.com/2009/12/amusing-error-messages.html' title='Amusing error messages'/><author><name>Jwink</name><uri>http://www.blogger.com/profile/07356738572886578752</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://1.bp.blogspot.com/_LHP9sz9ANuQ/SWrQ95K1ecI/AAAAAAAAADw/Y3VUIKi1xy0/S220/DSCF4218_face.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8077223744586062132.post-108405257735275165</id><published>2009-11-01T10:48:00.001-08:00</published><updated>2009-11-01T17:01:12.934-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='LadyAda'/><category scheme='http://www.blogger.com/atom/ns#' term='Halloween'/><category scheme='http://www.blogger.com/atom/ns#' term='Arduino'/><category scheme='http://www.blogger.com/atom/ns#' term='Radio Shack'/><title type='text'>Arduino-Lantern / Cylon</title><content type='html'>&lt;div style="text-align: center;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_LHP9sz9ANuQ/Su3iy2CTxOI/AAAAAAAAALY/e-6v1GHNuyo/s1600-h/Face.jpg"&gt;&lt;img style="float:right; margin:0 0 10px 10px;cursor:pointer; cursor:hand;width: 320px; height: 316px;" src="http://2.bp.blogspot.com/_LHP9sz9ANuQ/Su3iy2CTxOI/AAAAAAAAALY/e-6v1GHNuyo/s320/Face.jpg" border="0" alt="" id="BLOGGER_PHOTO_ID_5399220891413628130" /&gt;&lt;/a&gt;I had to do this. Partially because I could, but also partially because I needed a quick project. I hadn't done many projects recently (well, summer, duh) and I needed to do something easy with some real impact. Even if I wasn't sure who in the neighborhood would get the joke. I live in the 'burbs - a lot of non-geeks out here.&lt;div&gt;&lt;div&gt;I decided to do some real soldering on this one. I wanted to create a unit I could keep for later if I&lt;/div&gt;&lt;div&gt; wanted to use it. I started with a pile o&lt;/div&gt;&lt;div&gt;f red LED's I had liberated from a set of Christmas lights. Many of these LED's came pre-equipped with their own resistor. I'm not entirely sure why, though I've noticed during my forays with the RGB LEDs that the red typically wanted lower voltage. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I settled on 12 because its what I could comfortably fit in a Radio Shack proto-board. The LEDs with the resistor seemed okay with the 5 volts the Arduino put out without having issues, but the remaining non-resistored ones were rather bright otherwise. So bright that I wound up burning one out. I dug through my stockpile of resistors and found one with the same color stripes as those already set up.&lt;/div&gt;&lt;div style="text-align: left;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I then bent all the leads of the LEDs 90 degrees and, using a wide "chip clip" and my 3rd hand, soldered them into the board. Across from the LEDs I put a female pin header. The 12th LED got it's resistor on board and then all were connected to the female pin header with some extra solder (not an easy task).&lt;/div&gt;&lt;div style="text-align: center;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;img src="http://2.bp.blogspot.com/_LHP9sz9ANuQ/Su3jLflVTBI/AAAAAAAAALg/So3Kux2s330/s400/LEDsBack.jpg" style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 208px;" border="0" alt="" id="BLOGGER_PHOTO_ID_5399221314883243026" /&gt;&lt;div&gt;The female pin header was actually 24 wide. One pin was for voltage, the other for g&lt;/div&gt;&lt;div&gt;round. I considered connecting all the ground pins on board, but since LEDs actually care which is which and I couldn't remember which way I'd wired them, I left all 24 open to accept either.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;img src="http://1.bp.blogspot.com/_LHP9sz9ANuQ/Su3jZhzz22I/AAAAAAAAALo/7cNCic55Eyo/s400/LEDsTop.jpg" style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 246px;" border="0" alt="" id="BLOGGER_PHOTO_ID_5399221555999005538" /&gt;&lt;/div&gt;&lt;img src="http://1.bp.blogspot.com/_LHP9sz9ANuQ/Su3jxL6JLwI/AAAAAAAAALw/Yc5J-Tfu228/s320/Full.jpg" style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;width: 320px; height: 285px;" border="0" alt="" id="BLOGGER_PHOTO_ID_5399221962436849410" /&gt;&lt;div&gt;Part of a breadboard provided ground and a nice spacer between the Arduino pin outs and my LED unit. I wired it up and, using a modified "Knight Rider" program from LadyAda's tutorial site, I had it running in short order. Aside from expanding it to handle the 12 LEDs I had to update it slightly so it left the first LED on before recycling to the next loop. Otherwise that LED would turn off briefly and noticeably. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;Its worth noting that once I got all this working I realized it might have been easier to solder a set of male pins that could slot directly into the Arduino. On that side of the board were all the pins I was using as well as a ground. I could have soldered voltage directly to one pin of each LED and then joined all the other pins to ground. I went so far as to cut two sets of male pins before I realized that these would not line up with a protoboard. The two female headers on the Arduino on that side of the board are broken into two sets. The spacing between the two sets wasn't the proper width to fit standard hole spacings. Bummer.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;img src="http://1.bp.blogspot.com/_LHP9sz9ANuQ/Su3kJCBheUI/AAAAAAAAAL4/BbT6GIBWnKw/s320/Guts.jpg" style="float:right; margin:0 0 10px 10px;cursor:pointer; cursor:hand;width: 320px; height: 240px;" border="0" alt="" id="BLOGGER_PHOTO_ID_5399222372100307266" /&gt;&lt;div&gt;I didn't get around to carving the pumpkins until a couple hours before trick-or-treaters started arriving, so I was somewhat rushed near the end. I had originally planned to use a plastic container for the Arduino so it wasn't brushing up against pumpkin guts. But, in my haste, I ended up using a smaller pumpkin, one that barely fit the Ardunio and the LED unit through the top. I had to cut two slots near the back to allow the breadboard - the widest part - through the top. One slot also provided a nice outlet for the power supply.&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: center;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The pattern for the face came from another blog post from &lt;a href="http://www.evilmadscientist.com/article.php/CylonOLantern"&gt;Evil Mad Scientist Laboratories&lt;/a&gt;. Their project involved soldering a dedicated chip, but I was more interested in the pattern for the pumpkin. I just free-handed what they had on their page to my pumpkin and then used a knife to make deep cuts for most of it. From those deep cuts I sort of chipped away with the knife to reveal the face.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The Arduino is resting on a small plastic treat cup my kids use to eat Cheerios or whatever. This gave it enough height to poke the LEDs out the front. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Here are two videos I took of it. I couldn't decide which was better so I put both up. In the first one the face is easier to see, but the camera is kind of unsteady:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;object width="425" height="344"&gt;&lt;param name="movie" value="http://www.youtube.com/v/v-31tuBlI5g&amp;amp;hl=en&amp;amp;fs=1"&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;param name="allowscriptaccess" value="always"&gt;&lt;embed src="http://www.youtube.com/v/v-31tuBlI5g&amp;amp;hl=en&amp;amp;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I took another one in full darkness. The shot is more steady but the camera decided it needed a light. I could probably have turned it off, but meh...&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;object width="425" height="344"&gt;&lt;param name="movie" value="http://www.youtube.com/v/vXTHVpdrjjs&amp;amp;hl=en&amp;amp;fs=1"&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;param name="allowscriptaccess" value="always"&gt;&lt;embed src="http://www.youtube.com/v/vXTHVpdrjjs&amp;amp;hl=en&amp;amp;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Here's the code I used. As I mentioned it was based on the Knight Rider stuff. When I went through to put comments in I noticed a bunch of code that seemed to have no purpose. Instead of spending time fixing and testing, I figured I'd just make snide comments at myself.&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;pre style="margin: 0px; padding: 6px; border: 1px inset; width: 100%; height: 150px; text-align: left; font-family: Courier New, monospace; overflow: auto"&gt;&lt;br /&gt;/*&lt;br /&gt;* Cylon 12 - similar to Sequence blink&lt;br /&gt;*&lt;br /&gt;* Twelve red leds in sequence scrolling&lt;br /&gt;* back and forth.&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;int count = 0;    // loop counter&lt;br /&gt;int timer = 20;   // miliseconds to wait between blinks&lt;br /&gt;int temp = 0;     // temporary counter&lt;br /&gt;&lt;br /&gt;/*&lt;br /&gt; * Run-once method - turn 12 pins to output&lt;br /&gt; */&lt;br /&gt;void setup()&lt;br /&gt;{&lt;br /&gt; for (count = 1; count &lt;= 12; count++)   {     pinMode(count, OUTPUT);   } }  /*  * Main loop  */ void loop() {   // the loop going out from 1 to 12   for (count = 1; count &lt; temp =" count" count =" 12;"&gt; 0; count--)&lt;br /&gt; {&lt;br /&gt;   // again - shouldn't have to check this - remove it later I guess (or figure out why it's here)&lt;br /&gt;   if (count &lt; temp =" count"&gt; 0) { digitalWrite(temp, HIGH); }&lt;br /&gt;  &lt;br /&gt;   // as long as were in range (do we need to check)&lt;br /&gt;   if (count &gt; 1)&lt;br /&gt;   {&lt;br /&gt;     // wait a bit&lt;br /&gt;     delay(timer);&lt;br /&gt;    &lt;br /&gt;     // turn off main pin&lt;br /&gt;     digitalWrite(count, LOW);&lt;br /&gt;    &lt;br /&gt;     // wait double&lt;br /&gt;     delay(timer*2);&lt;br /&gt;   }&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8077223744586062132-108405257735275165?l=winkmake.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winkmake.blogspot.com/feeds/108405257735275165/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://winkmake.blogspot.com/2009/11/arduino-lantern-cylon.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8077223744586062132/posts/default/108405257735275165'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8077223744586062132/posts/default/108405257735275165'/><link rel='alternate' type='text/html' href='http://winkmake.blogspot.com/2009/11/arduino-lantern-cylon.html' title='Arduino-Lantern / Cylon'/><author><name>Jwink</name><uri>http://www.blogger.com/profile/07356738572886578752</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://1.bp.blogspot.com/_LHP9sz9ANuQ/SWrQ95K1ecI/AAAAAAAAADw/Y3VUIKi1xy0/S220/DSCF4218_face.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_LHP9sz9ANuQ/Su3iy2CTxOI/AAAAAAAAALY/e-6v1GHNuyo/s72-c/Face.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8077223744586062132.post-5840228438445977824</id><published>2009-11-01T10:36:00.000-08:00</published><updated>2009-11-01T21:25:51.972-08:00</updated><title type='text'>The Skywalker Family</title><content type='html'>The origins of the idea, we think, were with our daughter Evy. She wanted to be Princess Leia this year for Halloween. She has fairly long hair &amp;amp; we thought we could probably do the iconic hair buns fairly easily. The outfit that goes with it would be, hopefully, simple (for Jeanette) to make. From there we figured it'd be an easy jump to get Sean outfitted as Luke. &lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I'm not sure where the idea came from that we, their parents, should dress up as... well, their parents. We think Evy eventually decided that this would a cool thing for her parents to do. Jeanette spent many a late night at her serger sewing machine, first with their costumes and then (probably more hours) working on ours.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_LHP9sz9ANuQ/Su3XRn_osTI/AAAAAAAAALQ/rYSClrr0BpA/s1600-h/SkywalkerFamily.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 276px;" src="http://2.bp.blogspot.com/_LHP9sz9ANuQ/Su3XRn_osTI/AAAAAAAAALQ/rYSClrr0BpA/s320/SkywalkerFamily.jpg" border="0" alt="" id="BLOGGER_PHOTO_ID_5399208226080731442" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The result was just fantastic. I only got to wear mine twice, but I think Evy got to wear hers to 5 different events. Jeanette and Sean, both in costume, joined Evy on Friday for Evy's school party. We then all wore our outfits to a 40th birthday party of a friend of mine from college. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;We wore them again, for the last time this year (probably), on Halloween. I took the kids out on their run for candy and got a lot of good comments. Jeanette stayed back at the house and handed out candy. Not ready to be done for the night, Jeanette kept hers on for a shopping errand that same night. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Since this project is more craft than make - and I did very little of the work - any comments on the build I'll leave to Jeanette. If I can get her to post something here.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Jeanette's Comments:&lt;/div&gt;&lt;div&gt;Well, I will see what I can add to the above comments to fill in more details on what turned out to be a rather large, lengthy project for me to tackle in not too long of a time.  As Jim said, Evy was the one who came up with the initial idea of dressing up as Princess Leia. I thought this would be very fun and mostly easy since Leia's iconic outfit from Star Wars IV: A New Hope was fairly straight forward and uncomplicated.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The biggest worry I had to start with was how in the world I was going to get her hair to cooperate and stay contained in those buns. Being pretty young, she still has that awesome fine, slippery hair, just a step up from baby-fine toddler hair, that likes very much to slip out of its confinements starting very soon after said confinement has been implemented. I actually came up with a rather sneaky method for helping myself with this problem after going thru the motions twice using just binders (for the initial ponytails to keep her hair separated into 2 sections at either side of her head) and LOTS of bobby pins. The buns actually worked pretty well on their own for the short term and looked pretty adorable on her. However, for the day of her Halloween party at school I had to come up with another idea to help keep the hair contained for most of a day - during which I would not be present for the first several hours. My solution? I used old knee-high nylons of mine that were past their usefulness as stockings. They were just about the perfect length to go from the binders down to the end of her hair with just a little stretching to contain the ends once twisted into the buns. I had to use far fewer bobby pins (and had to poke holes thru the nylons for the pins to work properly -only minor discomfort to poor Evy during that process) and the buns stayed put remarkably well for a long period of time. It also helped that Evy's hair is a fairly light brown/dark blonde color so the stockings didn't stand out too horribly.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;As for the actual outfit, I used a pattern meant for a shepherdess outfit (think church Christmas play) and implemented a few minor changes that are pretty simple for a somewhat seasoned sewer (no, I am not what I would call an excellent seamstress by any means! I simply am able to make things look like I know what I am doing more than the average person). I made sure the sleeves were loose and fairly long and the hem length was just short enough for Evy to walk around easily without too much constriction but long enough to make no mistake as to who she was dresses as. Having done a couple of other outfits in the past with various collars, I was able to add one to the pattern I used without too much trouble. It did not quite duplicate the real thing but was close enough for costume purposes. I most certainly can not take credit for figuring out how to make the hood (which is actually just a length of material, like a trapezoid, that drapes from one shoulder down and back up to the other shoulder, without being sewed in the center back like a normal hood). I found an excellent website that has pictures of every costume in the Star Wars universe (as far as I can tell) with tons of details and pictures and suggestions for creating parts of the outfits: www.padawansguide.com is the place to go! Totally awesome pics!! The material I chose was some white drapey polyester (I think) type material I already owned. Going for the cost minimization thing here! I did have to make an under dress out of another, heavier white poly-type material I had in order to minimize the sheerness and aim for some greater warmth to accommodate our usually pretty cool Halloweens here in Minnesota. The belt I made for Evy was actually rather amusing. The big metal parts all around the white leather belt were not going to be an option for a child's costume (and a little difficult for me to even think about fabricating in just under a month!) so I came up with another option. I found some silver costume vinyl at the fabric store that I thought would work well as a stand in for the larger silver metal hexagon pieces circling the belt. The white leather-like matte vinyl I actually used for the belt was a remnant that got pretty cheap. As for what is supposed to be the bubble-like parts in the center of the metal hexagons I substituted shiny silver sequin-like discs, super-glued into stacks of 4 onto the center of the silver vinyl decorations. This whole mess was then fabric-glued onto the belt. I thought it turned out looking pretty close to the real thing, for being a child's costume that is.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Sean's Luke Skywalker costume was even easier. Think pajamas! That is exactly what pattern I used for the bottoms. I then took the pattern for the top from that same set and used it as a base size guideline for creating the wrap-style top that Luke wears in Star Wars IV: A New Hope. Now, I did not make extra efforts to make all these costumes without shoulder seams (Leia's, Luke's and even Anakin's outfits all seem to use patterns that have no shoulder seams -but that would require a WHOLE lot more material than I was willing to use or spend money on), but like I said, these are costumes not replicas. I used simple natural tone muslin material which was a pretty close stand-in for the real thing. Luke's belt was similarly improvised using some dark brown vinyl I got free from a friend who had 2 yards she didn't have much use for - terrific luck on my part! The buckle was made from the same silver vinyl (double layer, wrong sides fabric-glued together, for sturdiness and shape) as Evy's belt decorations.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Jim's Anakin outfit was almost as easy as the Luke costume. Think robe and pajama bottom patterns and there you have it! Again, I wasn't looking to duplicate the outfits, just make costumes that emulate them. Anakin actually has many layers to his outfit that proved just a little challenging. The under layer was made from the same natural tone muslin as Luke's outfit, cut to wrap across the torso and hang just below the hips. The pants and next top layer was made from dark brown quilter's cotton and cut the same way, only longer at the hem, to hang mid-thigh. The tabbards (I think that is what they are called) were made from lengths of the dark brown vinyl I got from my friend. I know the real Anakin costume actually had black leather tabbards but I was using what I could get my hands on without going into the poor house! Jim being as tall as he is, had me a little concerned if I could actually get the tabbards to hang nearly to his knees like Anakin's do. Turns out the 2 yards of vinyl I got were just about perfect. The vinyl was even used to make pseudo-boots for Jim to wear to the birthday party (which had a costume contest included, which we won, natch, since many other adults were too lame to wear much in the way of costumes... just teasing guys!), but he passed on those for Halloween night since we ran out of time to get dressed if we were going to let our monkeys actually do some trick-or-treating. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Finally, we have my Padme Amidala costume. This was a major task for me to accomplish and anyone with a bit of observational powers who has seen the movies, particularly Star Wars II: Attack of the Clones, more than a couple times will notice that I took several short cuts in order to actually have a prayer of completing this dress in time for Halloween and manage to keep some semblance of sanity in the process. It must have taken me over a month to decide upon which of the numerous gorgeous choices of dresses I would try to base my costume. Being in Minnesota ruled out several gowns as too impractical without lots of outer fall/winter wear to keep me from getting hypothermic. Others were a little too elaborate for me to wish to undertake with such a short timeline, both in dress and hair. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;After consulting several friends and family members, I settled on the grey and black dress Padme wears while packing up to head home after the Chancellor told her to leave Coruscant for her own safety. The dress was fairly simple in construction with just a couple of slightly elaborate decorations that I figured I could avoid trying to out right copy and instead simplify for my own costume. The hair was still going to be a little difficult to duplicate but I had a couple of ideas for that too.  But first, the dress:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Sticking to my desire to keep the costs down, I chose to use mostly costume fabric, which I obtained when it was at least 1/2 price, and used one rather significant substitution. Again I used a pattern that I was able to alter a bit on my own to closely resemble Padme's actual gown. The skirt was made from a dark grey silk-essence type of material that looks like a rough silk shantung and lays very nicely over the under-skirt crinoline I made. The skirt of Padme's dress is actually pleated at the waist but I didn't have the time to dedicate to making the waist look that perfect so I simply gathered it around and sewed it to the bodice. The real Padme costume was apparently a 2-piece dress with an under-dress that had a simple tank-top attached to the slightly drop-waisted skirt with the black velvet bodice and silky sleeves as a separate overlay piece. I opted for a one-piece dress for simplicity's sake.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The sleeves were made using a light grey silky costume fabric. The material at the shoulders of the sleeves was gathered onto the bodice. In the original costume had a 2-part sleeve that was gathered around the upper part of the arm creating a full, puffy looking sleeve top. The lower part of the sleeve is gathered at the upper arm where the top part is gathered and is full down to just above the wrist where it gathers into form-fitting cuffs. I made my cuffs only 4 inches tall or so, a bit shorter than the real thing but easy for me to manage. Mine were also closed by snaps, not the half dozen covered buttons of the original. One major difference I had on my outfit, due partly to time constraints and partly to a shortage of the particular trim I chose to imitate the actual metal armbands of Padme's costume, was the presence of only 1 decorative band at the gathered upper arm of my sleeves. I chose to use a silver and black trim I found on clearance at the fabric store in place of what looks like beaded silver bracelet-type bands. Perhaps I will add on bands at a later date and fix the sleeves to be puffier in between the gathering and the shoulder.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;For the bodice I ended up using some black corduroy I have had for many years as velvet is pretty pricey. I did not end up turning the bodice into a corset-style top with boning and all the works (as the real thing is) due to time constraints so it wasn't as closely form fitting as I would have liked but it did look pretty nice with its princess seams and shape. I managed to free-form the collar to add onto the top of the bodice with rather impressive results, if I do say so myself. The front had a placket opening that I chose to put snap closures on for ease of creation and dressing. The decorated front overlay placket proved a bit of a challenge. In the real costume the placket is made from what looks like cut of brocade-type of material that is embroidered and beaded rather elaborately. Uh, yeah, not going to happen on my costume. My sister-in-law and I came up with the idea of using fabric paints to closely mimic the beading pattern. I cut a piece of the silver vinyl and a piece of the grey silky costume material I used for the sleeves and fabric glued them together to give it a somewhat firmer structure. After that, I simply laid out my cut piece and had a close-up picture of the actual placket next to it for reference. From that I was able to create a design that was similar with glittery blue fabric paint playing the part of the turquoise beads. I included silver, gold, and shimmery white fabric paint to complete the look of beaded loveliness.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8077223744586062132-5840228438445977824?l=winkmake.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winkmake.blogspot.com/feeds/5840228438445977824/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://winkmake.blogspot.com/2009/11/skywalker-family.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8077223744586062132/posts/default/5840228438445977824'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8077223744586062132/posts/default/5840228438445977824'/><link rel='alternate' type='text/html' href='http://winkmake.blogspot.com/2009/11/skywalker-family.html' title='The Skywalker Family'/><author><name>Jwink</name><uri>http://www.blogger.com/profile/07356738572886578752</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://1.bp.blogspot.com/_LHP9sz9ANuQ/SWrQ95K1ecI/AAAAAAAAADw/Y3VUIKi1xy0/S220/DSCF4218_face.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_LHP9sz9ANuQ/Su3XRn_osTI/AAAAAAAAALQ/rYSClrr0BpA/s72-c/SkywalkerFamily.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8077223744586062132.post-6236896835582139567</id><published>2009-06-29T21:46:00.000-07:00</published><updated>2009-06-30T19:39:55.182-07:00</updated><title type='text'>RGB and XYZ</title><content type='html'>I think it's going on 14 years or more when I first had the idea: a lighted juggling ball that changes color as it rotates. Seriously - 14 years. I'm fairly sure of this because I told my girlfriend at the time (who eventually became my wife) and she made a prototype. But I get ahead of myself.&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;It was always LED's that did the lighting, of course. It was also a ball. This is important to note as juggling equipment comes in many shapes and sizes. It is lighted from within, hopefully evenly. As this ball (or many) rotates it changes color. Hopefully it is bright enough to be seen from a far in a dark theater and it's obvious that the color is changing. It's not crucial that the juggler be able to control the changes, but that might be a nice option.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_LHP9sz9ANuQ/SkqwVrfq47I/AAAAAAAAAKA/eUqJ7yeWNaY/s1600-h/DSCF5739_cropped.jpg"&gt;&lt;img style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;width: 320px; height: 236px;" src="http://1.bp.blogspot.com/_LHP9sz9ANuQ/SkqwVrfq47I/AAAAAAAAAKA/eUqJ7yeWNaY/s320/DSCF5739_cropped.jpg" border="0" alt="" id="BLOGGER_PHOTO_ID_5353284993582556082" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;When I told Jeanette (afore mentioned wife) she made a prototype for a class she was taking in college. It was just after we had started dating - I think during her Junior year. Second half she says, and it was for a physics class. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;What she created involved two mercury switches and three LEDs. The LEDs were two color - red and green, though they did a passable yellow as well. It worked fairly well as a test, but wasn't anything we could use in a juggling ball. Mercury switches would be too dangerous as they would most likely break.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;As I didn't have any other ideas for a switching mechanism, I shelved the idea focusing instead on other matters such as getting married, buying a house, having kids - the usual stuff. But the idea stuck around and when I started getting into the Arduino last year it was the first thing I thought of building. After many other tests and trials of ideas I decided to take another crack at it.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;By this point I'd had lots of experience with the accelerometer (see previous posts). It's functionality is rather simple. It expresses the position of each axis as strength of voltage. The highest voltage meant the position was at one side of the axis. No or low voltage meant the position was at the other side of the axis. The Arduino is capable of measuring the voltages with analog pins and can distinguish something like 693 different positions. Using the combination of all three axis you can determine which way is down - one axis, or a couple will always be pulled by gravity - except when in free-fall, which could be another position of sorts.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_LHP9sz9ANuQ/Skq0JuKH6XI/AAAAAAAAAKI/a3Fmxl8U0qU/s1600-h/DSCF4920_cropped.jpg" style="text-decoration: none;"&gt;&lt;img style="float:right; margin:0 0 10px 10px;cursor:pointer; cursor:hand;width: 320px; height: 280px;" src="http://2.bp.blogspot.com/_LHP9sz9ANuQ/Skq0JuKH6XI/AAAAAAAAAKI/a3Fmxl8U0qU/s320/DSCF4920_cropped.jpg" border="0" alt="" id="BLOGGER_PHOTO_ID_5353289186185570674" /&gt;&lt;/a&gt;The first thing I tried - even though I knew it wouldn't work - was to just let the accelerometer drive the LEDs. The RBG LED's I had worked at an operating voltage of near what the maximum output the accelerometer would produce: 3.3 volts.&lt;br /&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;This was fairly simple to set up and get running. The Arduino was only there to provide power, in this case off of the 3.3 volt "always on" pin. I plugged the accelerometer into the protoboard, set the input and sleep with the 3.3 volt, ground to the ground and the sensitivity pins. The X, Y, and Z axis, in turn, provided the voltage directly to the LED. Oh, and the LED also has a ground.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_LHP9sz9ANuQ/Skq4Pt8QE1I/AAAAAAAAAKQ/6Cf32zJ5VkM/s1600-h/DSCF4921_cropped.jpg"&gt;&lt;img style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;width: 320px; height: 293px;" src="http://3.bp.blogspot.com/_LHP9sz9ANuQ/Skq4Pt8QE1I/AAAAAAAAAKQ/6Cf32zJ5VkM/s320/DSCF4921_cropped.jpg" border="0" alt="" id="BLOGGER_PHOTO_ID_5353293687253111634" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;All this might be easier to see with the accelerometer off to the side. I ran the lines from the three axis under the accelerometer. The two pins sticking up are just there to keep the board level.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I have no code to share for this set up, of course. Again - the Arduino is just providing power.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Running this way did work - sort of. The red, green and blue faded in and out nicely. When any given color tied to an axis was on high voltage it lit nicely. But when it was on low voltage it didn't light at all. What I want is something that shows a color regardless of how the thing is turned. Preferrably there's a way I can tie half of each axis to a color. The RGB LED does a nice job of showing mixes. Sure, the dominant colors are red green and blue, but mix 'em and you also get yellow (sort of), purple (very nice), and aqua (also pretty good). Mix all three and it's a fairly good white.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Next I tried working out some fairly complicated math to assign various positions of the axis to certain colors. These, in turn, were used to set PWM values for the LEDs. The PWM maxes out to something close to 3.3 v for green and blue and 2.0 v for read. But based on the positions of the axis, the strength of the lighting was altered.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_LHP9sz9ANuQ/SkrEMUm9fVI/AAAAAAAAAKY/vJ8dBAbHJP8/s1600-h/DSCF5712_cropped.jpg"&gt;&lt;img style="float:right; margin:0 0 10px 10px;cursor:pointer; cursor:hand;width: 320px; height: 251px;" src="http://3.bp.blogspot.com/_LHP9sz9ANuQ/SkrEMUm9fVI/AAAAAAAAAKY/vJ8dBAbHJP8/s320/DSCF5712_cropped.jpg" border="0" alt="" id="BLOGGER_PHOTO_ID_5353306823052852562" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;This didn't work out very well. To do this I had picked a point between zero and full and treated that as half point. Doing this with each axis gives six "limbs" as it were. Given a position somewhere in or between these six I figured I could use this as a means of lighting or fading between colors. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I won't go into too many details as my failed attempts at this math are something of a private shame. Some of this still shows up - commented out - in the code I share below. I still think my goal of having all 6 colors show is possible - even with some nice fading and maybe having white as the "free fall" color.  But I think I need to come up with something different. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;What I did come up that works somewhat was to assign a color to each of the eight quadrants. If you bisect the three axis the same way you can think of a three dimensional cross with six points coming out of the middle. If you set the cross inside a cube, it actually looks like eight cubes stacked together - four cubes, two by two on two levels. Reading the accelerometer values I can "decide" that the position is in one of these eight sections and then light the appropriate color. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The problem is I really only have 7 colors: red, yellow, green, aqua, blue, purple, white. So I assinged "off" to the eighth. Here's another video:&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;object width="425" height="344"&gt;&lt;param name="movie" value="http://www.youtube.com/v/oDdWik-U8Vs&amp;amp;hl=en&amp;amp;fs=1&amp;amp;"&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;param name="allowscriptaccess" value="always"&gt;&lt;embed src="http://www.youtube.com/v/oDdWik-U8Vs&amp;amp;hl=en&amp;amp;fs=1&amp;amp;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;This video has got some interesting interferance lines, doesn't it? That's probably the PWM singing in tune with the camera I was using. Might be fun to play with later - but I digress.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;If I ever figure out some code that works with just six colors - and free-fall white - I might look into another Arduino board. I was thinking of an &lt;a href="http://www.sparkfun.com/commerce/product_info.php?products_id=9220"&gt;Arduino Pro Mini&lt;/a&gt; from Sparkfun. Its tiny, its output voltage is already 3.3 volts, and it's fairly cheap. All surface mount to boot, though I think I've gotta solder on my own connectors. I'd probably have to work out a way to connect the accelerometer directly to the thing and somehow tack on some power. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I'd most likely want to figure out a way to connect the LED's somewhat loosely to the board. Maybe connected via a loose wire. There'd probably be eight of these arranged also in quadrants. I'd probably put the bundle into a clear plastic ball and suspend it in that ball in some clear plastic beads that'd (hopefully) diffuse the light of the LED's a bit.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Its all ideas until I actually do it, which at this rate will be next year. Too many distractions...&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Anyway, here's the code:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;pre style="margin: 0px; padding: 6px; border: 1px inset; width: 100%; height: 150px; text-align: left; font-family: Courier New, monospace; overflow: auto"&gt;&lt;br /&gt;/*&lt;br /&gt;* XYZ (accelerometer) and RGB (LED)&lt;br /&gt;* Fading between colors controlled by accelerometer&lt;br /&gt;* PWM: 3, 5, 6, 9, 10, 11&lt;br /&gt;* USE: 9, 10, 11&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;// axis analog pins&lt;br /&gt;int xPin = 0;&lt;br /&gt;int yPin = 1;&lt;br /&gt;int zPin = 2;&lt;br /&gt;&lt;br /&gt;// mid value of any axis&lt;br /&gt;int max = 693;&lt;br /&gt;int mid = 346;&lt;br /&gt;&lt;br /&gt;// pins controlling red/green/blue&lt;br /&gt;int rPin = 9;&lt;br /&gt;int gPin = 10;&lt;br /&gt;int bPin = 11;&lt;br /&gt;&lt;br /&gt;// maximum PWM we want for each&lt;br /&gt;int rMax = 102;&lt;br /&gt;int gMax = 163;&lt;br /&gt;int bMax = 163;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/*&lt;br /&gt;* The run-once setup method&lt;br /&gt;*/&lt;br /&gt;void setup()&lt;br /&gt;{&lt;br /&gt;// set up to communicate with serial&lt;br /&gt;Serial.begin(9600);&lt;br /&gt;&lt;br /&gt;// set axis/analog pins to input&lt;br /&gt;pinMode(xPin, INPUT);&lt;br /&gt;pinMode(yPin, INPUT);&lt;br /&gt;pinMode(zPin, INPUT);&lt;br /&gt;&lt;br /&gt;// set LED pins to output - not&lt;br /&gt;// really necessary for PWM, tho&lt;br /&gt;pinMode(rPin, OUTPUT);&lt;br /&gt;pinMode(gPin, OUTPUT);&lt;br /&gt;pinMode(bPin, OUTPUT);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/*&lt;br /&gt;* Main loop - shift lights with accelerometer values&lt;br /&gt;*/&lt;br /&gt;void loop()&lt;br /&gt;{&lt;br /&gt;// fetch value from various analog&lt;br /&gt;int xVal = analogRead(xPin);&lt;br /&gt;int yVal = analogRead(yPin);&lt;br /&gt;int zVal = analogRead(zPin);&lt;br /&gt;&lt;br /&gt;// determine which zone that is&lt;br /&gt;int zone = findZone(xVal, yVal, zVal);&lt;br /&gt;&lt;br /&gt;// tell us which zone&lt;br /&gt;Serial.print("Zone: ");&lt;br /&gt;Serial.println(zone, DEC);&lt;br /&gt;&lt;br /&gt;/*&lt;br /&gt;// calculate how "on" each LED should be&lt;br /&gt;float rPer = redCalc(zone, xVal, yVal, zVal);&lt;br /&gt;float gPer = grnCalc(zone, xVal, yVal, zVal);&lt;br /&gt;float bPer = bluCalc(zone, xVal, yVal, zVal);&lt;br /&gt;// light 'em&lt;br /&gt;lightLed(rPer, gPer, bPer, 0);&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;switch(zone)&lt;br /&gt;{&lt;br /&gt; case 1:&lt;br /&gt;   lightLed(1.0, 1.0, 1.0, 0);&lt;br /&gt;   break;&lt;br /&gt; case 2:&lt;br /&gt;   lightLed(1.0, 0.0, 0.0, 0);&lt;br /&gt;   break;&lt;br /&gt; case 3:&lt;br /&gt;   lightLed(1.0, 1.0, 0.0, 0);&lt;br /&gt;   break;&lt;br /&gt; case 4:&lt;br /&gt;   lightLed(0.0, 1.0, 1.0, 0);&lt;br /&gt;   break;&lt;br /&gt; case 5:&lt;br /&gt;   lightLed(1.0, 0.0, 1.0, 0);&lt;br /&gt;   break;&lt;br /&gt; case 6:&lt;br /&gt;   lightLed(0.0, 0.0, 1.0, 0);&lt;br /&gt;   break;&lt;br /&gt; case 7:&lt;br /&gt;   lightLed(0.0, 1.0, 0.0, 0);&lt;br /&gt;   break;   &lt;br /&gt; default:&lt;br /&gt;   lightLed(0.0, 0.0, 0.0, 0);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/*&lt;br /&gt;* Based on the values of the 3 axis&lt;br /&gt;* determines which of 8 zones we are in&lt;br /&gt;*/&lt;br /&gt;int findZone(int x, int y, int z)&lt;br /&gt;{&lt;br /&gt;int zone = 0;&lt;br /&gt;&lt;br /&gt;if (x &gt; mid &amp;amp;&amp;amp; y &gt; mid &amp;amp;&amp;amp; z &gt; mid) { zone = 1; }&lt;br /&gt;else if (x &lt;= mid &amp;amp;&amp;amp; y &gt; mid &amp;amp;&amp;amp; z &gt; mid) { zone = 2; }&lt;br /&gt;else if (x &lt;= mid &amp;amp;&amp;amp; y &lt;= mid &amp;amp;&amp;amp; z &gt; mid) { zone = 3; }&lt;br /&gt;else if (x &gt; mid &amp;amp;&amp;amp; y &lt;= mid &amp;amp;&amp;amp; z &gt; mid) { zone = 4; }&lt;br /&gt;else if (x &gt; mid &amp;amp;&amp;amp; y &gt; mid &amp;amp;&amp;amp; z &lt;= mid) { zone = 5; }   else if (x &lt;= mid &amp;amp;&amp;amp; y &gt; mid &amp;amp;&amp;amp; z &lt;= mid) { zone = 6; }   else if (x &lt;= mid &amp;amp;&amp;amp; y &lt;= mid &amp;amp;&amp;amp; z &lt;= mid) { zone = 7; }   else if (x &gt; mid &amp;amp;&amp;amp; y &lt;= mid &amp;amp;&amp;amp; z &lt;= mid) { zone = 8; }    return zone;   }   /*  * Calculate how "on" red LED is  */ float redCalc(int zone, int x, int y, int z) {   float per = 0.0;      switch (zone)   {     case 1:       per = 1.0;       break;     case 2:       per = z - mid / mid;       break;     case 3:       per = z - mid / mid;       break;     case 4:       per = ((z + x) / 2) / mid;       break;     case 5:       per = ((x + y) / 2) / mid;       break;     case 6:       per = y / mid;       break;     case 7:       per = 0.0;       break;     case 8:       per = x - mid / mid;       break;   }      return per; }   /*  * Calculate how "on" green LED is  */ float grnCalc(int zone, int x, int y, int z) {   float per = 0.0;      switch (zone)   {     case 1:       per = y - mid / mid;       break;     case 2:       per = ((y + x) / 2) / mid;       break;     case 3:       per = x - mid / mid;       break;     case 4:       per = 0.0;       break;     case 5:       per = ((z + y) / 2) / mid;       break;     case 6:       per = 1.0;       break;     case 7:       per = ((x + z) / 2) / mid;       break;     case 8:       per = z / mid;       break;   }      return per; }   /*  * Calculate how "on" blue LED is  */ float bluCalc(int zone, int x, int y, int z) {   float per = 0.0;      switch (zone)   {     case 1:       per = z - mid / mid;       break;     case 2:       per = ((z + x) / 2) / mid;       break;     case 3:       per = 1.0;       break;     case 4:       per = ((y + z) / 2) / mid;       break;     case 5:       per = 0.0;       break;     case 6:       per = x / mid;       break;     case 7:       per = ((y + x) / 2) / mid;       break;     case 8:       per = y / mid;       break;   }     return per; }   /*  * Light the LEDs based on the percentages  */ void lightLed(float rPer, float gPer, float bPer, int wait) {   // caclulate percentages lit   int rVal = rMax * rPer;    int gVal = gMax * gPer;    int bVal = bMax * bPer;       // light the LEDs to these percents   analogWrite(rPin, rVal);   analogWrite(gPin, gVal);   analogWrite(bPin, bVal);      // if given a delay   if (wait &gt; 0)&lt;br /&gt;{&lt;br /&gt; // delay for a given milliseconds&lt;br /&gt; delay(wait);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8077223744586062132-6236896835582139567?l=winkmake.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winkmake.blogspot.com/feeds/6236896835582139567/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://winkmake.blogspot.com/2009/06/rgb-and-xyz.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8077223744586062132/posts/default/6236896835582139567'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8077223744586062132/posts/default/6236896835582139567'/><link rel='alternate' type='text/html' href='http://winkmake.blogspot.com/2009/06/rgb-and-xyz.html' title='RGB and XYZ'/><author><name>Jwink</name><uri>http://www.blogger.com/profile/07356738572886578752</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://1.bp.blogspot.com/_LHP9sz9ANuQ/SWrQ95K1ecI/AAAAAAAAADw/Y3VUIKi1xy0/S220/DSCF4218_face.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_LHP9sz9ANuQ/SkqwVrfq47I/AAAAAAAAAKA/eUqJ7yeWNaY/s72-c/DSCF5739_cropped.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8077223744586062132.post-6863251486481594359</id><published>2009-05-30T20:36:00.000-07:00</published><updated>2009-05-30T21:26:48.910-07:00</updated><title type='text'>RGB LED</title><content type='html'>&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_LHP9sz9ANuQ/SiIDPgoTeJI/AAAAAAAAAIY/mc1Ks2zIDQU/s1600-h/DSCF4923.JPG"&gt;&lt;img style="float:right; margin:0 0 10px 10px;cursor:pointer; cursor:hand;width: 200px; height: 150px;" src="http://2.bp.blogspot.com/_LHP9sz9ANuQ/SiIDPgoTeJI/AAAAAAAAAIY/mc1Ks2zIDQU/s200/DSCF4923.JPG" border="0" alt="" id="BLOGGER_PHOTO_ID_5341835673006733458" /&gt;&lt;/a&gt;&lt;br /&gt;Yet another bit of fun that came with my last order to SparkFun were 10 (?) RGB LEDs. These are clear and have four leads coming off of them. They are - shortest to longest: blue, green, ground, and red. &lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The blue and green take 3.3v, the red takes 2v. Again, the Arduino gives us 5v on most of it's digital pins. There is a 3.3v pin, but I think that's always on. But the Arduino also makes 6 of the pin capable of PWM or &lt;a href="http://arduino.cc/en/Tutorial/PWM"&gt;Pulse Width Modulation&lt;/a&gt;. This is the ability to pulse that 5v on and off at certain intervals and simulate different voltages. Click the link if you want to know more.&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Anyway, I set up the proto-shield using PWM and some 100 ohm resistors. While I still haven't bothered to actually calculate the proper resistance, I felt fairly certain I wasn't going to wreck the LED.  My first bit of code just flipped through the 8 different combinations of colors: off, red, green, blue, yellow (red/green), aqua (green/blue), purple (red/blue), and white (all 3). &lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;pre style="margin: 0px; padding: 6px; border: 1px inset; width: 100%; height: 150px; text-align: left; font-family: Courier New, monospace; overflow: auto"&gt;&lt;br /&gt;/*&lt;br /&gt;* RGB LED Test 1&lt;br /&gt;* Test lighting all in simple cycles.&lt;br /&gt;* PWM: 3, 5, 6, 9, 10, 11&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;// pins we'll use&lt;br /&gt;int redLed = 9;&lt;br /&gt;int grnLed = 10;&lt;br /&gt;int bluLed = 11;&lt;br /&gt;&lt;br /&gt;void setup()&lt;br /&gt;{&lt;br /&gt;pinMode(redLed, OUTPUT);&lt;br /&gt;pinMode(grnLed, OUTPUT);&lt;br /&gt;pinMode(bluLed, OUTPUT);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/*&lt;br /&gt;* Main loop - light in cycles&lt;br /&gt;*/&lt;br /&gt;void loop()&lt;br /&gt;{&lt;br /&gt;lightLed(false, false, false); // off&lt;br /&gt;lightLed(true,  false, false); // red&lt;br /&gt;lightLed(true,  true,  false); // yellow&lt;br /&gt;lightLed(false, true,  false); // green&lt;br /&gt;lightLed(false, true,  true);  // aqua&lt;br /&gt;lightLed(false, false, true);  // blue&lt;br /&gt;lightLed(true,  false, true);  // purple&lt;br /&gt;lightLed(true,  true,  true);  // white&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/*&lt;br /&gt;* Light the LEDs based on the booleans&lt;br /&gt;*/&lt;br /&gt;void lightLed(boolean redSet, boolean grnSet, boolean bluSet)&lt;br /&gt;{&lt;br /&gt;// default values to not set - no voltage&lt;br /&gt;int redVal = 0;&lt;br /&gt;int grnVal = 0;&lt;br /&gt;int bluVal = 0;&lt;br /&gt;&lt;br /&gt;// check booleans and set accordingly&lt;br /&gt;if (redSet) { redVal = 102; } // 2.0v, 20 mA&lt;br /&gt;if (grnSet) { grnVal = 163; } // 3.2v, 20 mA&lt;br /&gt;if (bluSet) { bluVal = 163; } // 3.2v, 20 mA&lt;br /&gt;&lt;br /&gt;// write what you set&lt;br /&gt;analogWrite(redLed, redVal);&lt;br /&gt;analogWrite(grnLed, grnVal);&lt;br /&gt;analogWrite(bluLed, bluVal);&lt;br /&gt;&lt;br /&gt;// delay for a half of a second using analog write&lt;br /&gt;delay(500);&lt;br /&gt;&lt;br /&gt;// this might cause problems being on the same timer&lt;br /&gt;// as PWM, but it's all we've got&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;This was a simple proof that showed I could get all three colors with some simple mixing. Pretty, but I figured with PWM there were many other colors I could get. So I played with fading the three colors in and out with each other. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;pre style="margin: 0px; padding: 6px; border: 1px inset; width: 100%; height: 150px; text-align: left; font-family: Courier New, monospace; overflow: auto"&gt;&lt;br /&gt;/*&lt;br /&gt;* RGB LED Test 5&lt;br /&gt;* Fading between colors&lt;br /&gt;* PWM: 3, 5, 6, 9, 10, 11&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;int redLed = 9;&lt;br /&gt;int grnLed = 10;&lt;br /&gt;int bluLed = 11;&lt;br /&gt;&lt;br /&gt;int redMax = 102;&lt;br /&gt;int grnMax = 163;&lt;br /&gt;int bluMax = 163;&lt;br /&gt;&lt;br /&gt;int pause = 50;&lt;br /&gt;float step = 0.10;&lt;br /&gt;&lt;br /&gt;void setup()&lt;br /&gt;{&lt;br /&gt;// set up to communication with serial&lt;br /&gt;Serial.begin(9600);&lt;br /&gt;&lt;br /&gt;pinMode(redLed, OUTPUT);&lt;br /&gt;pinMode(grnLed, OUTPUT);&lt;br /&gt;pinMode(bluLed, OUTPUT);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/*&lt;br /&gt;* Main loop - light in cycles&lt;br /&gt;*/&lt;br /&gt;void loop()&lt;br /&gt;{&lt;br /&gt;float red, grn, blu;&lt;br /&gt;&lt;br /&gt;// red on, green up, blue off&lt;br /&gt;red = 1; grn = 0; blu = 0;&lt;br /&gt;while (grn &lt;= 1)   {     lightLed(red, grn, blu, pause);     grn += step;     showPercents(1, red, grn, blu);   }        // red down, green on, blue off     red = 1; grn = 1; blu = 0;   while (red &gt;= 0)&lt;br /&gt;{&lt;br /&gt;  lightLed(red, grn, blu, pause);&lt;br /&gt;  red -= step;&lt;br /&gt;  showPercents(2, red, grn, blu);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;// red off, green on, blue up&lt;br /&gt;red = 0; grn = 1; blu = 0;&lt;br /&gt;while (blu &lt;= 1)   {     lightLed(red, grn, blu, pause);     blu += step;     showPercents(3, red, grn, blu);   }    // red off, green down, blue on     red = 0; grn = 1; blu = 1;   while (grn &gt;= 0)&lt;br /&gt;{&lt;br /&gt;  lightLed(red, grn, blu, pause);&lt;br /&gt;  grn -= step;&lt;br /&gt;  showPercents(4, red, grn, blu);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;// red up, green off, blue on&lt;br /&gt;red = 0; grn = 0; blu = 1;&lt;br /&gt;while (red &lt;= 1)   {     lightLed(red, grn, blu, pause);     red += step;     showPercents(5, red, grn, blu);   }    // red on, green off, blue down     red = 1; grn = 0; blu = 1;   while (blu &gt;= 0)&lt;br /&gt;{&lt;br /&gt;  lightLed(red, grn, blu, pause);&lt;br /&gt;  blu -= step;&lt;br /&gt;  showPercents(6, red, grn, blu);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/*&lt;br /&gt;* Light the LEDs based on the percentages&lt;br /&gt;*/&lt;br /&gt;void lightLed(float redPer, float grnPer, float bluPer, int wait)&lt;br /&gt;{&lt;br /&gt;// default values to not set - no voltage&lt;br /&gt;int redVal = redMax * redPer;&lt;br /&gt;int grnVal = grnMax * grnPer;&lt;br /&gt;int bluVal = bluMax * bluPer;&lt;br /&gt;&lt;br /&gt;// write what you set&lt;br /&gt;analogWrite(redLed, redVal);&lt;br /&gt;analogWrite(grnLed, grnVal);&lt;br /&gt;analogWrite(bluLed, bluVal);&lt;br /&gt;&lt;br /&gt;// delay for a given milliseconds&lt;br /&gt;delay(wait);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void showPercents(int state, float redPer, float grnPer, float bluPer)&lt;br /&gt;{&lt;br /&gt;Serial.print("State: ");&lt;br /&gt;Serial.print(state, DEC);&lt;br /&gt;&lt;br /&gt;Serial.print(", red: ");&lt;br /&gt;Serial.print(redPer*10, DEC);&lt;br /&gt;&lt;br /&gt;Serial.print(", grn: ");&lt;br /&gt;Serial.print(grnPer*10, DEC);&lt;br /&gt;&lt;br /&gt;Serial.print(", blu: ");&lt;br /&gt;Serial.print(bluPer*10, DEC);&lt;br /&gt;&lt;br /&gt;Serial.println(".");&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;This was a bit more satisfying to watch. So I decided to make another video of it:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;object width="425" height="344"&gt;&lt;param name="movie" value="http://www.youtube.com/v/bx-uOBlDzLU&amp;amp;hl=en&amp;amp;fs=1"&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;param name="allowscriptaccess" value="always"&gt;&lt;embed src="http://www.youtube.com/v/bx-uOBlDzLU&amp;amp;hl=en&amp;amp;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I had, of course, decided not long after doing this that I should hook in the accelerometer (I can't leave that thing alone, can I?).&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;But I'll leave that for another post.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8077223744586062132-6863251486481594359?l=winkmake.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winkmake.blogspot.com/feeds/6863251486481594359/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://winkmake.blogspot.com/2009/05/rgb-led.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8077223744586062132/posts/default/6863251486481594359'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8077223744586062132/posts/default/6863251486481594359'/><link rel='alternate' type='text/html' href='http://winkmake.blogspot.com/2009/05/rgb-led.html' title='RGB LED'/><author><name>Jwink</name><uri>http://www.blogger.com/profile/07356738572886578752</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://1.bp.blogspot.com/_LHP9sz9ANuQ/SWrQ95K1ecI/AAAAAAAAADw/Y3VUIKi1xy0/S220/DSCF4218_face.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_LHP9sz9ANuQ/SiIDPgoTeJI/AAAAAAAAAIY/mc1Ks2zIDQU/s72-c/DSCF4923.JPG' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8077223744586062132.post-1560771757856433540</id><published>2009-04-05T15:22:00.001-07:00</published><updated>2009-04-05T16:28:18.370-07:00</updated><title type='text'>Back to the Accelerometer</title><content type='html'>&lt;div style="text-align: left;"&gt;As I mentioned in my previous post I was a bit worried that my accelerometer wasn't working properly. When hooked up along with an LED matrix there were some LEDs that just wouldn't light. It seemed like was the X-axis that was giving me trouble. &lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: center;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Since I'd "&lt;a href="http://www.sparkfun.com/commerce/static.php?name=return_policy"&gt;played with it&lt;/a&gt;" I couldn't return it to Sparkfun, in any case it was past the 14 day limit. This is kind of a bummer because it cost me about $20 - aside from the Arduino, one of the most expensive components in my inventory.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;So, I decided to create a way to test it. I figured it'd be cool to find out if there was actually a range of values that the X-axis wasn't producing. To do this would involve having the Arduino read the 3 axis and output the values through the serial port. I'd then have to write some software on the other side to read the values and display them in a way that made sense. &lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;img src="http://4.bp.blogspot.com/_LHP9sz9ANuQ/Sdkwdi9uxjI/AAAAAAAAAHY/cMotOzOVzt0/s320/AccelerometerOnly.jpg" style="float:right; margin:0 0 10px 10px;cursor:pointer; cursor:hand;width: 320px; height: 237px;" border="0" alt="" id="BLOGGER_PHOTO_ID_5321337718875014706" /&gt;&lt;/div&gt;&lt;div&gt;First I hooked everything up on the Arduino and &lt;/div&gt;&lt;div&gt;proto-sheild (see image). Then I proceeded to write a &lt;span class="Apple-style-span" style="font-style: italic; "&gt;very&lt;/span&gt; simple sketch to read the accelerometer and output what it reads through the serial port. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Since I'd already done some serial communication between the Arduino and a .NET 2.0 application, this wasn't all that hard. The sketch reads all three axis in the main loop an then immediately outputs those values through serial as decimal values separated by commas. Each value is sent via Serial.print with the final one sent with a Serial.print&lt;span class="Apple-style-span" style="font-style: italic;"&gt;ln. &lt;/span&gt;The println statement slaps on a '\n' to the final value separating it from the next set of values that are sent. The code for all this is as follows:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;pre style="margin: 0px; padding: 6px; border: 1px inset; width: 100%; height: 150px; text-align: left; font-family: Courier New, monospace; overflow: auto"&gt;&lt;br /&gt;/*&lt;br /&gt;* TripleAxisAccelerometer4.pde&lt;br /&gt;*&lt;br /&gt;* This test involves sending the analog values out through&lt;br /&gt;* the serial port. These values will be read by a .NET app&lt;br /&gt;* and displayed on a WinForm. The goal here is to determine&lt;br /&gt;* whether the x-axis is as messed up as I think it is.&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;// axis analog pins&lt;br /&gt;int xPin = 0;&lt;br /&gt;int yPin = 1;&lt;br /&gt;int zPin = 2;&lt;br /&gt;&lt;br /&gt;// values from those pins&lt;br /&gt;int xVal = 0;&lt;br /&gt;int yVal = 0;&lt;br /&gt;int zVal = 0;&lt;br /&gt;&lt;br /&gt;// other working variable schtuff&lt;br /&gt;int mid = 337;&lt;br /&gt;int set = 0;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/*&lt;br /&gt;* The "run once" setup method&lt;br /&gt;*/&lt;br /&gt;void setup()&lt;br /&gt;{&lt;br /&gt;// set up to communication with serial&lt;br /&gt;Serial.begin(9600);&lt;br /&gt;&lt;br /&gt;// set axis/analog pins to input&lt;br /&gt;pinMode(xPin, INPUT);&lt;br /&gt;pinMode(yPin, INPUT);&lt;br /&gt;pinMode(zPin, INPUT);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/*&lt;br /&gt;* Main processing method&lt;br /&gt;*/&lt;br /&gt;void loop()&lt;br /&gt;{&lt;br /&gt;// fetch value from various analog&lt;br /&gt;xVal = analogRead(xPin);&lt;br /&gt;yVal = analogRead(yPin);&lt;br /&gt;zVal = analogRead(zPin);&lt;br /&gt;&lt;br /&gt;// show us&lt;br /&gt;Serial.print(xVal, DEC);&lt;br /&gt;Serial.print(",");&lt;br /&gt;Serial.print(yVal, DEC);&lt;br /&gt;Serial.print(",");&lt;br /&gt;Serial.println(zVal, DEC);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div style="text-align: center;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The next part was to write a .NET app to read what the Arduino produces. This was a little harder. I'd sent info to the Arduino, but never read anything. The .NET framework provides some easy to use libraries and methods to do this, including one method that reads in an entire line from the com port. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Initially I just displayed the values to text boxes - just to prove that I could. Then I included high and low values, and then some progress bars. This was also useful in finding out something I didn't really know. The accelerometer actually produces values from 0 to 693. I found this by using the low and high trackers - these just take whatever value comes off of the Arduino for a given axis and compares to a value in memory. If the new value is lower or higher, it's kept&lt;/div&gt;&lt;div&gt;. After many replacements you see what the limit is. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;This all went swimmingly until I decided to try and paint the values to the screen using the .NET System.Drawing library. There are a lot of examples on the web showing how to paint lines or polygons, but annoyingly enough there weren't many that showed how to paint just a single pixel. I eventually found one and that's what's included in the example below in the "Draw" method. Also note: I've only included the code-behind of the main form. This contains most of what anyone would need to reproduce this since I'm assuming any .NET developer could easily infer the rest on a simple WinForm app.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;pre style="margin: 0px; padding: 6px; border: 1px inset; width: 100%; height: 150px; text-align: left; font-family: Courier New, monospace; overflow: auto"&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.Collections.Generic;&lt;br /&gt;using System.ComponentModel;&lt;br /&gt;using System.Configuration;&lt;br /&gt;using System.Data;&lt;br /&gt;using System.Drawing;&lt;br /&gt;using System.Drawing.Drawing2D;&lt;br /&gt;using System.Drawing.Imaging;&lt;br /&gt;using System.IO.Ports;&lt;br /&gt;using System.Text;&lt;br /&gt;using System.Windows.Forms;&lt;br /&gt;&lt;br /&gt;namespace AccelerometerTest&lt;br /&gt;{&lt;br /&gt;public partial class MainForm : Form&lt;br /&gt;{&lt;br /&gt; #region Members&lt;br /&gt;&lt;br /&gt; private SerialPort arduino = null;&lt;br /&gt;&lt;br /&gt; private int valX = 0, valY = 0, valZ = 0;&lt;br /&gt; private int lowX = 1023, lowY = 1023, lowZ = 1023;&lt;br /&gt; private int highX = 0, highY = 0, highZ = 0;&lt;br /&gt;&lt;br /&gt; private bool readSerial = false;&lt;br /&gt;&lt;br /&gt; KnownColor[] allColors = null;&lt;br /&gt;&lt;br /&gt; #endregion Members&lt;br /&gt;&lt;br /&gt; #region Constructor&lt;br /&gt;&lt;br /&gt; public MainForm()&lt;br /&gt; {&lt;br /&gt;     InitializeComponent();&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; #endregion Constructor&lt;br /&gt;&lt;br /&gt; #region Events&lt;br /&gt;&lt;br /&gt; /// &lt;summary&gt;&lt;br /&gt; /// Setup of main form - and Arduino communications&lt;br /&gt; /// &lt;/summary&gt;&lt;br /&gt; ///&lt;br /&gt; ///&lt;br /&gt; private void MainForm_Load(object sender, EventArgs e)&lt;br /&gt; {&lt;br /&gt;     // fetch port and rate&lt;br /&gt;     string comPort = ConfigurationManager.AppSettings["ComPort"];&lt;br /&gt;     int baudRate = int.Parse(ConfigurationManager.AppSettings["BaudRate"]);&lt;br /&gt;&lt;br /&gt;     // connect to the Arduino&lt;br /&gt;     arduino = new SerialPort(comPort, baudRate);&lt;br /&gt;     arduino.ReadTimeout = 3000;&lt;br /&gt;     arduino.WriteTimeout = 3000;&lt;br /&gt;     arduino.Open();&lt;br /&gt;&lt;br /&gt;     System.Array colorsArray = Enum.GetValues(typeof(KnownColor));&lt;br /&gt;     allColors = new KnownColor[colorsArray.Length];&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; protected override void OnPaint(PaintEventArgs e)&lt;br /&gt; {&lt;br /&gt;     base.OnPaint(e);&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; /// &lt;summary&gt;&lt;br /&gt; /// Shut down the app.&lt;br /&gt; /// &lt;/summary&gt;&lt;br /&gt; ///&lt;br /&gt; ///&lt;br /&gt; private void btnExit_Click(object sender, EventArgs e)&lt;br /&gt; {&lt;br /&gt;     Application.Exit();&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; /// &lt;summary&gt;&lt;br /&gt; /// Initiate - or stop - the process of reading the Arduino.&lt;br /&gt; /// &lt;/summary&gt;&lt;br /&gt; ///&lt;br /&gt; ///&lt;br /&gt; private void btnStart_Click(object sender, EventArgs e)&lt;br /&gt; {&lt;br /&gt;     if (btnStart.Text == "Start")&lt;br /&gt;     {&lt;br /&gt;         btnStart.Text = "Stop";&lt;br /&gt;         readSerial = true;&lt;br /&gt;         ClearForm();&lt;br /&gt;         ReadArduino();&lt;br /&gt;     }&lt;br /&gt;     else&lt;br /&gt;     {&lt;br /&gt;         btnStart.Text = "Start";&lt;br /&gt;         readSerial = false;&lt;br /&gt;     }&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; #endregion Events&lt;br /&gt;&lt;br /&gt; #region Supporting&lt;br /&gt;&lt;br /&gt; /// &lt;summary&gt;&lt;br /&gt; /// Does the work of fetching serial data from the Arduino&lt;br /&gt; /// and displaying it - in various ways - to the form.&lt;br /&gt; /// &lt;/summary&gt;&lt;br /&gt; private void ReadArduino()&lt;br /&gt; {&lt;br /&gt;     // working variables&lt;br /&gt;     char[] delim = { ',' };&lt;br /&gt;     string line = "";&lt;br /&gt;     string[] axis = null;&lt;br /&gt;     int tmpX = -1, tmpY = -1, tmpZ = -1;&lt;br /&gt;&lt;br /&gt;     // while flagged to read&lt;br /&gt;     while (readSerial)&lt;br /&gt;     {&lt;br /&gt;         // fetch one line of serial data from the Arduino&lt;br /&gt;         line = arduino.ReadLine();&lt;br /&gt;&lt;br /&gt;         // remove the return at the end of the line&lt;br /&gt;         if (line.LastIndexOf("\r") &gt; -1)&lt;br /&gt;         {&lt;br /&gt;             line = line.Substring(0, line.Length - 1);&lt;br /&gt;         }&lt;br /&gt;&lt;br /&gt;         // if there was nothing read, just skip this iteration&lt;br /&gt;         if (string.IsNullOrEmpty(line.Trim())) { continue; }&lt;br /&gt;&lt;br /&gt;         // implicit else - split the line to an array of strings&lt;br /&gt;         axis = line.Split(delim);&lt;br /&gt;&lt;br /&gt;         // if we got an array&lt;br /&gt;         if (axis != null &amp;amp;&amp;amp; axis.Length == 3)&lt;br /&gt;         {&lt;br /&gt;             // update the values if possible&lt;br /&gt;             if (!int.TryParse(axis[0], out tmpX)) { tmpX = -1; }&lt;br /&gt;             if (!int.TryParse(axis[1], out tmpY)) { tmpY = -1; }&lt;br /&gt;             if (!int.TryParse(axis[2], out tmpZ)) { tmpZ = -1; }&lt;br /&gt;&lt;br /&gt;             // update the form with these values&lt;br /&gt;             UpdateForm(tmpX, tmpY, tmpZ);&lt;br /&gt;         }&lt;br /&gt;&lt;br /&gt;         // pump the windows message loop&lt;br /&gt;         Application.DoEvents();&lt;br /&gt;     }&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; /// &lt;summary&gt;&lt;br /&gt; /// Clear everything we've painted&lt;br /&gt; /// &lt;/summary&gt;&lt;br /&gt; private void ClearForm()&lt;br /&gt; {&lt;br /&gt;     // reset buckets&lt;br /&gt;     valX = 0;&lt;br /&gt;     valY = 0;&lt;br /&gt;     valZ = 0;&lt;br /&gt;     lowX = 1023;&lt;br /&gt;     lowY = 1023;&lt;br /&gt;     lowZ = 1023;&lt;br /&gt;     highX = 0;&lt;br /&gt;     highY = 0;&lt;br /&gt;     highZ = 0;&lt;br /&gt;&lt;br /&gt;     // reset texts&lt;br /&gt;     txtXaxis.Text = valX + "";&lt;br /&gt;     txtYaxis.Text = valY + "";&lt;br /&gt;     txtZaxis.Text = valZ + "";&lt;br /&gt;&lt;br /&gt;     txtXlow.Text = lowX + "";&lt;br /&gt;     txtYlow.Text = lowY + "";&lt;br /&gt;     txtZlow.Text = lowZ + "";&lt;br /&gt;&lt;br /&gt;     txtXhigh.Text = highX + "";&lt;br /&gt;     txtYhigh.Text = highY + "";&lt;br /&gt;     txtZhigh.Text = highZ + "";&lt;br /&gt;&lt;br /&gt;     // reset progress bars&lt;br /&gt;     pgXaxis.Value = valX;&lt;br /&gt;     pgYaxis.Value = valY;&lt;br /&gt;     pgZaxis.Value = valZ;&lt;br /&gt;&lt;br /&gt;     // clear the image&lt;br /&gt;     RectangleF rectFToFill =&lt;br /&gt;         new RectangleF(0, 0, pbTrack.Width, pbTrack.Height);&lt;br /&gt;     SolidBrush brush = new SolidBrush(Color.White);&lt;br /&gt;     Graphics gfx = pbTrack.CreateGraphics();&lt;br /&gt;     gfx.FillRectangles(brush, new RectangleF[] { rectFToFill });&lt;br /&gt;     brush.Dispose();&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; /// &lt;summary&gt;&lt;br /&gt; /// Update bounds text&lt;br /&gt; /// &lt;/summary&gt;&lt;br /&gt; ///&lt;br /&gt; ///&lt;br /&gt; ///&lt;br /&gt; private void UpdateForm(int tmpX, int tmpY, int tmpZ)&lt;br /&gt; {&lt;br /&gt;     // check if our values changed or are even valid&lt;br /&gt;     valX = (tmpX &gt; -1 &amp;amp;&amp;amp; tmpX != valX) ? tmpX : valX;&lt;br /&gt;     valY = (tmpY &gt; -1 &amp;amp;&amp;amp; tmpY != valY) ? tmpY : valY;&lt;br /&gt;     valZ = (tmpZ &gt; -1 &amp;amp;&amp;amp; tmpZ != valZ) ? tmpZ : valZ;&lt;br /&gt;&lt;br /&gt;     Draw(valX, valY, valZ);&lt;br /&gt;&lt;br /&gt;     // update the core value text boxes&lt;br /&gt;     txtXaxis.Text = valX + "";&lt;br /&gt;     txtYaxis.Text = valY + "";&lt;br /&gt;     txtZaxis.Text = valZ + "";&lt;br /&gt;&lt;br /&gt;     // first update the progress bars&lt;br /&gt;     pgXaxis.Value = valX;&lt;br /&gt;     pgYaxis.Value = valY;&lt;br /&gt;     pgZaxis.Value = valZ;&lt;br /&gt;&lt;br /&gt;     // set lower bound values&lt;br /&gt;     lowX = (valX &lt; lowy =" (valY" lowz =" (valZ" text =" lowX" text =" lowY" text =" lowZ" highx =" (valX"&gt; highX) ? valX : highX;&lt;br /&gt;     highY = (valY &gt; highY) ? valY : highY;&lt;br /&gt;     highZ = (valZ &gt; highZ) ? valZ : highZ;&lt;br /&gt;&lt;br /&gt;     // set upper bound text&lt;br /&gt;     txtXhigh.Text = highX + "";&lt;br /&gt;     txtYhigh.Text = highY + "";&lt;br /&gt;     txtZhigh.Text = highZ + "";&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; /// &lt;summary&gt;&lt;br /&gt; /// Draws a single point&lt;br /&gt; /// &lt;/summary&gt;&lt;br /&gt; ///&lt;br /&gt; ///&lt;br /&gt; ///&lt;br /&gt; private void Draw(int xVal, int yVal, int zVal)&lt;br /&gt; {&lt;br /&gt;     int idx = (zVal * 174) / 693;&lt;br /&gt;     // Pen pen = new Pen(Color.Black, 1);&lt;br /&gt;     Pen pen = new Pen(Color.FromKnownColor(allColors[idx]), 1);&lt;br /&gt;     Graphics gfx = pbTrack.CreateGraphics();&lt;br /&gt;     Point[] points = { new Point(xVal, yVal) };&lt;br /&gt;&lt;br /&gt;     // Create a 1 x 1 bitmap and set the color&lt;br /&gt;     Bitmap pt = new Bitmap(1, 1);&lt;br /&gt;     pt.SetPixel(0, 0, Color.Black);&lt;br /&gt;&lt;br /&gt;     // Draw bitmap on Graphics surface&lt;br /&gt;     gfx.DrawImageUnscaled(pt, xVal, yVal);&lt;br /&gt;&lt;br /&gt;     //gfx.DrawPolygon(pen, points);&lt;br /&gt;     //gfx.DrawRectangle(pen, new Rectangle(points[0], new Size(1, 1)));&lt;br /&gt;     //gfx.DrawRectangle(pen, new Rectangle(xVal, yVal, 1, 1));&lt;br /&gt;     //formGraphics.DrawLine(myPen, xVal, yVal, xVal, yVal);&lt;br /&gt;&lt;br /&gt;     pen.Dispose();&lt;br /&gt;     gfx.Dispose();&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; #endregion Supporting&lt;br /&gt;&lt;br /&gt; #region Properties&lt;br /&gt;&lt;br /&gt; #endregion Properties&lt;br /&gt;}&lt;br /&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;div style="text-align: center;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;When the app is run and the painting starts its actually kind of interesting how it works. The dots are sort of sprayed all over the place as the accelerometer is moved. I'm not sure if this is just an artifact of how sensitive the accelerometer is or if it's due to noise coming in on the Arduino's analog ports. Either way it looks a bit like an airbrush. In this first go I stuck with painting black dots on a white canvas and only used the X and Y axis to do the painting. I'd like to eventually use the Z axis to drive color, but I'd have to decide how to assign the 0 to 693 or so values to colors somehow. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Doing this kind of "painting" again revealed something I didn't know. Handling the accelerometer without actually shaking it hard shows some median limits to how far it senses. Regular force, or 1 g, is about halfway through the range of values. That is if you tip it on its side so one axis is fully down - like X or Y - the value it displays is about halfway of middle. By tipping the Arduino/proto-shield fully on it side and then slowly rotating it the app paints a rough circle. It's kind of cool, actually. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;img src="http://2.bp.blogspot.com/_LHP9sz9ANuQ/Sdk7Y5cjWBI/AAAAAAAAAHg/7J8N8eel6AI/s320/AccelerometerTest.jpg" style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 300px; height: 320px;" border="0" alt="" id="BLOGGER_PHOTO_ID_5321349733638428690" /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;One bit of work still remains, though: to pinpoint whether there are any values on the X axis (or the others, for that mater) that don't show. Based on what I am seeing, I don't think so. I suspect my problem with the LED matrix not showing some values is due to bad coding in the sketch somewhere. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I have made a recent purchase from SparkFun that will result in more posts. Among the items I've purchase is an &lt;a href="https://www.sparkfun.com/commerce/product_info.php?products_id=759"&gt;LED matrix with a serial interface&lt;/a&gt;. This is the same LED matrix I already have, except the folks in Boulder have added a daughter board on the back that handles the job of lighting the LEDs based on signals sent serially. So I don't have to use up nearly as many pins on the Arduino to accomplish the same thing. In fact, with this I can certainly do more. But again, I'll leave that for a later post.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8077223744586062132-1560771757856433540?l=winkmake.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winkmake.blogspot.com/feeds/1560771757856433540/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://winkmake.blogspot.com/2009/04/back-to-accelerometer.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8077223744586062132/posts/default/1560771757856433540'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8077223744586062132/posts/default/1560771757856433540'/><link rel='alternate' type='text/html' href='http://winkmake.blogspot.com/2009/04/back-to-accelerometer.html' title='Back to the Accelerometer'/><author><name>Jwink</name><uri>http://www.blogger.com/profile/07356738572886578752</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://1.bp.blogspot.com/_LHP9sz9ANuQ/SWrQ95K1ecI/AAAAAAAAADw/Y3VUIKi1xy0/S220/DSCF4218_face.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_LHP9sz9ANuQ/Sdkwdi9uxjI/AAAAAAAAAHY/cMotOzOVzt0/s72-c/AccelerometerOnly.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8077223744586062132.post-8702382208202290889</id><published>2009-04-05T13:35:00.000-07:00</published><updated>2009-05-30T20:33:59.072-07:00</updated><title type='text'>LED Matrix and Accelerometer</title><content type='html'>One of the last items I decided to try out from my first order from SparkFun was a medium sized &lt;a href="https://www.sparkfun.com/commerce/product_info.php?products_id=682"&gt;LED matrix&lt;/a&gt;. This is an 8 by 8 (64) grid of LEDs that are multi-color. Send voltage through one set of pins and you get green, through another set and you get red - through both I think yellow.&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The &lt;a href="http://www.sparkfun.com/datasheets/Components/SanYoung-Medium-RG.pdf"&gt;specifications&lt;/a&gt; claim some pretty specific levels of voltage and current. The green wants 3.3 volts and 20 mA, the red wants 2.0 volts and 20 mA. The Arduino &lt;a href="http://arduino.cc/en/Main/ArduinoBoardDuemilanove"&gt;Duemilanova&lt;/a&gt; puts out 5v and 40 mA for the most part, though it has one 3.3v pin that produces 50 mA. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Of course, when I started playing with it I just through 5v and 40 mA through everything trying to see what it was capable of. For a while this seemed fine, but after a bit it some of the LEDs stopped lighting, or some light when not sent current. It still works, for the most part, with a few obvious gaps.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I did remember later that the Arduino can do &lt;a href="http://arduino.cc/en/Tutorial/PWM"&gt;Pulse Width Modulation&lt;/a&gt; (PWM) through &lt;span class="Apple-style-span" style="font-style: italic;"&gt;some&lt;/span&gt; of it's digital out pins: 3, 5, 6, 9, 10, and 11. With PWM you can simulate a lower voltage by pulsing the 5v on and off over and over at a certain rate.&lt;/div&gt;&lt;img src="http://3.bp.blogspot.com/_LHP9sz9ANuQ/SdkfgeFG19I/AAAAAAAAAHI/4xIxaBjncvU/s320/LEDMatrixPlusAccel.jpg" style="float:right; margin:0 0 10px 10px;cursor:pointer; cursor:hand;width: 309px; height: 320px;" border="0" alt="" id="BLOGGER_PHOTO_ID_5321319077405710290" /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The LED matrix has two lines of 12 pins on the back of it. Eight of these accept ground leaving two other sets of eight for green or red. Connecting one of eight grounds with one of eight of either the green or red will light a single LED. Using as many pins as I could connect, I came up with the setup shown in the image here.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I used all the PWM capable pins as well as a couple of non PWM capable pins a full voltage. All of the voltage generating pins, however had 500 ohm (at least I think) resistors on them, lowering the current by half. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;For this first effort I just stuck with green since it could accept a higher voltage anyway. My first sketch just cycled through lighting all the green LEDs one by one - well, at least those that were still working. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;pre style="margin: 0px; padding: 6px; border: 1px inset; width: 100%; height: 150px; text-align: left; font-family: Courier New, monospace; overflow: auto"&gt;&lt;br /&gt;/*&lt;br /&gt;* Matrix Test 1&lt;br /&gt;* PWM: 3, 5, 6, 9, 10, 11&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;int grnds[] = { 4, 2, 1, 0, 13, 12,  8,  7 };&lt;br /&gt;int apins[] = { 3, 5, 6, 9, 10, 11, 18, 19 };&lt;br /&gt;&lt;br /&gt;void setup()&lt;br /&gt;{&lt;br /&gt;for (int i = 0; i &lt; i =" 0;" j =" 0;"&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;To get a single LED to light, that is to have one pin produce voltage and another become ground  - while the remaining pins do nothing - was a bit tricky. The groun pin must be set to output and low while the voltage pin has to be set to output and either output also (5v) or analog write 170 (about 3.3v). To turn that set off requires turning both ground and voltage to input. This at least proved to me that I could light each LED individually even if some - 3, actually - were broke.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;To me, the next logical step was to add the accelerometer to the test jig (also pictured above) and use it to direct the lighting of the individual LEDs. This proved to be a bit more difficult. The Accelerometer accepts 3.3v and outputs that much or less on 3 pins, one each for X, Y, or Z axis. The analog pins on the Arduino expect 5v and read to a granularity of 0 to 1023. With 3.3v the full range becomes more like 0 to 675 (though I found out later this was wrong - its more like 695). The LED matrix has 8 LEDs by 8, so I had to do some weird calculation to map 0 to 675 to 0 to 8. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;pre style="margin: 0px; padding: 6px; border: 1px inset; width: 100%; height: 150px; text-align: left; font-family: Courier New, monospace; overflow: auto"&gt;&lt;br /&gt;&lt;br /&gt;/*&lt;br /&gt;* LED Matrix plus Accelometer&lt;br /&gt;*&lt;br /&gt;* PWM: 3, 5, 6, 9, 10, 11&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;// pins on the matrix connected to ground&lt;br /&gt;int grnds[] = { 4, 2, 1, 0, 13, 12,  8,  7 };&lt;br /&gt;&lt;br /&gt;// pins on the matrix connected to voltage&lt;br /&gt;//int apins[] = { 3, 5, 6, 9, 10, 11, 18, 19 };&lt;br /&gt;int apins[] = { 19, 18, 11, 10, 9, 6, 5, 3 };&lt;br /&gt;&lt;br /&gt;// axis analog pins&lt;br /&gt;int xPin = 0;&lt;br /&gt;int yPin = 1;&lt;br /&gt;int zPin = 2;&lt;br /&gt;&lt;br /&gt;// calculations&lt;br /&gt;float maxValue = 506.385;&lt;br /&gt;float minValue = 168.795;&lt;br /&gt;float fulRange = 337.59;&lt;br /&gt;float divValue = (float)fulRange / 8.0;&lt;br /&gt;&lt;br /&gt;// other working variable schtuff&lt;br /&gt;int lstGrnd = 0;&lt;br /&gt;int lstApin = 0;&lt;br /&gt;int set = 0;&lt;br /&gt;&lt;br /&gt;/*&lt;br /&gt;* Run-once setup method&lt;br /&gt;*/&lt;br /&gt;void setup()&lt;br /&gt;{&lt;br /&gt;// set up to communication with serial&lt;br /&gt;Serial.begin(9600);&lt;br /&gt;&lt;br /&gt;// set axis/analog pins to input&lt;br /&gt;pinMode(xPin, INPUT);&lt;br /&gt;pinMode(yPin, INPUT);&lt;br /&gt;pinMode(zPin, INPUT);&lt;br /&gt;&lt;br /&gt;//showCalcs();&lt;br /&gt;&lt;br /&gt;// set up ground and voltage pins&lt;br /&gt;for (int i = 0; i &lt; set ="=" set =" 1;" xval =" analogRead(xPin);" yval =" analogRead(yPin);" gc =" calcIdx(xVal);" ac =" calcIdx(yVal);" idx =" (((aVal" idx =" 0;"&gt; 7) { idx = 7; }&lt;br /&gt;&lt;br /&gt;return idx;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;void ledOnOff(int grnd, int apin)&lt;br /&gt;{&lt;br /&gt;if (grnd != lstGrnd || apin != lstApin)&lt;br /&gt;{&lt;br /&gt;ledOff(lstGrnd, lstApin);&lt;br /&gt;ledOn(grnd, apin);&lt;br /&gt;lstGrnd = grnd;&lt;br /&gt;lstApin = apin;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/*&lt;br /&gt;ledOn(grnd, apin);&lt;br /&gt;ledOff(grnd, apin);&lt;br /&gt;*/&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void ledOn(int grnd, int apin)&lt;br /&gt;{&lt;br /&gt;pinMode(grnd, OUTPUT);&lt;br /&gt;digitalWrite(grnd, LOW);&lt;br /&gt;pinMode(apin, OUTPUT);&lt;br /&gt;&lt;br /&gt;if (apin == 3 || apin == 5 || apin == 6 ||&lt;br /&gt;apin == 9 || apin == 10 || apin == 11)&lt;br /&gt;{&lt;br /&gt;analogWrite(apin, 170);&lt;br /&gt;}&lt;br /&gt;else&lt;br /&gt;{&lt;br /&gt;digitalWrite(apin, HIGH);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void ledOff(int grnd, int apin)&lt;br /&gt;{&lt;br /&gt;pinMode(grnd, INPUT);&lt;br /&gt;pinMode(apin, INPUT);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;This did not work as I expected. More than one LED lit at once and there seemed to be a gap in the values produced by the X axis, which translated into a row or two of LEDs that wouldn't light. At first I suspected my math was wrong, but now I am wondering whether there is a problem with the accelerometer. It's almost as if it has a gap in the values it is able to produce. I will have a later post describing how I tested that, though.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Here's a video on YouTube of it running:&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;object width="425" height="344"&gt;&lt;param name="movie" value="http://www.youtube.com/v/IPj1x6IMomo&amp;amp;hl=en&amp;amp;fs=1"&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;param name="allowscriptaccess" value="always"&gt;&lt;embed src="http://www.youtube.com/v/IPj1x6IMomo&amp;amp;hl=en&amp;amp;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;Finally, before I disassembled this test jig I wanted to code a simple animation. I went with a box, lighting the outer sqare of LEDs, then the next inner, and so forth. Here's another video of it doing that bit:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;object width="425" height="344"&gt;&lt;param name="movie" value="http://www.youtube.com/v/lixDrv5bbPQ&amp;amp;hl=en&amp;amp;fs=1"&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;param name="allowscriptaccess" value="always"&gt;&lt;embed src="http://www.youtube.com/v/lixDrv5bbPQ&amp;amp;hl=en&amp;amp;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The code for that is listed at the end of this post. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Before I finish entirely, though, I will make note of one thing. This is what I'd call my first mistake with monetary consequences. Though the matrix isn't completely ruined, it's certainly not working completely. These LED matrixes aren't all that expensive. They run about $7 on SparkFun, but it is a bummer to have wrecked it. So far my experimentation with the Arduino has been fairly innocuous. I guess the lesson here is to read the specs and stick to the voltage/current as best you can.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;There is also one other thing I wanted to add. I made some videos of this project as well - which you can see I've added. My camera - a Fuji FinePix F50SE - can record movies at 640x480 / 30 fps for as long as I've got space on the memory card. They're pretty nice, but also in AVI or non-compressed format. I tried finding a way to convert these into MPEGs, but so far have not found any free software to do this. Googling for something of this sort almost always comes up with for pay, or trial then for pay software. I &lt;span class="Apple-style-span" style="font-style: italic;"&gt;know&lt;/span&gt; there's gotta be some nice freeware / open-source software out there somewhere, but I am at a loss to find it. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Anyway, not long after I wrote this post I had a conversation with some friends at work. Their response was - don't try and figure it out - let YouTube do it. It will take various formats and store these off in it's own way and then give you a link to play it. Plus you are not really worried about storage once you put things there (not sure about this). So I did this and here they are. Cool.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Anyway, here's that last bit of code:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;pre style="margin: 0px; padding: 6px; border: 1px inset; width: 100%; height: 150px; text-align: left; font-family: Courier New, monospace; overflow: auto"&gt;&lt;br /&gt;/*&lt;br /&gt;* Matrix Test 2&lt;br /&gt;*&lt;br /&gt;* Light squares&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;int grnds[] = { 4, 2, 1, 0, 13, 12,  8,  7 };&lt;br /&gt;int apins[] = { 3, 5, 6, 9, 10, 11, 18, 19 };&lt;br /&gt;int loops = 0;&lt;br /&gt;bool dir = true;&lt;br /&gt;&lt;br /&gt;void setup()&lt;br /&gt;{&lt;br /&gt;for (int i = 0; i &lt; dir =" true;"&gt; 100 &amp;amp;&amp;amp; loops &lt;&gt; 500 &amp;amp;&amp;amp; loops &lt;&gt; 700 &amp;amp;&amp;amp; loops &lt;&gt; 900) { dir = false; }&lt;br /&gt;&lt;br /&gt;if (dir) { loops++; }&lt;br /&gt;else { loops--; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void box(int low, int high)&lt;br /&gt;{&lt;br /&gt;for (int i = low; i &lt; apin ="=" apin ="=" apin ="=" apin ="=" apin ="=" apin ="="&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8077223744586062132-8702382208202290889?l=winkmake.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winkmake.blogspot.com/feeds/8702382208202290889/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://winkmake.blogspot.com/2009/04/led-matrix-and-accelerometer.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8077223744586062132/posts/default/8702382208202290889'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8077223744586062132/posts/default/8702382208202290889'/><link rel='alternate' type='text/html' href='http://winkmake.blogspot.com/2009/04/led-matrix-and-accelerometer.html' title='LED Matrix and Accelerometer'/><author><name>Jwink</name><uri>http://www.blogger.com/profile/07356738572886578752</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://1.bp.blogspot.com/_LHP9sz9ANuQ/SWrQ95K1ecI/AAAAAAAAADw/Y3VUIKi1xy0/S220/DSCF4218_face.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_LHP9sz9ANuQ/SdkfgeFG19I/AAAAAAAAAHI/4xIxaBjncvU/s72-c/LEDMatrixPlusAccel.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8077223744586062132.post-207129684835007246</id><published>2009-03-02T20:04:00.001-08:00</published><updated>2009-03-02T20:36:45.278-08:00</updated><title type='text'>Servo Plus Potentiometer</title><content type='html'>&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_LHP9sz9ANuQ/Sayu6tYwGkI/AAAAAAAAAHA/P5CunyV_QC8/s1600-h/PotServo.jpg"&gt;&lt;img style="float:right; margin:0 0 10px 10px;cursor:pointer; cursor:hand;width: 320px; height: 234px;" src="http://1.bp.blogspot.com/_LHP9sz9ANuQ/Sayu6tYwGkI/AAAAAAAAAHA/P5CunyV_QC8/s320/PotServo.jpg" border="0" alt="" id="BLOGGER_PHOTO_ID_5308810384402029122" /&gt;&lt;/a&gt;I had to do one more of these before I took it apart. &lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Not too long ago I saw a link on Make: regarding using &lt;a href="http://blog.makezine.com/archive/2009/02/how-to_tuesday_arduino_101_potentio.html?CMP=OTC-0D6B48984890"&gt;potentiometers and servos&lt;/a&gt;. To be honest, I never got around to watching the video. But after the last blog entry I made, adding in the potentiometer didn't seem all that hard.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The potentiometer takes 5v on one side, ground on the other. In the middle I hooked to one of the analog pins. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Analog read on the Arduino ranges from 0 to 1023. The servo however took a range of values from 375 to 2400. The leaves me needing to convert from 1023 to 2025. This is a fairly simple ratio, which I originally coded something like this:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;pulse value = ((potentiometer value * 2025) / 1023) + 375&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Using this formula introduced me to an interesting detail that I had not seen for a while. Not since a project I had done for the State of Minnesota. At the time I was working on a project for the Department of Education. I don't recall the specifics, but I had been doing some calculations with large numbers in Java. Every so often the numbers would turn negative. This is &lt;span class="Apple-style-span" style="font-style: italic;"&gt;exactly&lt;/span&gt; what I started seeing here when multiplying the potentiometer value with 2025.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;What's going on is something I learned about much further back in college. The type value I was using was too small for the value I was putting into it. Every bit of the value - or perhaps just one particular one - was overwriting the slot that holds the negative/positive indicator. Very annoying.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;To solve the problem on the DOE project I ended up using a larger type. I tried a few different types with the Arduino (doubles, long ints, floats) but to no avail. Instead of digging into a solution further in that direction, a different solution occurred to me - change the calculation:&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;pulse value = ((2025 / 1023)  * potentiometer value) + 375&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;This forces the division to occur first, which winds up with some value like 1.979 and so forth. This is a much smaller value that when multiplied by the pot value and added to 375 is still managable.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Anyway, here's the code:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;pre style="margin: 0px; padding: 6px; border: 1px inset; width: 100%; height: 150px; text-align: left; font-family: Courier New, monospace; overflow: auto"&gt;&lt;br /&gt;/*&lt;br /&gt; * Servo plus potentiometer - a match made in... &lt;br /&gt; * well, a match made on an Arduion at least.&lt;br /&gt; */&lt;br /&gt;&lt;br /&gt;int potPin = 1;&lt;br /&gt;int potVal = 0;&lt;br /&gt;int servoPin = 3;&lt;br /&gt;int baseChar = 48;&lt;br /&gt;int maxCycles = 40;&lt;br /&gt;int minPulse = 375;&lt;br /&gt;int maxPulse = 2400;&lt;br /&gt;int maxAnalog = 1023;&lt;br /&gt;int distance = maxPulse - minPulse;&lt;br /&gt;int list[4] = {-1, -1, -1, -1};&lt;br /&gt;int input = 0;&lt;br /&gt;int pulse = minPulse;&lt;br /&gt;int lastPulse = maxPulse;&lt;br /&gt;&lt;br /&gt;void setup()&lt;br /&gt;{&lt;br /&gt;  // setup serial schtuff&lt;br /&gt;  Serial.begin(9600);&lt;br /&gt;  pinMode(servoPin, OUTPUT);&lt;br /&gt;  &lt;br /&gt;  // say hello&lt;br /&gt;  Serial.println("Servo with potentiometer control - start");&lt;br /&gt;  &lt;br /&gt;  // get first potentiometer value&lt;br /&gt;  potVal = analogRead(potPin);&lt;br /&gt;  &lt;br /&gt;  // calculate pulse from it&lt;br /&gt;  calcPulse();&lt;br /&gt;    &lt;br /&gt;  // then go there&lt;br /&gt;  specific();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void loop()&lt;br /&gt;{&lt;br /&gt;  // read from potentiometer &lt;br /&gt;  int tmpVal = analogRead(potPin);&lt;br /&gt;  &lt;br /&gt;  // if this is a new value&lt;br /&gt;  if (tmpVal != potVal)&lt;br /&gt;  {&lt;br /&gt;    // keep it&lt;br /&gt;    potVal = tmpVal;&lt;br /&gt;&lt;br /&gt;    // calculate pulse from it&lt;br /&gt;    calcPulse();&lt;br /&gt;    &lt;br /&gt;    // then go there&lt;br /&gt;    specific();&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void calcPulse()&lt;br /&gt;{&lt;br /&gt;  double ratio = distance / maxAnalog;&lt;br /&gt;  &lt;br /&gt;  if (potVal == 0) &lt;br /&gt;    pulse = minPulse;&lt;br /&gt;  else if (potVal == maxAnalog)&lt;br /&gt;    pulse = maxPulse;&lt;br /&gt;  else&lt;br /&gt;    pulse = ratio * potVal + minPulse;&lt;br /&gt;    &lt;br /&gt;  Serial.print("potVal: ");&lt;br /&gt;  Serial.print(potVal, DEC);&lt;br /&gt;  Serial.print(", ratio: ");&lt;br /&gt;  Serial.print(ratio, DEC);&lt;br /&gt;  Serial.print(", pulse: ");&lt;br /&gt;  Serial.println(pulse, DEC);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void specific()&lt;br /&gt;{&lt;br /&gt;  if (pulse &gt;= minPulse &amp;&amp; pulse &lt;= maxPulse)&lt;br /&gt;  {&lt;br /&gt;    //Serial.print("Last pulse ");  &lt;br /&gt;    //Serial.println(lastPulse);  &lt;br /&gt;&lt;br /&gt;    //Serial.print("Current pulse ");  &lt;br /&gt;    //Serial.println(pulse);  &lt;br /&gt;&lt;br /&gt;    int travel = max(lastPulse, pulse) - min(lastPulse, pulse);&lt;br /&gt;    //Serial.print("Travel ");  &lt;br /&gt;    //Serial.println(travel);  &lt;br /&gt;    //Serial.print("Distance ");  &lt;br /&gt;    //Serial.println(distance);  &lt;br /&gt;    &lt;br /&gt;    float cut = (float)travel / (float)distance;&lt;br /&gt;    //Serial.print("Cut ");  &lt;br /&gt;    //Serial.println(cut, DEC);  &lt;br /&gt;    &lt;br /&gt;    unsigned int cycles = (maxCycles * cut) + 1;&lt;br /&gt;    cycles = max(cycles, 5);&lt;br /&gt;    //Serial.print("Cycles ");  &lt;br /&gt;    //Serial.println(cycles);  &lt;br /&gt;    &lt;br /&gt;    for (int i = 0; i &lt;= cycles; i++)&lt;br /&gt;    {&lt;br /&gt;      digitalWrite(servoPin, HIGH);&lt;br /&gt;      delayMicroseconds(pulse);&lt;br /&gt;      digitalWrite(servoPin, LOW);&lt;br /&gt;      delay(20);&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    lastPulse = pulse;&lt;br /&gt;  }&lt;br /&gt;  else&lt;br /&gt;  {&lt;br /&gt;    Serial.print("Pulse given ");  &lt;br /&gt;    Serial.print(pulse);  &lt;br /&gt;    Serial.print(" is outside of range: ");  &lt;br /&gt;    Serial.print(minPulse);  &lt;br /&gt;    Serial.print("-");  &lt;br /&gt;    Serial.println(maxPulse);  &lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  pulse = 0;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8077223744586062132-207129684835007246?l=winkmake.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winkmake.blogspot.com/feeds/207129684835007246/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://winkmake.blogspot.com/2009/03/servo-plus-potentiometer.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8077223744586062132/posts/default/207129684835007246'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8077223744586062132/posts/default/207129684835007246'/><link rel='alternate' type='text/html' href='http://winkmake.blogspot.com/2009/03/servo-plus-potentiometer.html' title='Servo Plus Potentiometer'/><author><name>Jwink</name><uri>http://www.blogger.com/profile/07356738572886578752</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://1.bp.blogspot.com/_LHP9sz9ANuQ/SWrQ95K1ecI/AAAAAAAAADw/Y3VUIKi1xy0/S220/DSCF4218_face.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_LHP9sz9ANuQ/Sayu6tYwGkI/AAAAAAAAAHA/P5CunyV_QC8/s72-c/PotServo.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8077223744586062132.post-2666098777203841468</id><published>2009-02-23T19:40:00.000-08:00</published><updated>2009-02-23T20:17:03.656-08:00</updated><title type='text'>Servo Control</title><content type='html'>Here's another one I did a while back &amp;amp; never got around to posting here. Further back, like years (don't remember how many - Evy was small) I got a rather nice RC car kit from my dad. It was a Tamiya "Baja Champ" - the whole deal, dissassembled, two servos, drive motor, trigger controller and such. He also got me a charger for the main power source. It was cool.&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;So I quickly put the thing together and discovered something interesting - and relevant to this post, I assure you. There were spare parts. Extra cogs, some plastic bits, but also a completely spare servo. I got the thing done and it ran fine, but I was still scratching my head over the spare servo. The answer came later. One of my wife's cousins and family were over for a visit and it turned out her husband had built some of these kits before. He said that the extra servo was kind of a hold over from before there was electronic speed control for the motor. The servo actually was the throttle, or whatever. But my kit came with a component that did the work. One servo for the steering and then this board in some box doing the throttle. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;So I've got this extra servo gathering dust for a few years until I get my Arduino. Once I got that every extra electronic gew-gaw and gadget in my house becomes an opportunity. Before I started though, I did some research. The servos I got with the Tamiya were Futaba, specifically S3003. I found a &lt;a href="http://www.gpdealera.com/cgi-bin/wgainf100p.pgm?I=FUTM0031"&gt;tech sheet&lt;/a&gt; on Futaba's site, but wasn't entirely convinced I had the right one. There were some useful links - &lt;a href="http://slab.concordia.ca/2008/arduino/servo-motors/"&gt;here&lt;/a&gt; and &lt;a href="http://www.coolcircuit.com/gadgets/2008/05/01/controling-a-servomotor/"&gt;here&lt;/a&gt; - that were somewhat close to what I had and were enought to get me started. The best link, though, I seem to have misplaced, so I can't share that.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;img src="http://2.bp.blogspot.com/_LHP9sz9ANuQ/SaN0qtQmNRI/AAAAAAAAAG4/XLwvCBfVgck/s320/ServoHalf.jpg" style="float:right; margin:0 0 10px 10px;cursor:pointer; cursor:hand;width: 320px; height: 283px;" border="0" alt="" id="BLOGGER_PHOTO_ID_5306213063025112338" /&gt;&lt;/div&gt;&lt;div&gt;The servo has a three wire cable coming off of it: black for ground, red for voltage - in the case I fed it the 5v,  and white for control. There were warnings here and there about not using the Arduino to directly power the server - something about it needing more amps than the Arduino can provide - but I decided to just blindly ignore this warning and forge ahead. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The pulsing of voltage to the white turned out to be the tricky part. It needs voltage for a given number of miliseconds and then off for like 20 miliseconds to drive it to a particular position. The number of times pulsed - on for a specific number of miliseconds, off for 20 milis, then rinse and repeat - also had some impact. I did not know what the minimum or maximum my servo wanted to move it's full range. I did get a few lines of code that would get it to move, but had no idea how it was working.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;After a bit of trial and error I found the limits: 375 miliseconds for minimum position, 2400 miliseconds for maximum position, or 0 to 180 degrees, give or take. I also found that the distance &lt;span class="Apple-style-span" style="font-style: italic;"&gt;travelled&lt;/span&gt; dictated how long you needed to pulse the cycle for. If you were travelling from 375 all the way to 2400 and you stopped pulsing before the servo completed the motion it would indeed stop halfway. Or three quarters or however long you actually pulsed for. So in my code I added some calculation to figure out how long the travel was and ensure a minimum number of cycles before cutting out. This minimum was whatever it absolutely needed to got the max distance cut down to whatever the travel was.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Anyway, here's the code. There's not much for comments in this version, but I'll eventually go back and put some in.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;pre style="margin: 0px; padding: 6px; border: 1px inset; width: 100%; height: 150px; text-align: left; font-family: Courier New, monospace; overflow: auto"&gt;&lt;br /&gt;/*&lt;br /&gt;* ServoTest5&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;int servoPin = 3;&lt;br /&gt;int baseChar = 48;&lt;br /&gt;int maxCycles = 40;&lt;br /&gt;int minPulse = 375;&lt;br /&gt;int maxPulse = 2400;&lt;br /&gt;int distance = maxPulse - minPulse;&lt;br /&gt;int list[4] = {-1, -1, -1, -1};&lt;br /&gt;int input = 0;&lt;br /&gt;int pulse = minPulse;&lt;br /&gt;int lastPulse = maxPulse;&lt;br /&gt;&lt;br /&gt;void setup()&lt;br /&gt;{&lt;br /&gt;Serial.begin(9600);&lt;br /&gt;pinMode(servoPin, OUTPUT);&lt;br /&gt;Serial.println("Serial servo ranging - start");&lt;br /&gt;specific();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void loop()&lt;br /&gt;{&lt;br /&gt;if (Serial.available())&lt;br /&gt;{&lt;br /&gt;  int count = 3;&lt;br /&gt;  Serial.print("Input: ");&lt;br /&gt;  do&lt;br /&gt;  {&lt;br /&gt;    input = intFromAscii(Serial.read());&lt;br /&gt;    if (input &gt; -1)&lt;br /&gt;    {&lt;br /&gt;      Serial.print(input);&lt;br /&gt;      list[count--] = input;&lt;br /&gt;    }&lt;br /&gt;  } while (input &gt; -1 &amp;amp;&amp;amp; count &gt;= 0); &lt;br /&gt;  Serial.println();&lt;br /&gt;&lt;br /&gt;  //showList();&lt;br /&gt;  pulse = intFromList();&lt;br /&gt;  specific();&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;int intFromAscii(int ascii)&lt;br /&gt;{&lt;br /&gt;int temp = ascii - baseChar;&lt;br /&gt;&lt;br /&gt;if (temp &gt;= 0 &amp;amp;&amp;amp; temp &lt;= 9)     return temp;   else     return -1; }  int intFromList() {   int temp = 0;   int mult = 1;        for (int i = 0; i &lt;&gt; -1)&lt;br /&gt;  {&lt;br /&gt;    temp += list[i] * mult;&lt;br /&gt;    mult *= 10;&lt;br /&gt;  }&lt;br /&gt;} &lt;br /&gt;&lt;br /&gt;clearList();&lt;br /&gt;&lt;br /&gt;return temp;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void clearList()&lt;br /&gt;{&lt;br /&gt;for(int i = 0; i &lt; i =" 0;"&gt;= minPulse &amp;amp;&amp;amp; pulse &lt;= maxPulse)   {     Serial.print("Last pulse ");       Serial.println(lastPulse);        Serial.print("Current pulse ");       Serial.println(pulse);        int travel = max(lastPulse, pulse) - min(lastPulse, pulse);     Serial.print("Travel ");       Serial.println(travel);       Serial.print("Distance ");       Serial.println(distance);            float cut = (float)travel / (float)distance;     Serial.print("Cut ");       Serial.println(cut, DEC);            unsigned int cycles = (maxCycles * cut) + 1;     cycles = max(cycles, 5);     Serial.print("Cycles ");       Serial.println(cycles);            for (int i = 0; i &lt;= cycles; i++)     {       digitalWrite(servoPin, HIGH);       delayMicroseconds(pulse);       digitalWrite(servoPin, LOW);       delay(20);     }          lastPulse = pulse;   }   else   {     Serial.print("Pulse given ");       Serial.print(pulse);       Serial.print(" is outside of range: ");       Serial.print(minPulse);       Serial.print("-");       Serial.println(maxPulse);     }      pulse = 0; } &lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8077223744586062132-2666098777203841468?l=winkmake.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winkmake.blogspot.com/feeds/2666098777203841468/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://winkmake.blogspot.com/2009/02/servo-control.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8077223744586062132/posts/default/2666098777203841468'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8077223744586062132/posts/default/2666098777203841468'/><link rel='alternate' type='text/html' href='http://winkmake.blogspot.com/2009/02/servo-control.html' title='Servo Control'/><author><name>Jwink</name><uri>http://www.blogger.com/profile/07356738572886578752</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://1.bp.blogspot.com/_LHP9sz9ANuQ/SWrQ95K1ecI/AAAAAAAAADw/Y3VUIKi1xy0/S220/DSCF4218_face.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_LHP9sz9ANuQ/SaN0qtQmNRI/AAAAAAAAAG4/XLwvCBfVgck/s72-c/ServoHalf.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8077223744586062132.post-4920145343818437800</id><published>2009-02-16T20:31:00.000-08:00</published><updated>2009-02-23T20:15:43.401-08:00</updated><title type='text'>Open Heart Kit</title><content type='html'>For Valentine's day I decided to create a heart shaped LED display. I had been trying to learn &lt;a href="http://en.wikipedia.org/wiki/Charlieplexing"&gt;Charlieplexing&lt;/a&gt; for a while, but the concept was, for some reason, a difficult one for me. There is an &lt;a href="http://www.instructables.com/"&gt;Instructable&lt;/a&gt; on the &lt;a href="http://www.instructables.com/id/Arduino-Charliplexed-Heart-just-in-time-for-Valen/"&gt;open heart kit&lt;/a&gt;, but the photos of the wiring didn't make any sense to me. There was also a schematic (somewhere) along with it, but that wasn't helping me for some reason. I also wanted to make it a surprise for my wife. Its easy to research the idea with her watching, but once I started my trial and error with a heart shape she'd probably wonder. All this coupled with the fact that Valentine's day was fast approaching, I decided to order a kit.&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;img src="http://4.bp.blogspot.com/_LHP9sz9ANuQ/SZpIiDcT79I/AAAAAAAAAGw/SN4thE-hq2Q/s320/OpenHeart_Half.jpg" style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 206px;" border="0" alt="" id="BLOGGER_PHOTO_ID_5303631261058985938" /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;div&gt;The kit was created by &lt;a href="http://www.jimmieprodgers.com/openheart"&gt;Jimmie Rodgers.&lt;/a&gt; I am fairly impressed with it. He doesn't actually sell the kits off of his site. Instead he went with the &lt;a href="http://www.makershed.com/"&gt;Maker shed&lt;/a&gt; site &lt;a href="http://www.makershed.com/ProductDetails.asp?ProductCode=MKJR1"&gt;here&lt;/a&gt;. One a side note I wasn't impressed with the size of box they sent. &lt;a href="http://www.adafruit.com/"&gt;Adafruit&lt;/a&gt; and &lt;a href="http://www.sparkfun.com/commerce/categories.php"&gt;Sparkfun&lt;/a&gt; both sent my stuff in a small box which fit in my mailbox. Maker shed sent a huge box with a small envelope inside. Since I sent it to work, it wasn't too hard to hide it from my wife, but still.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Soldering PCB wasn't all that difficult, though I did have trouble keeping the LEDs straight (I &lt;span class="Apple-style-span" style="font-style: italic;"&gt;need&lt;/span&gt; to get a 3rd hand or vise or something). I had that bit done in about an hour or tow. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The real problem came in when I started with the cable. Jimmie Rodgers admits it isn't the best solution, but was the best that fit the need. The PCB needs 6 pins off of the Arduino to go HIGH, LOW, or Input. The cable is there to pass these states on to the board. The problem I had with it is it was a bit stiff and difficult to work with. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;img src="http://2.bp.blogspot.com/_LHP9sz9ANuQ/SZpCdzYG9XI/AAAAAAAAAGY/AfN38YVM74g/s200/HeartConnectors_half.jpg" style="float:right; margin:0 0 10px 10px;cursor:pointer; cursor:hand;width: 200px; height: 113px;" border="0" alt="" id="BLOGGER_PHOTO_ID_5303624590957147506" /&gt;&lt;div&gt;I found the connections in the back a bit odd. I don't completely understand why there are three separate plugs. I suspect its that way to accomodate a flexible configuration - the open heart kit can also be sewn into material and connected via conductive thread.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The problem I had with these connectors was that I couldn't get the individual wires to the right length. So the bottom two were fine, but the middle/top was a bit short and kept coming unconnected. I never got around to fixing this because it worked for the most part. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The other problem I had was with the connectors to the Arduino. Included with the kit was a set of break-away headers. I initially just stripped the wires on the other end and attempted to solder them to the headers. Without a third hand or vise I couldn't quite get them to solder very well. They kept breaking. I did get them to stick well enough to prove all my LEDs were connected right before giving up that first night. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The next night I tried breaking up the headers with the thought I could reconfigure them how I liked. This didn't work so well, so I tried some heat shrink tubing to hold the solder joint on. Still didn't keep a good connection. I also tried some super glue, but that was a bit of a mess.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;img src="http://2.bp.blogspot.com/_LHP9sz9ANuQ/SZpGHRn8D5I/AAAAAAAAAGg/i3R5U1VIIZg/s200/PinHookup_half.jpg" style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;width: 200px; height: 146px;" border="0" alt="" id="BLOGGER_PHOTO_ID_5303628601986125714" /&gt;&lt;/div&gt;&lt;div&gt;I made one more attempt at getting pin connectors at the other end. I still had some headers left over from an order I'd made from Sparkfun. I cut six off of that and again soldered the wires directly. I did switch them around so the order was correct if I plugged it in directly to a set of pins on the Arduino. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I also used some heat shrink tubing to pins the solder down so it wouldn't come off. This seems to work, but I still wonder whether there's a better solution somewhere.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Jimmie Rodgers took this whole thing a step further and provided a rather nifty way to program it. It's  flash site that shows an image of the LEDs that you can click on. You click on each LED to light in a given frame and then add a new frame, click on more, and so forth. You really just have to &lt;a href="http://www.jimmieprodgers.com/OpenHeartProgrammer.html"&gt;check it out&lt;/a&gt; to understand. Once you've made all the frames you're going to make, you click generate and get some cut/paste-able code you can load into your Arduino.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I wrote a few different animations so I had some variety to show on Valentine's day. My wife and kids thought it was pretty cool. That along with flowers, chocolate, and wine made the day a success.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Here is the code I said I would, eventually, post. Again, I have to point out I did not write this code. This was generated using the Flash tool on Jimmie Rodger's site. To me the coolest part of this project is this code, or possibly cooler the generator. Having the code gives me some great examples of how he did it. Eventually I plan to apply that to a later project that involves a square array of LEDs and an accelerometer. More on that later (hopefully).&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;pre style="margin: 0px; padding: 6px; border: 1px inset; width: 100%; height: 150px; text-align: left; font-family: Courier New, monospace; overflow: auto"&gt;&lt;br /&gt;//**************************************************************//&lt;br /&gt;//  Name    : Charlieplexed Heart control                       //&lt;br /&gt;//  Author  : Jimmie P Rodgers   www.jimmieprodgers.com         //&lt;br /&gt;//  Date    : 08 Feb, 2008  Last update on 02/13/08             //&lt;br /&gt;//  Version : 1.3                                               //&lt;br /&gt;//  Notes   : Uses Charlieplexing techniques to light up        //&lt;br /&gt;//          : a matrix of 27 LEDs in the shape of a heart       //&lt;br /&gt;//          : project website: www.jimmieprodgers.com/openheart //&lt;br /&gt;//****************************************************************   //&lt;br /&gt;#include &lt;avr/pgmspace.h&gt;  //This is in the Arduino library &lt;br /&gt;int pin1 =1;&lt;br /&gt;int pin2 =2;&lt;br /&gt;int pin3 =3;&lt;br /&gt;int pin4 =4;&lt;br /&gt;int pin5 =5;&lt;br /&gt;int pin6 =6;&lt;br /&gt;const int pins[] = {&lt;br /&gt;  pin1,pin2,pin3,pin4,pin5,pin6};&lt;br /&gt;const int heartpins[27][2] ={&lt;br /&gt;  {pin3, pin1},&lt;br /&gt;  {pin1, pin3},&lt;br /&gt;  {pin2, pin1},&lt;br /&gt;  {pin1, pin2},&lt;br /&gt;  {pin3, pin4},&lt;br /&gt;  {pin4, pin1},&lt;br /&gt;  {pin1, pin4},&lt;br /&gt;  {pin1, pin5},&lt;br /&gt;  {pin6, pin1},&lt;br /&gt;  {pin1, pin6},&lt;br /&gt;  {pin6, pin2},&lt;br /&gt;  {pin4, pin3},&lt;br /&gt;  {pin3, pin5},&lt;br /&gt;  {pin5, pin3},&lt;br /&gt;  {pin5, pin1},&lt;br /&gt;  {pin2, pin5},&lt;br /&gt;  {pin5, pin2},&lt;br /&gt;  {pin2, pin6},&lt;br /&gt;  {pin4, pin5},&lt;br /&gt;  {pin5, pin4},&lt;br /&gt;  {pin3, pin2},&lt;br /&gt;  {pin6, pin5},&lt;br /&gt;  {pin5, pin6},&lt;br /&gt;  {pin4, pin6},&lt;br /&gt;  {pin2, pin3},&lt;br /&gt;  {pin6, pin4},&lt;br /&gt;  {pin4, pin2}&lt;br /&gt; };&lt;br /&gt;int blinkdelay = 200;&lt;br /&gt;//This basically controls brightness. Lower is dimmer&lt;br /&gt;int runspeed = 50;&lt;br /&gt;    //smaller = faster&lt;br /&gt;byte heart[][27] PROGMEM ={&lt;br /&gt;{0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,1,0,0,0,0,0,0},&lt;br /&gt;{0,0,0,0,0,1,1,0,1,1,0,0,1,0,1,0,1,0,0,1,0,1,0,0,1,0,0},&lt;br /&gt;{1,1,1,1,1,0,0,1,0,0,1,1,0,0,0,0,0,1,1,0,0,0,1,1,0,1,1},&lt;br /&gt;{0,0,0,0,0,1,1,0,1,1,0,0,1,0,1,0,1,0,0,1,0,1,0,0,1,0,0},&lt;br /&gt;{2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};&lt;br /&gt;void setup() {&lt;br /&gt;//  blinkall(2); // useful for testing&lt;br /&gt;}&lt;br /&gt;void loop() {&lt;br /&gt;// sequenceon(); // useful for testing&lt;br /&gt;play();&lt;br /&gt;}&lt;br /&gt;void turnon(int led) {&lt;br /&gt;  int pospin = heartpins[led][0];&lt;br /&gt;  int negpin = heartpins[led][1];&lt;br /&gt;  pinMode (pospin, OUTPUT);&lt;br /&gt;  pinMode (negpin, OUTPUT);&lt;br /&gt;  digitalWrite (pospin, HIGH);&lt;br /&gt;  digitalWrite (negpin, LOW);&lt;br /&gt;}&lt;br /&gt;  void alloff() {&lt;br /&gt;  for(int i = 0; i &lt; 6; i++)   {&lt;br /&gt;    pinMode (pins[i], INPUT);&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;void play() {&lt;br /&gt;  boolean run = true;&lt;br /&gt;  byte k;&lt;br /&gt;  int t = 0;&lt;br /&gt;  while(run == true)   {&lt;br /&gt;    for(int i = 0; i &lt; runspeed; i++)     {&lt;br /&gt;      for(int j = 0; j &lt; 27; j++)       {&lt;br /&gt;        k = pgm_read_byte(&amp;(heart[t][j]));&lt;br /&gt;        if (k == 2)         {&lt;br /&gt;          t = 0;&lt;br /&gt;          //run = false;&lt;br /&gt;        }&lt;br /&gt;        else if(k == 1)         {&lt;br /&gt;          turnon(j);&lt;br /&gt;          delayMicroseconds(blinkdelay);&lt;br /&gt;          alloff();&lt;br /&gt;        }&lt;br /&gt;        else if(k == 0)         {&lt;br /&gt;          delayMicroseconds(blinkdelay);&lt;br /&gt;        }&lt;br /&gt;      }&lt;br /&gt;    }     t++;&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;void blinkall(int numblink) {&lt;br /&gt;  alloff();&lt;br /&gt;  for(int n = 0;n &lt; numblink;n++)   {&lt;br /&gt;    for(int i = 0; i &lt; runspeed; i++)     {&lt;br /&gt;      for(int j = 0; j &lt; 27; j++)       {&lt;br /&gt;        turnon(j);&lt;br /&gt;        delay(blinkdelay);&lt;br /&gt;        alloff();&lt;br /&gt;      }&lt;br /&gt;    }&lt;br /&gt;    delay(500);&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;void sequenceon() {&lt;br /&gt;  for(int i = 0; i &lt; 27; i++)   {&lt;br /&gt;    turnon(i);&lt;br /&gt;    delay(800);&lt;br /&gt;       alloff();&lt;br /&gt;    delay(800);&lt;br /&gt;     }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8077223744586062132-4920145343818437800?l=winkmake.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winkmake.blogspot.com/feeds/4920145343818437800/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://winkmake.blogspot.com/2009/02/open-heart-kit.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8077223744586062132/posts/default/4920145343818437800'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8077223744586062132/posts/default/4920145343818437800'/><link rel='alternate' type='text/html' href='http://winkmake.blogspot.com/2009/02/open-heart-kit.html' title='Open Heart Kit'/><author><name>Jwink</name><uri>http://www.blogger.com/profile/07356738572886578752</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://1.bp.blogspot.com/_LHP9sz9ANuQ/SWrQ95K1ecI/AAAAAAAAADw/Y3VUIKi1xy0/S220/DSCF4218_face.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_LHP9sz9ANuQ/SZpIiDcT79I/AAAAAAAAAGw/SN4thE-hq2Q/s72-c/OpenHeart_Half.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8077223744586062132.post-279998381526397566</id><published>2009-01-22T21:29:00.001-08:00</published><updated>2009-01-22T21:48:40.096-08:00</updated><title type='text'>Dark sensor</title><content type='html'>&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_LHP9sz9ANuQ/SXlYZUsKXoI/AAAAAAAAAEc/l8xXzaWHN0U/s1600-h/DSCF4320_small.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 233px;" src="http://3.bp.blogspot.com/_LHP9sz9ANuQ/SXlYZUsKXoI/AAAAAAAAAEc/l8xXzaWHN0U/s320/DSCF4320_small.jpg" border="0" alt="" id="BLOGGER_PHOTO_ID_5294360029024640642" /&gt;&lt;/a&gt;&lt;br /&gt;This is really a test of a light sensor, or Light Dependent Resistor (LDR). I got one of these with my prototyping kit from Adafruit and figured I should learn how to use it. There is actually a much more useful article on &lt;a href="http://www.libelium.com/squidbee/index.php?title=Adding_a_light_sensor"&gt;Libelium&lt;/a&gt; that shows how to hook it up more clearly and even gives schematics. &lt;div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The 5v is dropped a bit with a 1k resistor. The LDR is dropped into ground with the other end sitting between the dropped 5v and one of the analog ports. As voltage varies through the LDR the analog port sees the difference and reports it. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;In my code whatever is found on the LDR/analog port (0-1023) is translated into a number of LEDs to light. The lower the value - or less resistance to ground - presented by the LDR shows up as a lower value on the analog port. This means less LEDs lit. The higher the values and the more LEDs are lit. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I built several versions of this setup, but the one pictured is the last version. It uses 9 LEDs I took from a Christmas light string I got from Gerten's. The LEDs aren't fancy, but I've got a lot of them, so I figured on the last incarnation of this thing I'd use as many as I could comfortably fit on the proto-shield.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;&lt;pre style="margin: 0px; padding: 6px; border: 1px inset; width: 100%; height: 150px; text-align: left; font-family: Courier New, monospace; overflow: auto"&gt;&lt;br /&gt;/* &lt;br /&gt; * LightSensor4.pde&lt;br /&gt; * Controls 9 LEDw which get turned on or off in relation&lt;br /&gt; * to values read from the LDR. None on for darkest up to&lt;br /&gt; * all on for brightest.&lt;br /&gt; */&lt;br /&gt;&lt;br /&gt;// Light Dependent Resistor (LDR) - or analog pin we'll listen to&lt;br /&gt;int LDR = 0;&lt;br /&gt;&lt;br /&gt;// various levels of analog read - total range is 1023 (dark) to zero (light)&lt;br /&gt;// int level[] = { 1024, 896, 768, 640, 512, 384, 256, 128 };&lt;br /&gt;int level[] = { 1000, 900, 800, 700, 600, 500, 400, 300, 200 };&lt;br /&gt;&lt;br /&gt;// establish an array for our LED pins&lt;br /&gt;int ledpin[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };&lt;br /&gt;&lt;br /&gt;// other working variable schtuff&lt;br /&gt;int leds = 9;&lt;br /&gt;int count = 0;&lt;br /&gt;int val = 0;&lt;br /&gt;int set = 0;&lt;br /&gt;&lt;br /&gt;/*&lt;br /&gt; * The "run once" setup method&lt;br /&gt; */&lt;br /&gt;void setup() &lt;br /&gt;{&lt;br /&gt;  // set up to communication with serial&lt;br /&gt;  Serial.begin(9600);&lt;br /&gt;  &lt;br /&gt;  // set this pin (analog/light sensor) to input&lt;br /&gt;  pinMode(LDR, INPUT);&lt;br /&gt;  &lt;br /&gt;  // set all the LED pins to output&lt;br /&gt;  for (count = 0; count &lt; leds; count++)&lt;br /&gt;  {&lt;br /&gt;    pinMode(ledpin[count], OUTPUT);&lt;br /&gt;    // and turn on those LEDs&lt;br /&gt;    //digitalWrite(ledpin[count], HIGH);&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  // say that we're done if anyone's listening&lt;br /&gt;  Serial.println("Setup has run");&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/*&lt;br /&gt; * Main processing method&lt;br /&gt; */&lt;br /&gt;void loop() &lt;br /&gt;{&lt;br /&gt;  // fetch a value from the light sensor&lt;br /&gt;  val = analogRead(LDR);&lt;br /&gt;  &lt;br /&gt;  // show us what analog/LDR val is&lt;br /&gt;  Serial.print("val: ");&lt;br /&gt;  Serial.println(val, DEC);&lt;br /&gt;&lt;br /&gt;  // initially set LEDs to light to max # possible&lt;br /&gt;  set = leds;&lt;br /&gt;&lt;br /&gt;  // look through range of levels&lt;br /&gt;  for (count = 0; count &lt; leds; count++)&lt;br /&gt;  {&lt;br /&gt;    // if value less than a given level, drop # of LEDs to light by 1&lt;br /&gt;    if (val &lt; level[count]) { set--; }&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  // show us what we think the number of LEDs to set is&lt;br /&gt;  Serial.print("set: ");&lt;br /&gt;  Serial.println(set, DEC);&lt;br /&gt;  &lt;br /&gt;  // if there's anything to set&lt;br /&gt;  if (set &gt; 0)&lt;br /&gt;  {&lt;br /&gt;    // loop up to only the number to set&lt;br /&gt;    for (count = 0; count &lt; set; count++)&lt;br /&gt;    {&lt;br /&gt;      // and turn on those LEDs&lt;br /&gt;      digitalWrite(ledpin[count], HIGH);&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  // loop through the remaining LEDs&lt;br /&gt;  for (count = (leds - 1); count &gt;= set; count--)&lt;br /&gt;  {&lt;br /&gt;    // and turn 'em off&lt;br /&gt;    digitalWrite(ledpin[count], LOW);    &lt;br /&gt;  }&lt;br /&gt;  */&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8077223744586062132-279998381526397566?l=winkmake.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winkmake.blogspot.com/feeds/279998381526397566/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://winkmake.blogspot.com/2009/01/dark-sensor.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8077223744586062132/posts/default/279998381526397566'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8077223744586062132/posts/default/279998381526397566'/><link rel='alternate' type='text/html' href='http://winkmake.blogspot.com/2009/01/dark-sensor.html' title='Dark sensor'/><author><name>Jwink</name><uri>http://www.blogger.com/profile/07356738572886578752</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://1.bp.blogspot.com/_LHP9sz9ANuQ/SWrQ95K1ecI/AAAAAAAAADw/Y3VUIKi1xy0/S220/DSCF4218_face.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_LHP9sz9ANuQ/SXlYZUsKXoI/AAAAAAAAAEc/l8xXzaWHN0U/s72-c/DSCF4320_small.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8077223744586062132.post-1823951845377222614</id><published>2009-01-14T22:20:00.000-08:00</published><updated>2009-01-26T14:05:32.615-08:00</updated><title type='text'>Triple Axis Accelerometer</title><content type='html'>&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_LHP9sz9ANuQ/SW7Zz4kj-pI/AAAAAAAAAEU/aKSItYdRo0U/s1600-h/DSCF4252_small.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 239px;" src="http://3.bp.blogspot.com/_LHP9sz9ANuQ/SW7Zz4kj-pI/AAAAAAAAAEU/aKSItYdRo0U/s320/DSCF4252_small.jpg" border="0" alt="" id="BLOGGER_PHOTO_ID_5291406097589205650" /&gt;&lt;/a&gt;&lt;br /&gt;Another post-holidays item I ordered from SparkFun was a triple-axis accelerometer (MMA7260Q). This was probably the most expensive item in my order and the one I was the most twitchy about working with. If I wrecked it - soldered it wrong or fed it too much voltage - well, that was $20 gone. &lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;What I got was fairly easy to work with, though. SparkFun pre-mounts the chip onto a breakout board for convenience. From there all I had to do was solder on some headers so I could slot it into a bread-board.&lt;br /&gt;&lt;br /&gt;SparkFun frequently provides a link to the &lt;a href="http://www.sparkfun.com/datasheets/Accelerometers/MMA7260Q-Rev1.pdf"&gt;datasheet&lt;/a&gt; PDF, which helps with some of the basics of what each given item's specs, limitations are - what it can do. They also provided another helpful link to Tom Igoe's site to a &lt;a href="http://itp.nyu.edu/physcomp/sensors/Reports/MMA7260Q"&gt;page&lt;/a&gt; describing the MMA7260Q. The data sheet was helpful, but Tom Igoe's description was more so. This description didn't discuss using it with the Arduino specifically, but I could infer enough to get things going.&lt;br /&gt;&lt;br /&gt;Once I had the break-out soldered, I plugged it into the proto-board and started into it. The pins on the breakout were as follows:&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;The first pin accepts 3.3v, of which the Arduino provides one.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;The next pin is ground (there are lots of places to put this to on the proto-board).&lt;br /&gt;&lt;/li&gt;&lt;li&gt;The X axis went to analog 0.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;The Y axis went to analog 1.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;The Z axis went to analog 2.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;The next two used in combination control sensitivity, i.e. combinations 3.3v or ground will change sesitivity from 1.5 g to 6 g. I put both to ground which sets it to the most sensitive setting.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;The last pin controls sleep mode.&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;The meaning last pin wasn't immediately apparent to me. It puts the accelerometer to sleep, sure, but I didn't understand how. I started with no signal - nothing hooked up - and then ground. I spent the next half hour wondering why I was getting nothing from the accelerometer &amp;amp; assuming I'd broken it before I tried throwing 3.3v through it. Then it woke up and I started getting real data off of the analog pins from which I was reading. No signal or ground means sleep, 3.3v means wake up.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;My initial testing with the chip involved just watching what I'd get from Serial.read off of the three analog pins. The max voltage going in was 3.3v, so that's the max that would come out of the analog - or X/Y/Z - ports. The range of values the Arduino analog pins &lt;i&gt;could&lt;/i&gt; read was 0 to 1023 - or for 5v. This meant my max value possible from the accelerometer was somewhat lower; 0 to 675 or there abouts.&lt;br /&gt;&lt;br /&gt;After a couple tests the prototype I came up with involved 6 LED's that would dim or brighten based on which axis were leaning in a given direction. This meant splitting the values produced by analog in half and then converting that range of values to something from 0 to 255 - the digital pins outputting voltage to the LEDs only have resolution from 0 to 255.&lt;br /&gt;&lt;br /&gt;The X and Y axis worked great - one LED would dim as the other brightened. At level both on the same axis would be dark (or close) and so forth. The Z axis was a bit of a let-down though. I wasn't exactly sure what to expect. To get it to do anything, though, I had to sort of shake the whole unit up and down. Otherwise, one of the LEDs was on all the time and the other off. I think the Z axias is used for free-fall detection. for my simple little rig, it wasn't much use.&lt;br /&gt;&lt;br /&gt;The final code to run the configuration pictured was:&lt;br /&gt;&lt;br /&gt;&lt;pre style="margin: 0px; padding: 6px; border: 1px inset; width: 100%; height: 150px; text-align: left; font-family: Courier New, monospace; overflow: auto"&gt;&lt;br /&gt;/*&lt;br /&gt;* TripleAxisAccelerometer3.pde&lt;br /&gt;* This next test of the triple-axis accelerometer&lt;br /&gt;* involves using it's info to dim and brighten 6 LEDs,&lt;br /&gt;* one for each possible direction, or a cube.&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;// axis analog pins&lt;br /&gt;int xAx = 0;&lt;br /&gt;int yAx = 1;&lt;br /&gt;int zAx = 2;&lt;br /&gt;&lt;br /&gt;// values from those pins&lt;br /&gt;int xVal = 0;&lt;br /&gt;int yVal = 0;&lt;br /&gt;int zVal = 0;&lt;br /&gt;&lt;br /&gt;// the LED pins&lt;br /&gt;int xPins[] = { 9, 6 };&lt;br /&gt;int yPins[] = { 3, 11 };&lt;br /&gt;int zPins[] = { 10, 5 };&lt;br /&gt;&lt;br /&gt;// calculated values - remove later?&lt;br /&gt;int xl = 0;&lt;br /&gt;int xr = 0;&lt;br /&gt;int yl = 0;&lt;br /&gt;int yr = 0;&lt;br /&gt;int zl = 0;&lt;br /&gt;int zr = 0;&lt;br /&gt;&lt;br /&gt;// calculations&lt;br /&gt;float hafRange = 337.59;&lt;br /&gt;float maxAnlog = 255;&lt;br /&gt;float adjuster = (float)maxAnlog / (float)hafRange;&lt;br /&gt;&lt;br /&gt;// other working variable schtuff&lt;br /&gt;int mid = 337;&lt;br /&gt;int set = 0;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/*&lt;br /&gt;* The "run once" setup method&lt;br /&gt;*/&lt;br /&gt;void setup()&lt;br /&gt;{&lt;br /&gt; // set up to communication with serial&lt;br /&gt; Serial.begin(9600);&lt;br /&gt;&lt;br /&gt; // set axis/analog pins to input&lt;br /&gt; pinMode(xAx, INPUT);&lt;br /&gt; pinMode(yAx, INPUT);&lt;br /&gt; pinMode(zAx, INPUT);&lt;br /&gt;&lt;br /&gt; showCalcs();&lt;br /&gt;&lt;br /&gt; // say that we're done if anyone's listening&lt;br /&gt; Serial.println("Setup has run");&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/*&lt;br /&gt;* Main processing method&lt;br /&gt;*/&lt;br /&gt;void loop()&lt;br /&gt;{&lt;br /&gt; // message to show once&lt;br /&gt; if (set == 0)&lt;br /&gt; {&lt;br /&gt;   Serial.println("Loop has started");&lt;br /&gt;   set = 1;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; // fetch value from various analog&lt;br /&gt; xVal = analogRead(xAx);&lt;br /&gt; yVal = analogRead(yAx);&lt;br /&gt; zVal = analogRead(zAx);&lt;br /&gt;&lt;br /&gt; // calculate values &lt;br /&gt; xl = adjustLeft(xVal);&lt;br /&gt; xr = adjustRight(xVal);&lt;br /&gt; yl = adjustLeft(yVal);&lt;br /&gt; yr = adjustRight(yVal);&lt;br /&gt; zl = adjustLeft(zVal);&lt;br /&gt; zr = adjustRight(zVal);&lt;br /&gt;&lt;br /&gt; // show us&lt;br /&gt; Serial.print("xl ");&lt;br /&gt; Serial.print(xl);&lt;br /&gt; Serial.print(", xr ");&lt;br /&gt; Serial.print(xr);&lt;br /&gt; Serial.print(", yl ");&lt;br /&gt; Serial.print(yl);&lt;br /&gt; Serial.print(", yr ");&lt;br /&gt; Serial.print(yr);&lt;br /&gt; Serial.print(", zl ");&lt;br /&gt; Serial.print(zl);&lt;br /&gt; Serial.print(", zr ");&lt;br /&gt; Serial.println(zr);&lt;br /&gt;&lt;br /&gt; // write to pins&lt;br /&gt; writePin('X', 'L', xPins[0], adjustLeft(xVal));&lt;br /&gt; writePin('X', 'R', xPins[1], adjustRight(xVal));&lt;br /&gt; writePin('Y', 'L', yPins[0], adjustLeft(yVal));&lt;br /&gt; writePin('Y', 'R', yPins[1], adjustRight(yVal));&lt;br /&gt; writePin('Z', 'L', zPins[0], adjustLeft(zVal));&lt;br /&gt; writePin('Z', 'L', zPins[1], adjustRight(zVal));&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/*&lt;br /&gt;* Adjust the value incoming from analog&lt;br /&gt;* to something between 0 and 255.&lt;br /&gt;*/&lt;br /&gt;int adjustLeft(int valRead)&lt;br /&gt;{&lt;br /&gt; int adjusted = 0;&lt;br /&gt;&lt;br /&gt; if (valRead &lt; adjusted =" maxAnlog" adjusted =" 0;"&gt; hafRange)&lt;br /&gt; {&lt;br /&gt;   adjusted = (valRead * adjuster) - maxAnlog;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; return adjusted;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/*&lt;br /&gt;* Do the work of writing one value to&lt;br /&gt;* one pin here so we can print some info.&lt;br /&gt;*/&lt;br /&gt;void writePin(char axis, char dir, int pin, int val)&lt;br /&gt;{&lt;br /&gt; /* &lt;br /&gt; Serial.print("axis ");&lt;br /&gt; Serial.print(axis);&lt;br /&gt; Serial.print(", dir ");&lt;br /&gt; Serial.print(dir);&lt;br /&gt; Serial.print(", pin ");&lt;br /&gt; Serial.print(pin);&lt;br /&gt; Serial.print(", val ");&lt;br /&gt; Serial.println(val);&lt;br /&gt; */&lt;br /&gt;&lt;br /&gt; analogWrite(pin, val);&lt;br /&gt; // analogWrite(xPins[0], adjustLeft(xVal));&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;void showCalcs()&lt;br /&gt;{&lt;br /&gt; unsigned int temp = 0;&lt;br /&gt;&lt;br /&gt; temp = hafRange * 100;&lt;br /&gt; Serial.print("hafRange: ");&lt;br /&gt; Serial.println(temp, DEC);&lt;br /&gt;&lt;br /&gt; Serial.print("maxAnlog: ");&lt;br /&gt; Serial.println(maxAnlog, DEC);&lt;br /&gt;&lt;br /&gt; temp = adjuster * 100;&lt;br /&gt; Serial.print("adjuster: ");&lt;br /&gt; Serial.println(temp, DEC);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8077223744586062132-1823951845377222614?l=winkmake.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winkmake.blogspot.com/feeds/1823951845377222614/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://winkmake.blogspot.com/2009/01/triple-axis-accelerometer.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8077223744586062132/posts/default/1823951845377222614'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8077223744586062132/posts/default/1823951845377222614'/><link rel='alternate' type='text/html' href='http://winkmake.blogspot.com/2009/01/triple-axis-accelerometer.html' title='Triple Axis Accelerometer'/><author><name>Jwink</name><uri>http://www.blogger.com/profile/07356738572886578752</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://1.bp.blogspot.com/_LHP9sz9ANuQ/SWrQ95K1ecI/AAAAAAAAADw/Y3VUIKi1xy0/S220/DSCF4218_face.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_LHP9sz9ANuQ/SW7Zz4kj-pI/AAAAAAAAAEU/aKSItYdRo0U/s72-c/DSCF4252_small.jpg' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8077223744586062132.post-2202867348862330936</id><published>2009-01-11T21:52:00.001-08:00</published><updated>2009-01-13T14:56:52.959-08:00</updated><title type='text'>Seven segment LED</title><content type='html'>&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_LHP9sz9ANuQ/SWwiPdulCZI/AAAAAAAAAEM/G9xxWYDVX-I/s1600-h/SevenSegment.jpg"&gt;&lt;img style="float:right; margin:0 0 10px 10px;cursor:pointer; cursor:hand;width: 320px; height: 240px;" src="http://1.bp.blogspot.com/_LHP9sz9ANuQ/SWwiPdulCZI/AAAAAAAAAEM/G9xxWYDVX-I/s320/SevenSegment.jpg" border="0" alt="" id="BLOGGER_PHOTO_ID_5290641311326865810" /&gt;&lt;/a&gt;&lt;br /&gt;Over the holidays when gift giving was over and I could spend money again (don't ask), I made an order to both Adafruit and Sparkfun. From the latter I ordered a number of things (in later blogs) including 4 seven-segment LEDs. I mean, c'mon - they were only 95 cents. &lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Using my Arduino Duemilanova and protoyping kit I got one of these things working. I could display 0-9 and then turn off at the touch of a button. In the interest of sharing, here are my notes.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The image shows the finished product. A prototyping shield on top of my Duemilanova. On that is one of my single 7 segment LED (SparkFun COM-08546). The unit has 10 pins coming out of the back of it - 5 on top, and five on bottom. They fit nicely into a breadboard. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Eight of the pins are used to control the segments - one of those being the decimal dot to the right of the number. There is a dot to the left of it, but it doesn't do anything. One of the pins - dead center at the top - accepts voltage. According to the &lt;a href="http://www.sparkfun.com/datasheets/Components/YSD-160AR4B-8.pdf"&gt;specs&lt;/a&gt; on SparkFun it should take only 2.2 volts, but I set the full 5 that the Arduino would deliver before I realized I probably shouldn't do that. It didn't blow it out or anything, but it was real bright. I put a resistor in line with one of the 5 volt outputs and this dimmed it a bit, but I still haven't figured out how to be more specific about controlling voltage/amps, etc. Probably a diode?&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I wired up a switch same as described in LadyAda's &lt;a href="http://www.ladyada.net/learn/arduino/lesson5.html"&gt;tutorial&lt;/a&gt; because it was useful in counting presses - exactly what I wanted to do here. Each press of the button would increment the digit displayed, 0 through 9. After 9 it'd go dark and then repeat. The code I developed to accomplish this is as follows:&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;pre style="margin: 0px; padding: 6px; border: 1px inset; width: 100%; height: 150px; text-align: left; font-family: Courier New, monospace; overflow: auto"&gt;&lt;br /&gt;/* &lt;br /&gt; * SegmentLEDTest4.pde&lt;br /&gt; * Test code to tick up the display&lt;br /&gt; * along with hits to the button.&lt;br /&gt; */&lt;br /&gt;&lt;br /&gt;// state which pin will switch&lt;br /&gt;int switchPin = 13;&lt;br /&gt;&lt;br /&gt;// establish an array for our LED pins&lt;br /&gt;int ledpin[] = { 11, 3, 12, 2, 5, 8, 6, 9 }; &lt;br /&gt;&lt;br /&gt;// establish multi-dimensional array to show numbers&lt;br /&gt;int numbers[][11] = {&lt;br /&gt;  { LOW,  LOW,  LOW,  HIGH, LOW,  LOW,  LOW,  HIGH }, // 0&lt;br /&gt;  { HIGH, HIGH, LOW,  HIGH, HIGH, LOW,  HIGH, HIGH }, // 1&lt;br /&gt;  { LOW,  HIGH, LOW,  LOW,  LOW,  HIGH, LOW,  HIGH }, // 2&lt;br /&gt;  { LOW,  HIGH, LOW,  LOW,  HIGH, LOW,  LOW,  HIGH }, // 3&lt;br /&gt;  { HIGH, LOW,  LOW,  LOW,  HIGH, LOW,  HIGH, HIGH }, // 4&lt;br /&gt;  { LOW,  LOW,  HIGH, LOW,  HIGH, LOW,  LOW,  HIGH }, // 5&lt;br /&gt;  { LOW,  LOW,  HIGH, LOW,  LOW,  LOW,  LOW,  HIGH }, // 6&lt;br /&gt;  { LOW,  HIGH, LOW,  HIGH, HIGH, LOW,  HIGH, HIGH }, // 7&lt;br /&gt;  { LOW,  LOW,  LOW,  LOW,  LOW,  LOW,  LOW,  HIGH }, // 8&lt;br /&gt;  { LOW,  LOW,  LOW,  LOW,  HIGH, LOW,  HIGH, HIGH }, // 9&lt;br /&gt;  { HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH }  // off&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;// other working variable schtuff&lt;br /&gt;int leds = 9;&lt;br /&gt;int count = 0;&lt;br /&gt;int state = HIGH;&lt;br /&gt;int val = LOW;&lt;br /&gt;int digit = 10;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/*&lt;br /&gt; * The "run once" setup method&lt;br /&gt; */&lt;br /&gt;void setup() &lt;br /&gt;{&lt;br /&gt;  // set the switch pin to read&lt;br /&gt;  pinMode(switchPin, INPUT);&lt;br /&gt;  &lt;br /&gt;  // set all the LED pins to output and high - in this case NOT ground&lt;br /&gt;  for (count = 0; count &lt; leds; count++)&lt;br /&gt;  {&lt;br /&gt;    pinMode(ledpin[count], OUTPUT);&lt;br /&gt;    digitalWrite(ledpin[count], HIGH);&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/*&lt;br /&gt; * Main processing method&lt;br /&gt; */&lt;br /&gt;void loop() &lt;br /&gt;{&lt;br /&gt;  // read the switch&lt;br /&gt;  val = digitalRead(switchPin);&lt;br /&gt;  &lt;br /&gt;  // if it's pressed, or at least state has changed&lt;br /&gt;  if (val != state)&lt;br /&gt;  {&lt;br /&gt;    // AND that state is low, or the button is DOWN&lt;br /&gt;    if (val == LOW)&lt;br /&gt;    {&lt;br /&gt;      // increment digit&lt;br /&gt;      digit = digit + 1;&lt;br /&gt;&lt;br /&gt;      // reset if we exceeded our limit of what we can actually display&lt;br /&gt;      if (digit &gt; 10) &lt;br /&gt;      { &lt;br /&gt;        // reset it to zero&lt;br /&gt;        digit = 0; &lt;br /&gt;      }&lt;br /&gt;&lt;br /&gt;      // show the digit&lt;br /&gt;      Display();&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    // keep last&lt;br /&gt;    state = val;&lt;br /&gt;  }  &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/*&lt;br /&gt;  * Given a specific value, pluck out that row&lt;br /&gt;  * in the multi-dimensional array and show that&lt;br /&gt;  * combination of HIGH and LOW values&lt;br /&gt;  */&lt;br /&gt;void Display()&lt;br /&gt;{&lt;br /&gt;  // loop through LED pins&lt;br /&gt;  for (count = 0; count &lt; leds; count++)&lt;br /&gt;  {&lt;br /&gt;    // writing on (LOW or accept ground) or off (HIGH or do not accept ground) depending on digit&lt;br /&gt;    digitalWrite(ledpin[count], numbers[digit][count]);&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8077223744586062132-2202867348862330936?l=winkmake.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winkmake.blogspot.com/feeds/2202867348862330936/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://winkmake.blogspot.com/2009/01/seven-segment-led.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8077223744586062132/posts/default/2202867348862330936'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8077223744586062132/posts/default/2202867348862330936'/><link rel='alternate' type='text/html' href='http://winkmake.blogspot.com/2009/01/seven-segment-led.html' title='Seven segment LED'/><author><name>Jwink</name><uri>http://www.blogger.com/profile/07356738572886578752</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://1.bp.blogspot.com/_LHP9sz9ANuQ/SWrQ95K1ecI/AAAAAAAAADw/Y3VUIKi1xy0/S220/DSCF4218_face.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_LHP9sz9ANuQ/SWwiPdulCZI/AAAAAAAAAEM/G9xxWYDVX-I/s72-c/SevenSegment.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8077223744586062132.post-5668400308817374461</id><published>2009-01-11T21:15:00.000-08:00</published><updated>2009-02-16T20:31:21.901-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='LadyAda'/><category scheme='http://www.blogger.com/atom/ns#' term='Make'/><category scheme='http://www.blogger.com/atom/ns#' term='Arduino'/><category scheme='http://www.blogger.com/atom/ns#' term='Adafruit'/><category scheme='http://www.blogger.com/atom/ns#' term='Duemilanova'/><title type='text'>Introduction</title><content type='html'>I've never had a blog before, and for that matter, never had a reason. Now I do, or at least now I want to get some things down before I forget. If any of this winds up being useful to other people, great. If not, well, I've got notes out in the cloud I can get back to from anywhere. It has come to my attention that computers are better at remembering things than my own brain - more on that later...&lt;div style="text-align: center;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;For a while I've had a number of ideas regarding various gadgets I wanted to build. Most of these gadgets are of an electronic nature. I am a Software Engineer by trade. While I've got 15+ years of experience programming in various languages, I've got little or no experience with electronics. This has, until recently, stopped me from acting on any of these ideas.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;With software you can debug and you can try again with little or not consequences. With electronics sometimes if you make a mistake you can fry a component - and you're out real money. I hadn't gotten into it because I was afraid. That and I didn't know where to start.&lt;/div&gt;&lt;div style="text-align: center;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I had been trolling the web and other blogs for a while to see how other people build their stuff. It was during these trolls - and this is recently - that I discovered Arduino. It was open souce - which means something to me coming from the software industry - and low cost. The barriers to entry were all but dropped, so I plunked down some cash and bought one.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;img src="http://1.bp.blogspot.com/_LHP9sz9ANuQ/SZo9aMI0_DI/AAAAAAAAAGI/xphtbcD-kfo/s320/ArduinoDuemilanova_half.jpg" style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 218px;" border="0" alt="" id="BLOGGER_PHOTO_ID_5303619031326325810" /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;What I bought was an &lt;a href="http://www.arduino.cc/"&gt;Arduino&lt;/a&gt; "Duemilanove" (2009) and a prototyping kit from &lt;a href="http://www.adafruit.com/"&gt;Adafruit&lt;/a&gt;. The Arduino itself was assembled and I got a USB cable with the kit. Adafruit pointed me at a great &lt;a href="http://www.ladyada.net/learn/arduino/index.html"&gt;tutorial&lt;/a&gt; written by one of the owners (&lt;a href="http://www.ladyada.net/"&gt;LadyAda&lt;/a&gt; if you don't already know) that walked me through getting familiar with the Arduino as well as teachning me how to assemble the prototyping kit.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Some soldering and electronics indoctrination (?)  later, I was hooked. I've created a number of little "projects" of my own. I wouldn't call these finished product - more doodles, or sketches designed to teach myself how to work with something in particular. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Don't get me wrong - I'm not saying I'm doing this just to learn things. It's fun playing with the thing and getting it to work. If anyone else in the programming field is reading this then they know the joy behind fiddling with code to accomplish a complicated goal. Its fun to try different things - some that work, some that don't - but to eventually come up with the solution and see your application running on the screen. Working with electronics - and the Arduino in particular - is that same joy on a different level. When I get it working I can show my wife and kids and it's not just on a computer screen; it's there in front of them, blinking, or moving a motor, or what have you.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I've created a number of projects of my own that mimic some of what I've seen out out on the web to some degree, some don't. With this blog I intend to try and post info on what I &lt;i&gt;don't&lt;/i&gt; see many examples of. Images, code, and - if I can figure out how to write them - schematics will also be posted here. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Whenever I find errors in my own stuff, I will endeavor to correct them. I can make no claims as to how fast that will happen or how quickly new material will appear. I have a full time job, a wife, 2 kids, and many other interests all of which I must spend my limited time nurturing and caring for. &lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;That said, enjoy and thanks for listening...&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8077223744586062132-5668400308817374461?l=winkmake.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winkmake.blogspot.com/feeds/5668400308817374461/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://winkmake.blogspot.com/2009/01/introduction.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8077223744586062132/posts/default/5668400308817374461'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8077223744586062132/posts/default/5668400308817374461'/><link rel='alternate' type='text/html' href='http://winkmake.blogspot.com/2009/01/introduction.html' title='Introduction'/><author><name>Jwink</name><uri>http://www.blogger.com/profile/07356738572886578752</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://1.bp.blogspot.com/_LHP9sz9ANuQ/SWrQ95K1ecI/AAAAAAAAADw/Y3VUIKi1xy0/S220/DSCF4218_face.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_LHP9sz9ANuQ/SZo9aMI0_DI/AAAAAAAAAGI/xphtbcD-kfo/s72-c/ArduinoDuemilanova_half.jpg' height='72' width='72'/><thr:total>0</thr:total></entry></feed>
