<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>lithium flowers bloom &#187; Arduino</title>
	<atom:link href="http://leejayxia.com/blog/tag/arduino/feed/" rel="self" type="application/rss+xml" />
	<link>http://leejayxia.com/blog</link>
	<description>the weblog</description>
	<lastBuildDate>Sat, 15 May 2010 20:52:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Sensor Network: Data Logging and Visualization</title>
		<link>http://leejayxia.com/blog/sensor-network-data-logging-and-visualization/</link>
		<comments>http://leejayxia.com/blog/sensor-network-data-logging-and-visualization/#comments</comments>
		<pubDate>Mon, 01 Mar 2010 07:50:18 +0000</pubDate>
		<dc:creator>L.J</dc:creator>
				<category><![CDATA[ITP]]></category>
		<category><![CDATA[Sociable Objects Workshop]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Processing]]></category>
		<category><![CDATA[sensor network]]></category>
		<category><![CDATA[Visualization]]></category>
		<category><![CDATA[xbee]]></category>

		<guid isPermaLink="false">http://leejayxia.com/blog/?p=823</guid>
		<description><![CDATA[I&#8217;m working with Sebastian and Michael as &#8220;visualization&#8221; team for the sensor network assignment for this week&#8217;s Sociable Objects Workshop. It&#8217;s very challenging for the whole class to work on one single project, but so far it went on pretty well. Tasks are split and assigned and we also find ways to work with dependencies [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m working with Sebastian and Michael as &#8220;visualization&#8221; team for the sensor network assignment for this week&#8217;s Sociable Objects Workshop. It&#8217;s very challenging for the whole class to work on one single project, but so far it went on pretty well. Tasks are split and assigned and we also find ways to work with dependencies and such constraints.</p>
<p>Since we are just focusing on the visualization part, meaning that we take on only after all the data are aggregated at the coordinator xbee, our main effort will be data logging, mining and visualization. So the first thing we built is a <strong>pseudo data generator</strong> that feeds data in the same format as the data will be from the coordinator. We talked to the base station team and agreed that we will be getting raw API I/O RX packet and we will take care of the parsing and data storage. </p>
<p>I put together some simple arduino code to feed pseudo data, they could be easily replaced by a real coordinator and ideally we will not have to change the processing code on the other side which is listening to the serial channel.</p>
<div class="codecolorer-container c dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:1300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br /></div></td><td><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933;">#define ADDRESS_COUNT 9</span><br />
<span style="color: #993333;">int</span> addresses<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">9</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #208080;">0x0001</span><span style="color: #339933;">,</span><br />
&nbsp; <span style="color: #208080;">0x0002</span><span style="color: #339933;">,</span><br />
&nbsp; <span style="color: #208080;">0x0003</span><span style="color: #339933;">,</span><br />
&nbsp; <span style="color: #208080;">0x0004</span><span style="color: #339933;">,</span><br />
&nbsp; <span style="color: #208080;">0x0005</span><span style="color: #339933;">,</span><br />
&nbsp; <span style="color: #208080;">0x0006</span><span style="color: #339933;">,</span><br />
&nbsp; <span style="color: #208080;">0x0007</span><span style="color: #339933;">,</span><br />
&nbsp; <span style="color: #208080;">0x0008</span><span style="color: #339933;">,</span><br />
&nbsp; <span style="color: #208080;">0x0009</span><span style="color: #339933;">,</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #993333;">void</span> setup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; Serial.<span style="color: #202020;">begin</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">9600</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; randomSeed<span style="color: #009900;">&#40;</span>analogRead<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #993333;">void</span> loop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> i <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>i <span style="color: #339933;">&lt;</span> ADDRESS_COUNT<span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><br />
&nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>random<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1000</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">990</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>random<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1000</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">500</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; sendPseudoPackage<span style="color: #009900;">&#40;</span>addresses<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">else</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; sendPseudoPackage<span style="color: #009900;">&#40;</span>addresses<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; delay<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">50</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<br />
<span style="color: #993333;">void</span> sendPseudoPackage<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> address<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> value<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> &nbsp;<span style="color: #666666; font-style: italic;">// pass either a 0x4 or and 0x5 to turn the pin on or off</span><br />
&nbsp; Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #208080;">0x7E</span><span style="color: #339933;">,</span> BYTE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// start byte</span><br />
&nbsp; Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #208080;">0x0</span><span style="color: #339933;">,</span> BYTE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// high part of length (always zero)</span><br />
&nbsp; Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #208080;">0x17</span><span style="color: #339933;">,</span> BYTE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// low part of length (the number of bytes that follow, not including checksum)</span><br />
&nbsp; Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #208080;">0x92</span><span style="color: #339933;">,</span> BYTE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// 0x92 is I/O RX Packet</span><br />
<br />
&nbsp; <span style="color: #666666; font-style: italic;">//05-12: &nbsp;64-bit address</span><br />
&nbsp; Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #208080;">0x00</span><span style="color: #339933;">,</span>BYTE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #208080;">0x13</span><span style="color: #339933;">,</span>BYTE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #208080;">0xA2</span><span style="color: #339933;">,</span>BYTE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #208080;">0x00</span><span style="color: #339933;">,</span>BYTE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #208080;">0x40</span><span style="color: #339933;">,</span>BYTE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #208080;">0x33</span><span style="color: #339933;">,</span>BYTE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; <span style="color: #993333;">int</span> low <span style="color: #339933;">=</span> address <span style="color: #339933;">&amp;</span> <span style="color: #208080;">0xFF</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #993333;">int</span> high <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>address <span style="color: #339933;">-</span> low<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;&gt;</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span>high<span style="color: #339933;">,</span> BYTE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span>low<span style="color: #339933;">,</span> BYTE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
<br />
<br />
&nbsp; <span style="color: #666666; font-style: italic;">//13-14: &nbsp;16 bit of recipient or 0xFFFE if unknown</span><br />
&nbsp; Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #208080;">0xFF</span><span style="color: #339933;">,</span> BYTE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #208080;">0xFE</span><span style="color: #339933;">,</span> BYTE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; <span style="color: #666666; font-style: italic;">//15: &nbsp;Receive Option</span><br />
&nbsp; Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #208080;">0x01</span><span style="color: #339933;">,</span> BYTE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; <span style="color: #666666; font-style: italic;">//16: &nbsp;Num Samples</span><br />
&nbsp; Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #208080;">0x01</span><span style="color: #339933;">,</span> BYTE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; <span style="color: #666666; font-style: italic;">//17-18 Digital Channel Mask</span><br />
&nbsp; Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #208080;">0x00</span><span style="color: #339933;">,</span> BYTE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #208080;">0x01</span><span style="color: #339933;">,</span> BYTE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//only Digital I/O 0</span><br />
<br />
&nbsp; <span style="color: #666666; font-style: italic;">//19: &nbsp;Analog Channel Mask</span><br />
&nbsp; Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #208080;">0x00</span><span style="color: #339933;">,</span> BYTE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; <span style="color: #666666; font-style: italic;">//20-21: &nbsp;Digital Samples</span><br />
&nbsp; Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #208080;">0x00</span><span style="color: #339933;">,</span> BYTE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span>value<span style="color: #339933;">,</span> BYTE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; <span style="color: #666666; font-style: italic;">//no analog samples</span><br />
<br />
&nbsp; <span style="color: #666666; font-style: italic;">// checksum is all bytes after length bytes</span><br />
&nbsp; <span style="color: #993333;">long</span> sum <span style="color: #339933;">=</span> <span style="color: #208080;">0xFF</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//fake</span><br />
&nbsp; Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span> <span style="color: #208080;">0xFF</span> <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span> sum <span style="color: #339933;">&amp;</span> <span style="color: #208080;">0xFF</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">,</span> BYTE <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// calculate the proper checksum</span><br />
&nbsp; delay<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// safety pause to avoid overwhelming the serial port (if this function is not implemented properly)</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Then I wrote a basic processing sketch which filters the data and stores only changes to the databases. The sketch itself servers as some sort of realtime visualization on the input, and we get a feeling of how often data are changing and potentially detects sensor failures if one sensor is not active for a very long time.</p>
<p><object width="500" height="281"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=9819815&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=0&amp;show_portrait=0&amp;color=ffffff&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=9819815&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=0&amp;show_portrait=0&amp;color=ffffff&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="500" height="281"></embed></object></p>
<p>The processing sketch is sending data to a website that handles data logging. The website also provides query api that returns sensor history in json format, and functions like filtering by certain address. The site itself is lightweight and fairly easy to add new functionality.</p>
<p>The plan is to meet tomorrow and start building a web interface upon the api for the final visualization. Hopefully we could also get to verify if the pseudo data is identical to the real format, and maybe we can get a test run with the real setup.</p>
<p><del datetime="2010-03-24T04:37:19+00:00">Stay tuned!</del></p>
<p><strong>UPDATE</strong>: A list of available API functions:</p>
<p>url: http://itp.nyu.edu/~lx243/sensornet/index.php/api/</p>
<blockquote><p>all (meaning that the url will look like http://itp.nyu.edu/~lx243/sensornet/index.php/api/all)
</p></blockquote>
<p>returning all records in json format</p>
<blockquote><p>find/:address</p></blockquote>
<p>returning all records from address specified<br />
address should be a string of 64bit address, e.g. 0013A20040330001</p>
<blockquote><p>find_today/:address</p></blockquote>
<blockquote><p>find_by_day/:address/:day
</p></blockquote>
<p>day should be in the format of yyyymmdd, e.g. 20100301</p>
<blockquote><p>status/:address
</p></blockquote>
<p>returning latest records from specified address</p>
<blockquote><p>status_at/:address/:time
</p></blockquote>
<p>returning latest records by the time specified<br />
time should be in the format of yyyymmddHHMMSS, e.g. 20100301140000</p>
<blockquote><p>changes/:address
</p></blockquote>
<p>returning all changes at specified address</p>
<blockquote><p>changes_today/:address
</p></blockquote>
<p>returning changes happened today at specified address</p>
<blockquote><p>changes_by_day/:address/:day
</p></blockquote>
<p>returning changes happened today on specified date at specified address<br />
day should be in the format of yyyymmdd, e.g. 20100301</p>
<blockquote><p>stats/:address
</p></blockquote>
<p>returning open time, close time, changes, and total active time of the sensor</p>
<blockquote><p>stats_today/:address
</p></blockquote>
<p>returning above stats from specified address</p>
<blockquote><p>stats_by_day/:address/:day
</p></blockquote>
<p>returning above stats from specified address on specified day</p>
<p><strong>UPDATE 2</strong>: Visualization</p>
<p>It took a while for Sebastian and I to make processing.js to talk to the API and get real time update. We used jQuery as a bridge to retrieve the data and feed it on the page to processing.js.  But eventually all is fine:</p>
<p><a href="http://leejayxia.com/blog/wp-content/uploads/2010/03/Mozilla-Firefox.png" rel="lightbox[823]"><img src="http://leejayxia.com/blog/wp-content/uploads/2010/03/Mozilla-Firefox.png" alt="" title="Where is my professor?" width="797" height="284" class="alignnone size-full wp-image-840" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://leejayxia.com/blog/sensor-network-data-logging-and-visualization/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Storytelling stickers update</title>
		<link>http://leejayxia.com/blog/storytelling-stickers-update/</link>
		<comments>http://leejayxia.com/blog/storytelling-stickers-update/#comments</comments>
		<pubDate>Thu, 09 Apr 2009 22:28:27 +0000</pubDate>
		<dc:creator>L.J</dc:creator>
				<category><![CDATA[Toy Design]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[final]]></category>
		<category><![CDATA[ITP]]></category>
		<category><![CDATA[Processing]]></category>
		<category><![CDATA[RFID]]></category>
		<category><![CDATA[sound]]></category>
		<category><![CDATA[Spring 2009]]></category>
		<category><![CDATA[sticker]]></category>
		<category><![CDATA[toy]]></category>

		<guid isPermaLink="false">http://leejayxia.com/blog/?p=611</guid>
		<description><![CDATA[Wrapping up what&#8217;s happened to the storytelling stickers! THE READER The RFID reader is working! It took a while though. I did some search and ended up taking arduino codes from http://blog.formatlos.de/2008/12/08/arduino-id-12/ featuring the AF_SoftSerial library. It&#8217;s very well written and comprehensive. The scripts added a kicking off step and a disconnection detection as well. [...]]]></description>
			<content:encoded><![CDATA[<p>Wrapping up what&#8217;s happened to the <a href="http://leejayxia.com/blog/toy-design-proposal/">storytelling stickers</a>!</p>
<h3>THE READER</h3>
<p>The RFID reader is working! It took a while though. I did some search and ended up taking arduino codes from <a href="http://blog.formatlos.de/2008/12/08/arduino-id-12/">http://blog.formatlos.de/2008/12/08/arduino-id-12/</a> featuring the <a href="http://www.ladyada.net/make/eshield/AFSoftSerial.zip">AF_SoftSerial library</a>. It&#8217;s very well written and comprehensive. The scripts added a kicking off step and a disconnection detection as well. Great work! A simple processing sketch was made to display the identifier code. </p>
<p><object width="640" height="480"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=3933690&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=0&amp;show_portrait=0&amp;color=00ADEF&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=3933690&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=0&amp;show_portrait=0&amp;color=00ADEF&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="640" height="480"></embed></object></p>
<p>The tag needs to be really close to the reader to be recognized, which is fine in my project. But since I probably needs to get reading from both ends of a miniature trumpet/horn, that might not be good enough. I&#8217;m trying to build some antenna for the reader and see if it could extend the accessibility.  </p>
<h3>THE TAG</h3>
<p>The tags arrived too. I ordered 300 raw EM4001 RFID tags (meaning that they come with exposed coil antennae) and unfortunately a lot of them broke. A lot of soldering is ahead! But I got enough to start anyway, like a hundred.</p>
<p><a href="http://leejayxia.com/blog/wp-content/uploads/2009/04/image019.jpg" rel="lightbox[611]"><img src="http://leejayxia.com/blog/wp-content/uploads/2009/04/image019-300x225.jpg" alt="image019" title="image019" width="300" height="225" class="alignnone size-medium wp-image-616" /></a>&nbsp;<a href="http://leejayxia.com/blog/wp-content/uploads/2009/04/image017.jpg" rel="lightbox[611]"><img src="http://leejayxia.com/blog/wp-content/uploads/2009/04/image017-300x225.jpg" alt="image017" title="image017" width="300" height="225" class="alignnone size-medium wp-image-615" /></a>&nbsp;<a href="http://leejayxia.com/blog/wp-content/uploads/2009/04/image0251.jpg" rel="lightbox[611]"><img src="http://leejayxia.com/blog/wp-content/uploads/2009/04/image0251-300x225.jpg" alt="image0251" title="image0251" width="300" height="225" class="alignnone size-medium wp-image-617" /></a></p>
<h3>THE SOUND</h3>
<p>I got the <a href="http://www.ladyada.net/make/waveshield/">wave sound shield from Adafruit</a> and finished assembling while procrastinating. But I haven&#8217;t tried to use them because it doesn&#8217;t record to the card and I decided to fall back to use a computer in this phrase.</p>
<p>So now it works like this. Whenever a card/tag/sticker is seen/read, according to the mode an audio clip associated to the tag ID would be recorded or played, by the computer. All sound files are stored on the computer instead of any hardware/memory card as I previously planned. The processing sketch was adapted to keep track of a known card and pick the corresponding sound file to play/record. </p>
<p>[Videos to be uploaded soon]</p>
<div class="codecolorer-container java dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br />115<br />116<br />117<br />118<br />119<br />120<br />121<br />122<br />123<br />124<br />125<br />126<br />127<br />128<br />129<br />130<br />131<br />132<br />133<br />134<br />135<br />136<br />137<br />138<br />139<br />140<br />141<br />142<br />143<br />144<br />145<br />146<br />147<br />148<br />149<br />150<br />151<br />152<br />153<br />154<br />155<br />156<br />157<br />158<br />159<br />160<br />161<br />162<br />163<br />164<br />165<br />166<br />167<br />168<br />169<br />170<br />171<br />172<br />173<br />174<br />175<br />176<br />177<br />178<br />179<br />180<br />181<br />182<br />183<br />184<br />185<br />186<br />187<br />188<br />189<br />190<br />191<br />192<br />193<br />194<br />195<br />196<br />197<br />198<br />199<br />200<br />201<br />202<br />203<br />204<br />205<br />206<br />207<br />208<br />209<br />210<br />211<br />212<br />213<br />214<br />215<br />216<br />217<br />218<br />219<br />220<br />221<br />222<br />223<br />224<br />225<br />226<br />227<br />228<br />229<br />230<br />231<br />232<br />233<br />234<br />235<br />236<br />237<br />238<br />239<br />240<br />241<br />242<br />243<br />244<br />245<br />246<br />247<br />248<br />249<br />250<br />251<br />252<br />253<br />254<br />255<br />256<br />257<br />258<br />259<br />260<br />261<br />262<br />263<br />264<br />265<br />266<br />267<br />268<br />269<br />270<br />271<br />272<br />273<br />274<br />275<br />276<br />277<br />278<br />279<br />280<br />281<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">ddf.minim.signals.*</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">ddf.minim.*</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">ddf.minim.analysis.*</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">ddf.minim.effects.*</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">processing.serial.*</span><span style="color: #339933;">;</span><br />
<br />
Serial myPort<span style="color: #339933;">;</span><br />
<span style="color: #000066; font-weight: bold;">boolean</span> connected <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #003399;">String</span> activeTag <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Waiting...&quot;</span><span style="color: #339933;">;</span><br />
PFont f <span style="color: #339933;">=</span> createFont<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Helvetica&quot;</span>, <span style="color: #cc66cc;">50</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #003399;">Hashtable</span> cards<span style="color: #339933;">;</span><br />
Minim minim<span style="color: #339933;">;</span><br />
AudioInput in<span style="color: #339933;">;</span><br />
AudioRecorder recorder<span style="color: #339933;">;</span><br />
AudioPlayer player<span style="color: #339933;">;</span><br />
<br />
<span style="color: #003399;">String</span> previousCard <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span><br />
<span style="color: #000066; font-weight: bold;">boolean</span> playMode <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
<span style="color: #000066; font-weight: bold;">boolean</span> autoPilot <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">void</span> setup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; println<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;connecting...&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; myPort <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Serial<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>, Serial.<span style="color: #006633;">list</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span>, <span style="color: #cc66cc;">9600</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; myPort.<span style="color: #006633;">clear</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; cards <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Hashtable</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; loadCards<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; minim <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Minim<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; in <span style="color: #339933;">=</span> minim.<span style="color: #006633;">getLineIn</span><span style="color: #009900;">&#40;</span>Minim.<span style="color: #006633;">STEREO</span>, <span style="color: #cc66cc;">2048</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; size<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">800</span>,<span style="color: #cc66cc;">600</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; background<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; fill<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; noStroke<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; textAlign<span style="color: #009900;">&#40;</span>CENTER<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; textFont<span style="color: #009900;">&#40;</span>f<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; text<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;WAITING&quot;</span>,width <span style="color: #339933;">/</span> <span style="color: #cc66cc;">2</span>, height <span style="color: #339933;">/</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">void</span> draw<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; background<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>connected<span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; myPort.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'C'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">else</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; text<span style="color: #009900;">&#40;</span>activeTag,width <span style="color: #339933;">/</span> <span style="color: #cc66cc;">2</span>, height <span style="color: #339933;">/</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>playMode<span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;PLAYING&quot;</span>,width <span style="color: #339933;">/</span> <span style="color: #cc66cc;">2</span>, height <span style="color: #339933;">/</span> <span style="color: #cc66cc;">2</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">90</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;RECORDING&quot;</span>,width <span style="color: #339933;">/</span> <span style="color: #cc66cc;">2</span>, height <span style="color: #339933;">/</span> <span style="color: #cc66cc;">2</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">90</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>recorder <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stroke<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>playMode<span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>player <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> player.<span style="color: #006633;">left</span>.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; line<span style="color: #009900;">&#40;</span>i, <span style="color: #cc66cc;">50</span> <span style="color: #339933;">+</span> player.<span style="color: #006633;">left</span>.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">50</span>, i<span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">50</span> <span style="color: #339933;">+</span> player.<span style="color: #006633;">left</span>.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">50</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; line<span style="color: #009900;">&#40;</span>i, <span style="color: #cc66cc;">150</span> <span style="color: #339933;">+</span> player.<span style="color: #006633;">right</span>.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">50</span>, i<span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">150</span> <span style="color: #339933;">+</span> player.<span style="color: #006633;">right</span>.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">50</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> in.<span style="color: #006633;">bufferSize</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; line<span style="color: #009900;">&#40;</span>i, <span style="color: #cc66cc;">50</span> <span style="color: #339933;">+</span> in.<span style="color: #006633;">left</span>.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">50</span>, i<span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">50</span> <span style="color: #339933;">+</span> in.<span style="color: #006633;">left</span>.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">50</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; line<span style="color: #009900;">&#40;</span>i, <span style="color: #cc66cc;">150</span> <span style="color: #339933;">+</span> in.<span style="color: #006633;">right</span>.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">50</span>, i<span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">150</span> <span style="color: #339933;">+</span> in.<span style="color: #006633;">right</span>.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">50</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">void</span> closePlayer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>player <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">&amp;&amp;</span> player.<span style="color: #006633;">isPlaying</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; player.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">void</span> closeRecorder<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>recorder <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #666666; font-style: italic;">/* &amp;&amp; recorder.isRecording()*/</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; recorder.<span style="color: #006633;">endRecord</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; recorder.<span style="color: #006633;">save</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">void</span> loadCards<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; cards.<span style="color: #006633;">clear</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #003399;">String</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span>lines <span style="color: #339933;">=</span> loadStrings<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;index.txt&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>lines <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> lines.<span style="color: #006633;">length</span> <span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">String</span> card <span style="color: #339933;">=</span> trim<span style="color: #009900;">&#40;</span>lines<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; cards.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>card, <span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">void</span> dumpCards<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #003399;">PrintWriter</span> writer <span style="color: #339933;">=</span> createWriter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;data/index.txt&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Enumeration</span> e <span style="color: #339933;">=</span> cards.<span style="color: #006633;">keys</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span> e.<span style="color: #006633;">hasMoreElements</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span><span style="color: #009900;">&#41;</span> <br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">String</span> card <span style="color: #339933;">=</span> e.<span style="color: #006633;">nextElement</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; writer.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>card<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; writer.<span style="color: #006633;">flush</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; writer.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">void</span> serialEvent<span style="color: #009900;">&#40;</span>Serial port<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #003399;">String</span> myString <span style="color: #339933;">=</span> port.<span style="color: #006633;">readStringUntil</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">' '</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>myString <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; myString <span style="color: #339933;">=</span> trim<span style="color: #009900;">&#40;</span>myString<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>myString.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;connected&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; connected <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; println<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;connected~!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>myString.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;0000000000&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; activeTag <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Disconnected&quot;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>playMode <span style="color: #339933;">&amp;&amp;</span> player <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; println<span style="color: #009900;">&#40;</span>previousCard <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;: Disconnect from playing&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; closePlayer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; println<span style="color: #009900;">&#40;</span>previousCard <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;: Disconnect from recording&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; closeRecorder<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; previousCard <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; activeTag <span style="color: #339933;">=</span> myString<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>cards.<span style="color: #006633;">containsKey</span><span style="color: #009900;">&#40;</span>activeTag<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cards.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>activeTag,<span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dumpCards<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>autoPilot<span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; closePlayer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; playMode <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//auto switch to record &nbsp; &nbsp; &nbsp; </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; println<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Autopilot: switch to record mode&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #666666; font-style: italic;">//found</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>autoPilot<span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; playMode <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//auto switch to play&nbsp; </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; closeRecorder<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; println<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Autopilot: switch to play mode&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>playMode<span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>cards.<span style="color: #006633;">containsKey</span><span style="color: #009900;">&#40;</span>activeTag<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; println<span style="color: #009900;">&#40;</span>activeTag <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;: Start playing new file, disconnect from previous &quot;</span> <span style="color: #339933;">+</span> previousCard<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; closePlayer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; println<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;loading &quot;</span> <span style="color: #339933;">+</span> activeTag <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; to play&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; player <span style="color: #339933;">=</span> minim.<span style="color: #006633;">loadFile</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;data/&quot;</span> <span style="color: #339933;">+</span> activeTag <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;.wav&quot;</span>, <span style="color: #cc66cc;">2048</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; player.<span style="color: #006633;">play</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; player.<span style="color: #006633;">loop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; println<span style="color: #009900;">&#40;</span>activeTag <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;: Not recorded yet&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #666666; font-style: italic;">//record mode</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>activeTag <span style="color: #339933;">!=</span> previousCard<span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; println<span style="color: #009900;">&#40;</span>activeTag <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;: Start playing new file, disconnect from previous &quot;</span> <span style="color: #339933;">+</span> previousCard<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; closePlayer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; closeRecorder<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; recorder <span style="color: #339933;">=</span> minim.<span style="color: #006633;">createRecorder</span><span style="color: #009900;">&#40;</span>in, <span style="color: #0000ff;">&quot;data/&quot;</span> <span style="color: #339933;">+</span> activeTag <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;.wav&quot;</span>, <span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; recorder.<span style="color: #006633;">beginRecord</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; previousCard <span style="color: #339933;">=</span> activeTag<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">void</span> stop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; in.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; closePlayer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; closeRecorder<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; minim.<span style="color: #006633;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">void</span> keyPressed<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>key <span style="color: #339933;">==</span> <span style="color: #0000ff;">' '</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; playMode <span style="color: #339933;">=</span> <span style="color: #339933;">!</span>playMode<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>playMode<span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; println<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;play mode&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; println<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;record mode&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>key <span style="color: #339933;">==</span> <span style="color: #0000ff;">'a'</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; autoPilot <span style="color: #339933;">=</span> <span style="color: #339933;">!</span>autoPilot<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>autoPilot<span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; println<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Autopilot: ON&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; println<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Autopilot: OFF&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<h3>THE NAME</h3>
<p>Any thoughts on a name for the toy?</p>
]]></content:encoded>
			<wfw:commentRss>http://leejayxia.com/blog/storytelling-stickers-update/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Everyone with crazy ideas of the keyless entry must be living in a dorm!</title>
		<link>http://leejayxia.com/blog/everyone-with-crazy-ideas-of-the-keyless-entry-must-be-living-in-a-dorm/</link>
		<comments>http://leejayxia.com/blog/everyone-with-crazy-ideas-of-the-keyless-entry-must-be-living-in-a-dorm/#comments</comments>
		<pubDate>Fri, 07 Nov 2008 20:51:15 +0000</pubDate>
		<dc:creator>L.J</dc:creator>
				<category><![CDATA[Introduction to Physical Computing]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[keyless entry]]></category>

		<guid isPermaLink="false">http://leejayxia.com/blog/?p=288</guid>
		<description><![CDATA[I ran into this post today and apparently it&#8217;s a similar but much savvier implementation of my unlocking system. Really like the touch sensor use! What&#8217;s really sad is I was locked again outside my bedroom two weeks ago at midnight. I cannot always stick my arduino to the door. Nice work Alex! Check out [...]]]></description>
			<content:encoded><![CDATA[<p>I ran into <a href="http://students.washington.edu/acleone/projects/door/" target="_blank">this post</a> today and apparently it&#8217;s a similar but much savvier implementation of <a href="http://leejayxia.com/blog/solution-for-lockouts/" target="_blank">my unlocking system</a>.<br />
Really like the touch sensor use!</p>
<p>What&#8217;s really sad is I was locked again outside my bedroom two weeks ago at midnight. I cannot always stick my arduino to the door.</p>
<p>Nice work Alex!</p>
<p>Check out the video below:</p>
<p><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/GU8Ej0c2R14&#038;color1=0xb1b1b1&#038;color2=0xcfcfcf&#038;fs=1"></param><param name="allowFullScreen" value="true"></param><embed src="http://www.youtube.com/v/GU8Ej0c2R14&#038;color1=0xb1b1b1&#038;color2=0xcfcfcf&#038;fs=1" type="application/x-shockwave-flash" allowfullscreen="true" width="425" height="344"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://leejayxia.com/blog/everyone-with-crazy-ideas-of-the-keyless-entry-must-be-living-in-a-dorm/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>UPDATED: Pcom lab catch up and GO OUT</title>
		<link>http://leejayxia.com/blog/pcom-lab-catch-up/</link>
		<comments>http://leejayxia.com/blog/pcom-lab-catch-up/#comments</comments>
		<pubDate>Wed, 29 Oct 2008 15:59:59 +0000</pubDate>
		<dc:creator>L.J</dc:creator>
				<category><![CDATA[Introduction to Physical Computing]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[DC motor]]></category>
		<category><![CDATA[Michel Gondry]]></category>
		<category><![CDATA[Physical Computing]]></category>
		<category><![CDATA[Strand]]></category>
		<category><![CDATA[transister]]></category>
		<category><![CDATA[Week8]]></category>

		<guid isPermaLink="false">http://leejayxia.com/blog/?p=273</guid>
		<description><![CDATA[The transister lab looks fun because I like these DC motors since young. They have a unique smell while spinning really fast. In my impression they could work very well with just 2 AA battery (3V) in a toy car, so I&#8217;m curious about how would it be with 9 or 12V. First I hooked [...]]]></description>
			<content:encoded><![CDATA[<p>The transister lab looks fun because I like these DC motors since young. They have a unique smell while spinning really fast. In my impression they could work very well with just 2 AA battery (3V) in a toy car, so I&#8217;m curious about how would it be with 9 or 12V.</p>
<p>First I hooked up the circuit according to the website walkthrough, using the 9V output from the arduino. Surprisedly it didn&#8217;t work, even in the simplified program without the potentiameter. I checked the circuit for a couple of times and tried to hook the motor directly to the batteries, 5V from the arduino and 12V from the wall through the adapter, all approaches worked.</p>
<p>It came to me a sad conclusion that the 9V output on my arduino is broken. So I tested the circuit with the 9V from my another arduino and it worked. Is it that the arduino cannot output 5V and 9V at the same time? I haven&#8217;t tested this hypothesis yet.</p>
<p>some photos and videos (the motor was spinning so hard that I had to tape it to the board):</p>
<p><a href="http://leejayxia.com/blog/wp-content/uploads/2008/10/dsc04800.jpg" rel="lightbox[273]"><img class="alignnone size-medium wp-image-274" title="dsc04800" src="http://leejayxia.com/blog/wp-content/uploads/2008/10/dsc04800-300x225.jpg" alt="" width="300" height="225" /> </a><a href="http://leejayxia.com/blog/wp-content/uploads/2008/10/dsc04801.jpg" rel="lightbox[273]"><img class="alignnone size-medium wp-image-275" title="transister TIP120" src="http://leejayxia.com/blog/wp-content/uploads/2008/10/dsc04801-300x225.jpg" alt="" width="300" height="225" /></a></p>
<p><a href="http://leejayxia.com/blog/wp-content/uploads/2008/10/dsc04802.jpg" rel="lightbox[273]"><img class="alignnone size-medium wp-image-276" title="9V power from another arduino" src="http://leejayxia.com/blog/wp-content/uploads/2008/10/dsc04802-300x225.jpg" alt="" width="300" height="225" /> </a><a href="http://leejayxia.com/blog/wp-content/uploads/2008/10/dsc04803.jpg" rel="lightbox[273]"><img class="alignnone size-medium wp-image-277" title="transister lab" src="http://leejayxia.com/blog/wp-content/uploads/2008/10/dsc04803-300x225.jpg" alt="" width="300" height="225" /></a></p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="400" height="302" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://vimeo.com/moogaloop.swf?clip_id=2100064&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=ffffff&amp;fullscreen=1" /><embed type="application/x-shockwave-flash" width="400" height="302" src="http://vimeo.com/moogaloop.swf?clip_id=2100064&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=ffffff&amp;fullscreen=1" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="400" height="302" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://vimeo.com/moogaloop.swf?clip_id=2100071&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=ffffff&amp;fullscreen=1" /><embed type="application/x-shockwave-flash" width="400" height="302" src="http://vimeo.com/moogaloop.swf?clip_id=2100071&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=ffffff&amp;fullscreen=1" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p>I&#8217;l catch up with the H-bridge lab next week.</p>
<p>&#8212;&#8212; a happy going-out seperator &#8212;&#8212;</p>
<p>I was having a group meeting on a short film for commlab and someone just mentioned Michel Gondry while Marco turned around from the table beside and told us that Michel Gondry was going to give a talk right that evening at Strand. I hesitated for a while since I have another project due the next morning, but it was not long. We were really lucky that Marco got us there one hour earlier before the talk started at 7. Huge crowd started to gather since 6:30 and by then we were already sitting within 10 meters from the stage. I did take some photos but the memory card of my phone seems half broken and seriously it does not make much sense to take photo of people in a talk.</p>
<p>The talk started by showing some of Michel&#8217;s recent work, then a short interview between him and his PR guy, and another short video, and another short interview and so on. The screening including some excerpts from his latest film &#8220;be kind rewind&#8221; but my favorite is the music video he did for &#8220;Mad World&#8221; by Gary Jules and Michael Andrews. Not only Donnie Darko is one of my favorite and I love the song SOOOO MUUUCHHH but this music video is so moving and so well made in one long take. It&#8217;s like a combination of all my loved things. Check out the video below:</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="344" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/Kfcw2yEsabk&amp;hl=en&amp;fs=1" /><embed type="application/x-shockwave-flash" width="425" height="344" src="http://www.youtube.com/v/Kfcw2yEsabk&amp;hl=en&amp;fs=1" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p>Michel also talked about the &#8220;protocal&#8221; of filmmaking and sharing within the community. It&#8217;s more discussed in his new book that I haven&#8217;t read yet so I&#8217;m not sure I totally understand that. He actually accused his PR guy for charging too high on the book (?). And once while Michel is still talking the guy started to check the time, Michel suddenly stopped and turned to him and said &#8220;Don&#8217;t look at your watch while I&#8217;m still talking. It&#8217;s VERY rude.&#8221; It became a little bit awkward in the atmosphere for a while. But I like it.</p>
]]></content:encoded>
			<wfw:commentRss>http://leejayxia.com/blog/pcom-lab-catch-up/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CUBE was not built/burnt in a day</title>
		<link>http://leejayxia.com/blog/cube-was-not-builtburnt-in-a-day/</link>
		<comments>http://leejayxia.com/blog/cube-was-not-builtburnt-in-a-day/#comments</comments>
		<pubDate>Wed, 22 Oct 2008 16:12:27 +0000</pubDate>
		<dc:creator>L.J</dc:creator>
				<category><![CDATA[Introduction to Physical Computing]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[cube]]></category>
		<category><![CDATA[Fall 2008]]></category>
		<category><![CDATA[ITP]]></category>
		<category><![CDATA[microphone]]></category>
		<category><![CDATA[midterm]]></category>
		<category><![CDATA[Physical Computing]]></category>

		<guid isPermaLink="false">http://leejayxia.com/blog/?p=266</guid>
		<description><![CDATA[ACT 0: BRAINSTORMING THE CUBE ACT 1: ARDUINO ONLY SOUND ANALYSIS pcom midterm: microphone + arduino beat detection from Leejay Xia on Vimeo. pcom midterm: mircophone + arduinobeat detection log from Leejay Xia on Vimeo. ACT 2: THE MACHANICS pcom midterm: the skeleton from Leejay Xia on Vimeo. ACT 3: IT WORKED!!! pcom midterm: rhythm [...]]]></description>
			<content:encoded><![CDATA[<h2>ACT 0: BRAINSTORMING THE CUBE</h2>
<p><a href="http://leejayxia.com/blog/wp-content/uploads/2008/10/dsc04759.jpg" rel="lightbox[266]"><img class="alignnone size-medium wp-image-267" title="dsc04759" src="http://leejayxia.com/blog/wp-content/uploads/2008/10/dsc04759-300x197.jpg" alt="" width="300" height="197" /></a></p>
<h2>ACT 1: ARDUINO ONLY SOUND ANALYSIS</h2>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="400" height="302" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://vimeo.com/moogaloop.swf?clip_id=1997878&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=ffffff&amp;fullscreen=1" /><embed type="application/x-shockwave-flash" width="400" height="302" src="http://vimeo.com/moogaloop.swf?clip_id=1997878&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=ffffff&amp;fullscreen=1" allowscriptaccess="always" allowfullscreen="true"></embed></object><br />
<a href="http://vimeo.com/1997878?pg=embed&amp;sec=1997878">pcom midterm: microphone + arduino beat detection</a> from <a href="http://vimeo.com/user758219?pg=embed&amp;sec=1997878">Leejay Xia</a> on <a href="http://vimeo.com?pg=embed&amp;sec=1997878">Vimeo</a>.</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="400" height="302" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://vimeo.com/moogaloop.swf?clip_id=1997885&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=ffffff&amp;fullscreen=1" /><embed type="application/x-shockwave-flash" width="400" height="302" src="http://vimeo.com/moogaloop.swf?clip_id=1997885&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=ffffff&amp;fullscreen=1" allowscriptaccess="always" allowfullscreen="true"></embed></object><br />
<a href="http://vimeo.com/1997885?pg=embed&amp;sec=1997885">pcom midterm: mircophone + arduinobeat detection log</a> from <a href="http://vimeo.com/user758219?pg=embed&amp;sec=1997885">Leejay Xia</a> on <a href="http://vimeo.com?pg=embed&amp;sec=1997885">Vimeo</a>.</p>
<h2>ACT 2: THE MACHANICS</h2>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="400" height="302" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://vimeo.com/moogaloop.swf?clip_id=2037455&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=ffffff&amp;fullscreen=1" /><embed type="application/x-shockwave-flash" width="400" height="302" src="http://vimeo.com/moogaloop.swf?clip_id=2037455&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=ffffff&amp;fullscreen=1" allowscriptaccess="always" allowfullscreen="true"></embed></object><br />
<a href="http://vimeo.com/2037455?pg=embed&amp;sec=2037455">pcom midterm: the skeleton</a> from <a href="http://vimeo.com/user758219?pg=embed&amp;sec=2037455">Leejay Xia</a> on <a href="http://vimeo.com?pg=embed&amp;sec=2037455">Vimeo</a>.</p>
<h2>ACT 3: IT WORKED!!!</h2>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="400" height="302" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://vimeo.com/moogaloop.swf?clip_id=2037479&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=ffffff&amp;fullscreen=1" /><embed type="application/x-shockwave-flash" width="400" height="302" src="http://vimeo.com/moogaloop.swf?clip_id=2037479&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=ffffff&amp;fullscreen=1" allowscriptaccess="always" allowfullscreen="true"></embed></object><br />
<a href="http://vimeo.com/2037479?pg=embed&amp;sec=2037479">pcom midterm: rhythm awareness dance pattern</a> from <a href="http://vimeo.com/user758219?pg=embed&amp;sec=2037479">Leejay Xia</a> on <a href="http://vimeo.com?pg=embed&amp;sec=2037479">Vimeo</a>.</p>
<p>on two arduinos:</p>
<p><a href="http://leejayxia.com/blog/wp-content/uploads/2008/10/dsc00454.jpg" rel="lightbox[266]"><img class="alignnone size-medium wp-image-271" title="dsc00454" src="http://leejayxia.com/blog/wp-content/uploads/2008/10/dsc00454-300x223.jpg" alt="" width="300" height="223" /></a></p>
<h2>ACT 4: &#8230;UNTIL WE BURNT OUT THE CORE SERVO</h2>
<p>The only motion left was the up-down. But it still works!</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="400" height="302" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://vimeo.com/moogaloop.swf?clip_id=2037489&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=ffffff&amp;fullscreen=1" /><embed type="application/x-shockwave-flash" width="400" height="302" src="http://vimeo.com/moogaloop.swf?clip_id=2037489&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=ffffff&amp;fullscreen=1" allowscriptaccess="always" allowfullscreen="true"></embed></object><br />
<a href="http://vimeo.com/2037489?pg=embed&amp;sec=2037489">pcom midterm: dance!</a> from <a href="http://vimeo.com/user758219?pg=embed&amp;sec=2037489">Leejay Xia</a> on <a href="http://vimeo.com?pg=embed&amp;sec=2037489">Vimeo</a>.</p>
<h2>ACT 5: NOT THE WORST DANCE IN THE WORLD</h2>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="400" height="302" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://vimeo.com/moogaloop.swf?clip_id=2037505&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=ffffff&amp;fullscreen=1" /><embed type="application/x-shockwave-flash" width="400" height="302" src="http://vimeo.com/moogaloop.swf?clip_id=2037505&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=ffffff&amp;fullscreen=1" allowscriptaccess="always" allowfullscreen="true"></embed></object><br />
<a href="http://vimeo.com/2037505?pg=embed&amp;sec=2037505">pcom midterm: dance!</a> from <a href="http://vimeo.com/user758219?pg=embed&amp;sec=2037505">Leejay Xia</a> on <a href="http://vimeo.com?pg=embed&amp;sec=2037505">Vimeo</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://leejayxia.com/blog/cube-was-not-builtburnt-in-a-day/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>PCom Update: multiple serial input</title>
		<link>http://leejayxia.com/blog/multiple-serial-input/</link>
		<comments>http://leejayxia.com/blog/multiple-serial-input/#comments</comments>
		<pubDate>Wed, 15 Oct 2008 06:11:52 +0000</pubDate>
		<dc:creator>L.J</dc:creator>
				<category><![CDATA[Introduction to Physical Computing]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Fall 2008]]></category>
		<category><![CDATA[force sensor]]></category>
		<category><![CDATA[ITP]]></category>
		<category><![CDATA[Physical Computing]]></category>
		<category><![CDATA[Processing]]></category>
		<category><![CDATA[Serial]]></category>
		<category><![CDATA[simulation]]></category>
		<category><![CDATA[Week6]]></category>

		<guid isPermaLink="false">http://leejayxia.com/blog/?p=238</guid>
		<description><![CDATA[I&#8217;ve been mostly working on viz class and pcom mid term over the weekend. One big thing is I once made the eight-buck-deal RF Link work in the studio, but never succeeded in testing again since I went back to the dorm. I used software serial library to utilize digital pins as serial input/output and [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been mostly working on viz class and pcom mid term over the weekend. One big thing is I once made the eight-buck-deal RF Link work in the studio, but never succeeded in testing again since I went back to the dorm. I used software serial library to utilize digital pins as serial input/output and leave the original serial port for computer monitoring, but the RL Links still feel like a black box to me. The transmitter side looks working perfectly while I hooked up a USB cable and tried to read the TX stream, however the receiver side keeps getting rubbish data. More efforts are to be invested on this issue!!</p>
<p>Just a quick update on the multi-serial-input, shown as the video below (yes I still love my force sensors):</p>
<p><object width="400" height="302"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=1971879&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=ffffff&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=1971879&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=ffffff&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="302"></embed></object></p>
<p>It&#8217;s pretty simple, just using two serial inputs. But the concept of encoding data and protocol is pretty clear.</p>
<p>Arduino Code:</p>
<div class="codecolorer-container c dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br /></div></td><td><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333;">int</span> leftPin <span style="color: #339933;">=</span> <span style="color: #0000dd;">4</span><span style="color: #339933;">;</span><br />
<span style="color: #993333;">int</span> rightPin <span style="color: #339933;">=</span> <span style="color: #0000dd;">5</span><span style="color: #339933;">;</span><br />
<span style="color: #993333;">int</span> leftValue<span style="color: #339933;">,</span>rightValue<span style="color: #339933;">;</span><br />
<br />
<span style="color: #993333;">void</span> setup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; beginSerial<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">9600</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp;<span style="color: #666666; font-style: italic;">//set up communication back to pc</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #993333;">void</span> loop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; leftValue <span style="color: #339933;">=</span> analogRead<span style="color: #009900;">&#40;</span>leftPin<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
&nbsp; rightValue <span style="color: #339933;">=</span> analogRead<span style="color: #009900;">&#40;</span>rightPin<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
<br />
&nbsp; <span style="color: #666666; font-style: italic;">//if (abs(leftValue - rightValue) &gt; 50)</span><br />
&nbsp; <span style="color: #666666; font-style: italic;">//{</span><br />
&nbsp; &nbsp; Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span>leftValue<span style="color: #339933;">,</span>DEC<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">44</span><span style="color: #339933;">,</span>BYTE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span>rightValue<span style="color: #339933;">,</span>DEC<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">44</span><span style="color: #339933;">,</span>BYTE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; Serial.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #666666; font-style: italic;">//}</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Processing Code:</p>
<div class="codecolorer-container java dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">processing.serial.*</span><span style="color: #339933;">;</span><br />
<br />
Serial myPort<span style="color: #339933;">;</span><br />
<span style="color: #003399;">String</span> data<span style="color: #339933;">;</span><br />
<span style="color: #000066; font-weight: bold;">int</span> leftValue <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><br />
<span style="color: #000066; font-weight: bold;">int</span> rightValue <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">void</span> setup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; size<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">800</span>, <span style="color: #cc66cc;">600</span>, P3D<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; directionalLight<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">126</span>, <span style="color: #cc66cc;">126</span>, <span style="color: #cc66cc;">126</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; ambientLight<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">102</span>, <span style="color: #cc66cc;">102</span>, <span style="color: #cc66cc;">102</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; noStroke<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; myPort <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Serial<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>, Serial.<span style="color: #006633;">list</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span>, <span style="color: #cc66cc;">9600</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; ellipseMode<span style="color: #009900;">&#40;</span>CENTER<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">void</span> draw<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; background<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #000066; font-weight: bold;">float</span> leftR <span style="color: #339933;">=</span> map<span style="color: #009900;">&#40;</span>leftValue,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">1023</span>,<span style="color: #cc66cc;">0</span>,PI<span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #000066; font-weight: bold;">float</span> rightR <span style="color: #339933;">=</span> map<span style="color: #009900;">&#40;</span>rightValue,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">1023</span>,<span style="color: #cc66cc;">0</span>,PI<span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; translate<span style="color: #009900;">&#40;</span>width<span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span>, height<span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <br />
&nbsp; rotateX<span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span>PI<span style="color: #339933;">/</span><span style="color: #cc66cc;">12</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; rotateZ<span style="color: #009900;">&#40;</span>rightR <span style="color: #339933;">-</span> leftR<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; stroke<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">160</span>,<span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; fill<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">150</span>,<span style="color: #cc66cc;">150</span>,<span style="color: #cc66cc;">150</span>,<span style="color: #cc66cc;">90</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; box<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">500</span>,<span style="color: #cc66cc;">10</span>,<span style="color: #cc66cc;">100</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; translate<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <br />
&nbsp; noStroke<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; fill<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">255</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; translate<span style="color: #009900;">&#40;</span>map<span style="color: #009900;">&#40;</span>rightValue <span style="color: #339933;">-</span> leftValue,<span style="color: #339933;">-</span><span style="color: #cc66cc;">1023</span>,<span style="color: #cc66cc;">1023</span>,<span style="color: #339933;">-</span><span style="color: #cc66cc;">250</span>,<span style="color: #cc66cc;">250</span><span style="color: #009900;">&#41;</span>,<span style="color: #339933;">-</span><span style="color: #cc66cc;">25</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; sphere<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">void</span> serialEvent<span style="color: #009900;">&#40;</span>Serial p<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #003399;">String</span> input <span style="color: #339933;">=</span> p.<span style="color: #006633;">readStringUntil</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp;<span style="color: #666666; font-style: italic;">//make sure you return (Ascii 13) at the end of your transmission</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>input <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><br />
&nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> parts <span style="color: #339933;">=</span> input.<span style="color: #006633;">split</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;,&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp;<span style="color: #666666; font-style: italic;">//this will only work if you put commas (Ascii 44) between things in your transmission</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>parts.<span style="color: #006633;">length</span> <span style="color: #339933;">&gt;=</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//println(&quot;Raw Input: &quot; + input);</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>abs<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#40;</span>parts<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> leftValue<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; leftValue <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#40;</span>parts<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>abs<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#40;</span>parts<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> rightValue<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; rightValue <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#40;</span>parts<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
]]></content:encoded>
			<wfw:commentRss>http://leejayxia.com/blog/multiple-serial-input/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PCom: Serial Input in Processing</title>
		<link>http://leejayxia.com/blog/serial-input-in-processing/</link>
		<comments>http://leejayxia.com/blog/serial-input-in-processing/#comments</comments>
		<pubDate>Wed, 08 Oct 2008 15:42:33 +0000</pubDate>
		<dc:creator>L.J</dc:creator>
				<category><![CDATA[Introduction to Physical Computing]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Fall 2008]]></category>
		<category><![CDATA[force sensor]]></category>
		<category><![CDATA[ITP]]></category>
		<category><![CDATA[Physical Computing]]></category>
		<category><![CDATA[Processing]]></category>
		<category><![CDATA[Serial]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[Week5]]></category>

		<guid isPermaLink="false">http://leejayxia.com/blog/?p=229</guid>
		<description><![CDATA[I do enjoy the force sensor I got in week 5&#8242;s application class so I&#8217;ll definitely use it more in the assignment! First I revisited the processing codes I wrote for week 2, which now seems to be a total mess. I didn&#8217;t know about the serialEvent callback then so I parsed the serial input [...]]]></description>
			<content:encoded><![CDATA[<p>I do enjoy the force sensor I got in week 5&#8242;s application class so I&#8217;ll definitely use it more in the assignment!</p>
<p>First I revisited the processing codes I wrote for <a href="http://leejayxia.com/blog/physical-computing-week-2-analog/" target="_blank">week 2</a>, which now seems to be a total mess. I didn&#8217;t know about the serialEvent callback then so I parsed the serial input in the draw loop, and I didn&#8217;t use BYTE output in the arduino board so I need to parse it as string. It worked pretty well but the revised the version is much better.</p>
<p><object width="400" height="302"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=1913389&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=ff9933&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=1913389&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=ff9933&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="302"></embed></object></p>
<p>Codes:</p>
<div class="codecolorer-container java dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">processing.serial.*</span><span style="color: #339933;">;</span><br />
<br />
Serial myPort<span style="color: #339933;">;</span><br />
<span style="color: #000066; font-weight: bold;">int</span> window <span style="color: #339933;">=</span> <span style="color: #cc66cc;">800</span><span style="color: #339933;">;</span><br />
<span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> values <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#91;</span>window <span style="color: #339933;">-</span> <span style="color: #cc66cc;">100</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
<span style="color: #000066; font-weight: bold;">int</span> index <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><br />
<span style="color: #000066; font-weight: bold;">int</span> input <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">void</span> setup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; size<span style="color: #009900;">&#40;</span>window,window<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; background<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">30</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; smooth<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #666666; font-style: italic;">// List all the available serial ports:</span><br />
&nbsp; <span style="color: #666666; font-style: italic;">//println(Serial.list());</span><br />
&nbsp; myPort <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Serial<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>, Serial.<span style="color: #006633;">list</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span>, <span style="color: #cc66cc;">9600</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <br />
&nbsp; <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;</span>window <span style="color: #339933;">-</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><br />
&nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; values<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">void</span> draw<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; background<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">20</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> window <span style="color: #339933;">-</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><br />
&nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">int</span> j <span style="color: #339933;">=</span> i <span style="color: #339933;">+</span> index<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>j <span style="color: #339933;">&gt;=</span> <span style="color: #009900;">&#40;</span>window <span style="color: #339933;">-</span> <span style="color: #cc66cc;">100</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; j <span style="color: #339933;">=</span> j <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span>window <span style="color: #339933;">-</span> <span style="color: #cc66cc;">100</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; stroke<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">255</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">80</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; line<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">50</span> <span style="color: #339933;">+</span> i, <span style="color: #009900;">&#40;</span>window <span style="color: #339933;">-</span> <span style="color: #cc66cc;">50</span><span style="color: #009900;">&#41;</span>, <span style="color: #cc66cc;">50</span> <span style="color: #339933;">+</span> i, <span style="color: #009900;">&#40;</span>window <span style="color: #339933;">-</span> <span style="color: #cc66cc;">50</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span>values<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span> <span style="color: #339933;">*</span> <span style="color: #009900;">&#40;</span>window <span style="color: #339933;">-</span> <span style="color: #cc66cc;">100</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #cc66cc;">1024</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; stroke<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">255</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">100</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; point<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">50</span> <span style="color: #339933;">+</span> i, <span style="color: #009900;">&#40;</span>window <span style="color: #339933;">-</span> <span style="color: #cc66cc;">50</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; point<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">50</span> <span style="color: #339933;">+</span> i, <span style="color: #009900;">&#40;</span>window <span style="color: #339933;">-</span> <span style="color: #cc66cc;">50</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span>values<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span> <span style="color: #339933;">*</span> <span style="color: #009900;">&#40;</span>window <span style="color: #339933;">-</span> <span style="color: #cc66cc;">100</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #cc66cc;">1024</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">void</span> serialEvent<span style="color: #009900;">&#40;</span>Serial p<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; input <span style="color: #339933;">=</span> p.<span style="color: #006633;">read</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; println<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;input:&quot;</span> <span style="color: #339933;">+</span> input<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; values<span style="color: #009900;">&#91;</span>index<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> input <span style="color: #339933;">*</span> <span style="color: #cc66cc;">4</span><span style="color: #339933;">;</span><br />
&nbsp; index<span style="color: #339933;">++;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>index <span style="color: #339933;">&gt;=</span> window <span style="color: #339933;">-</span> <span style="color: #cc66cc;">100</span><span style="color: #009900;">&#41;</span><br />
&nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; index <span style="color: #339933;">=</span> index <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span>window <span style="color: #339933;">-</span> <span style="color: #cc66cc;">100</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Then I thought about the nature of the force sensor and really wished I could visualize the &#8220;force&#8221; in the processing. So I adopted the &#8220;string&#8221; example bundled in the processing application and integrated it with the serial input.</p>
<p><object width="400" height="302"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=1913399&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=ff9933&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=1913399&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=ff9933&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="302"></embed></object></p>
<p>Codes:</p>
<div class="codecolorer-container java dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">processing.serial.*</span><span style="color: #339933;">;</span><br />
<span style="color: #666666; font-style: italic;">// The serial port:</span><br />
Serial myPort<span style="color: #339933;">;</span><br />
<span style="color: #000066; font-weight: bold;">int</span> input <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><br />
<span style="color: #000066; font-weight: bold;">int</span> lastInput <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;">// Spring drawing constants for top bar</span><br />
<span style="color: #000066; font-weight: bold;">int</span> s_height <span style="color: #339933;">=</span> <span style="color: #cc66cc;">16</span><span style="color: #339933;">;</span> &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Height</span><br />
<span style="color: #000066; font-weight: bold;">int</span> left <span style="color: #339933;">=</span> <span style="color: #cc66cc;">150</span><span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Left position</span><br />
<span style="color: #000066; font-weight: bold;">int</span> right <span style="color: #339933;">=</span> <span style="color: #cc66cc;">250</span><span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Right position</span><br />
<span style="color: #000066; font-weight: bold;">int</span> max <span style="color: #339933;">=</span> <span style="color: #cc66cc;">300</span><span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Maximum Y value</span><br />
<span style="color: #000066; font-weight: bold;">int</span> min <span style="color: #339933;">=</span> <span style="color: #cc66cc;">20</span><span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #666666; font-style: italic;">// Minimum Y value</span><br />
<span style="color: #000066; font-weight: bold;">boolean</span> over <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span> &nbsp;<span style="color: #666666; font-style: italic;">// If mouse over</span><br />
<span style="color: #000066; font-weight: bold;">boolean</span> move <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span> &nbsp;<span style="color: #666666; font-style: italic;">// If mouse down and over</span><br />
<br />
<span style="color: #666666; font-style: italic;">// Spring simulation constants</span><br />
<span style="color: #000066; font-weight: bold;">float</span> M <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0.8</span><span style="color: #339933;">;</span> &nbsp; <span style="color: #666666; font-style: italic;">// Mass</span><br />
<span style="color: #000066; font-weight: bold;">float</span> K <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0.2</span><span style="color: #339933;">;</span> &nbsp; <span style="color: #666666; font-style: italic;">// Spring constant</span><br />
<span style="color: #000066; font-weight: bold;">float</span> D <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0.92</span><span style="color: #339933;">;</span> &nbsp;<span style="color: #666666; font-style: italic;">// Damping</span><br />
<span style="color: #000066; font-weight: bold;">float</span> R <span style="color: #339933;">=</span> <span style="color: #cc66cc;">60</span><span style="color: #339933;">;</span> &nbsp; &nbsp;<span style="color: #666666; font-style: italic;">// Rest position</span><br />
<br />
<span style="color: #666666; font-style: italic;">// Spring simulation variables</span><br />
<span style="color: #000066; font-weight: bold;">float</span> ps <span style="color: #339933;">=</span> <span style="color: #cc66cc;">60.0</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Position</span><br />
<span style="color: #000066; font-weight: bold;">float</span> vs <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0.0</span><span style="color: #339933;">;</span> &nbsp;<span style="color: #666666; font-style: italic;">// Velocity</span><br />
<span style="color: #000066; font-weight: bold;">float</span> as <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> &nbsp; &nbsp;<span style="color: #666666; font-style: italic;">// Acceleration</span><br />
<span style="color: #000066; font-weight: bold;">float</span> f <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Force</span><br />
<br />
<br />
<span style="color: #000066; font-weight: bold;">void</span> setup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; size<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">400</span>, <span style="color: #cc66cc;">400</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; rectMode<span style="color: #009900;">&#40;</span>CORNERS<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; noStroke<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; myPort <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Serial<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>, Serial.<span style="color: #006633;">list</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span>, <span style="color: #cc66cc;">9600</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">void</span> draw<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; background<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">102</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; updateSpring<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; drawSpring<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">void</span> drawSpring<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #666666; font-style: italic;">// Draw base</span><br />
&nbsp; fill<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0.2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #000066; font-weight: bold;">float</span> b_width <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0.5</span> <span style="color: #339933;">*</span> ps <span style="color: #339933;">+</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">8</span><span style="color: #339933;">;</span><br />
&nbsp; rect<span style="color: #009900;">&#40;</span>width<span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span> <span style="color: #339933;">-</span> b_width, ps <span style="color: #339933;">+</span> s_height, width<span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span> <span style="color: #339933;">+</span> b_width, <span style="color: #cc66cc;">350</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<br />
<span style="color: #000066; font-weight: bold;">void</span> updateSpring<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #666666; font-style: italic;">// Update the spring position</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>move<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; f <span style="color: #339933;">=</span> <span style="color: #339933;">-</span>K <span style="color: #339933;">*</span> <span style="color: #009900;">&#40;</span>ps <span style="color: #339933;">-</span> R<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; &nbsp;<span style="color: #666666; font-style: italic;">// f=-ky</span><br />
&nbsp; &nbsp; as <span style="color: #339933;">=</span> f <span style="color: #339933;">/</span> M<span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Set the acceleration, f=ma == a=f/m</span><br />
&nbsp; &nbsp; vs <span style="color: #339933;">=</span> D <span style="color: #339933;">*</span> <span style="color: #009900;">&#40;</span>vs <span style="color: #339933;">+</span> as<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; <span style="color: #666666; font-style: italic;">// Set the velocity</span><br />
&nbsp; &nbsp; ps <span style="color: #339933;">=</span> ps <span style="color: #339933;">+</span> vs<span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Updated position</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>abs<span style="color: #009900;">&#40;</span>vs<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">0.1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; vs <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0.0</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; <span style="color: #666666; font-style: italic;">// Test if mouse is over the top bar</span><br />
&nbsp; <span style="color: #666666; font-style: italic;">/*<br />
&nbsp; if(mouseX &gt; left &amp;&amp; mouseX &lt; right &amp;&amp; mouseY &gt; ps &amp;&amp; mouseY &lt; ps + s_height) {<br />
&nbsp; &nbsp; over = true;<br />
&nbsp; } else {<br />
&nbsp; &nbsp; over = false;<br />
&nbsp; }<br />
&nbsp; */</span><br />
&nbsp; <br />
&nbsp; <span style="color: #666666; font-style: italic;">// Set and constrain the position of top bar</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>move<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; ps <span style="color: #339933;">=</span> map<span style="color: #009900;">&#40;</span>input,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">255</span>,min,max<span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> s_height<span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>ps <span style="color: #339933;">&lt;</span> min<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> ps <span style="color: #339933;">=</span> min<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> <br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>ps <span style="color: #339933;">&gt;</span> max<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> ps <span style="color: #339933;">=</span> max<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">void</span> serialEvent<span style="color: #009900;">&#40;</span>Serial p<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; input <span style="color: #339933;">=</span> p.<span style="color: #006633;">read</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; println<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;input:&quot;</span> <span style="color: #339933;">+</span> input<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <br />
&nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>input <span style="color: #339933;">&gt;</span> lastInput<span style="color: #009900;">&#41;</span><br />
&nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; move <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>lastInput <span style="color: #339933;">&gt;</span> input <span style="color: #339933;">+</span> <span style="color: #cc66cc;">10</span> <span style="color: #339933;">||</span> input <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><br />
&nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; move <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; <br />
&nbsp; lastInput <span style="color: #339933;">=</span> input<span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
]]></content:encoded>
			<wfw:commentRss>http://leejayxia.com/blog/serial-input-in-processing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Solution for Lockouts</title>
		<link>http://leejayxia.com/blog/solution-for-lockouts/</link>
		<comments>http://leejayxia.com/blog/solution-for-lockouts/#comments</comments>
		<pubDate>Wed, 01 Oct 2008 07:18:57 +0000</pubDate>
		<dc:creator>L.J</dc:creator>
				<category><![CDATA[Introduction to Physical Computing]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Fall 2008]]></category>
		<category><![CDATA[ITP]]></category>
		<category><![CDATA[lockout]]></category>
		<category><![CDATA[Physical Computing]]></category>
		<category><![CDATA[servomotor]]></category>
		<category><![CDATA[Week4]]></category>

		<guid isPermaLink="false">http://leejayxia.com/blog/?p=192</guid>
		<description><![CDATA[Lockouts are irritating. especially when you live in a dorm, at midnight, your roommate is sleeping, and backup keys are two hours away. Here&#8217;s the self-service solution. I should have made a much more complex combination lock with multiple sensors and flexible customization functionalities, but it&#8217;s two in the morning&#8230; so maybe next time&#8230; Secret [...]]]></description>
			<content:encoded><![CDATA[<p>Lockouts are irritating. especially when you live in a dorm, at midnight, your roommate is sleeping, and backup keys are two hours away. </p>
<p>Here&#8217;s the self-service solution. </p>
<p><object width="400" height="302"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=1856583&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=ff9933&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=1856583&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=ff9933&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="302"></embed></object></p>
<p>I should have made a much more complex combination lock with multiple sensors and flexible customization functionalities, but it&#8217;s two in the morning&#8230; so maybe next time&#8230;</p>
<p>Secret revealed. </p>
<p><object width="400" height="302"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=1856584&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=ff9933&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=1856584&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=ff9933&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="302"></embed></object></p>
<p>It&#8217;s kind of low tech in the backstage. All we need are: arduino, plus a servomotor, and, <strong><em>gravity</em></strong>. 8 quarter coins are used as weight. So it&#8217;s basically a two dollar solution! (what? the arduino? breadboard  servomotor and all the lab kits? well&#8230;)</p>
<p>More pictures:</p>
<p><a href="http://leejayxia.com/blog/wp-content/uploads/2008/10/dsc04742.jpg" rel="lightbox[192]"><img src="http://leejayxia.com/blog/wp-content/uploads/2008/10/dsc04742-300x225.jpg" alt="" title="dsc04742" width="300" height="225" class="alignnone size-medium wp-image-200" /></a>&nbsp;<a href="http://leejayxia.com/blog/wp-content/uploads/2008/10/dsc04741.jpg" rel="lightbox[192]"><img src="http://leejayxia.com/blog/wp-content/uploads/2008/10/dsc04741-300x225.jpg" alt="" title="dsc04741" width="300" height="225" class="alignnone size-medium wp-image-199" /></a>&nbsp;<a href="http://leejayxia.com/blog/wp-content/uploads/2008/10/dsc04740.jpg" rel="lightbox[192]"><img src="http://leejayxia.com/blog/wp-content/uploads/2008/10/dsc04740-300x225.jpg" alt="" title="dsc04740" width="300" height="225" class="alignnone size-medium wp-image-198" /></a></p>
<p><a href="http://leejayxia.com/blog/wp-content/uploads/2008/10/dsc04736.jpg" rel="lightbox[192]"><img src="http://leejayxia.com/blog/wp-content/uploads/2008/10/dsc04736-300x225.jpg" alt="" title="dsc04736" width="300" height="225" class="alignnone size-medium wp-image-195" /></a>&nbsp;<a href="http://leejayxia.com/blog/wp-content/uploads/2008/10/dsc04737.jpg" rel="lightbox[192]"><img src="http://leejayxia.com/blog/wp-content/uploads/2008/10/dsc04737-300x225.jpg" alt="" title="dsc04737" width="300" height="225" class="alignnone size-medium wp-image-196" /></a>&nbsp;<a href="http://leejayxia.com/blog/wp-content/uploads/2008/10/dsc04738.jpg" rel="lightbox[192]"><img src="http://leejayxia.com/blog/wp-content/uploads/2008/10/dsc04738-300x225.jpg" alt="" title="dsc04738" width="300" height="225" class="alignnone size-medium wp-image-197" /></a></p>
<p>bonus video &#8211; playing servomotor with force sensor (warning: not fun to watch at all)</p>
<p><object width="400" height="302"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=1856578&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=ff9933&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=1856578&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=ff9933&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="302"></embed></object></p>
<p>Thanks Li for the force sensor! We&#8221;ll have to talk!</p>
]]></content:encoded>
			<wfw:commentRss>http://leejayxia.com/blog/solution-for-lockouts/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Physical Computing Week 2: Analog!</title>
		<link>http://leejayxia.com/blog/physical-computing-week-2-analog/</link>
		<comments>http://leejayxia.com/blog/physical-computing-week-2-analog/#comments</comments>
		<pubDate>Wed, 17 Sep 2008 15:11:07 +0000</pubDate>
		<dc:creator>L.J</dc:creator>
				<category><![CDATA[Introduction to Physical Computing]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Fall 2008]]></category>
		<category><![CDATA[ITP]]></category>
		<category><![CDATA[Physical Computing]]></category>
		<category><![CDATA[Processing]]></category>
		<category><![CDATA[Week2]]></category>

		<guid isPermaLink="false">http://leejayxia.com/blog/?p=100</guid>
		<description><![CDATA[Hooking up the following stuff according to the diagram was easy and quick. And a resister of 220 10K Om is working ideally to create an ouput range of 0 &#8211; 930 (from total darkness to direct shine of torchlight) for the photocell. I changed the switch from last week to a much smaller one [...]]]></description>
			<content:encoded><![CDATA[<p>Hooking up the following stuff according to <a href="http://www.tigoe.net/pcomp/code/input-output/analog-input" target="_blank">the diagram</a> was easy and quick. And a resister of <del datetime="2008-09-18T02:39:37+00:00">220</del> 10K Om is working ideally to create an ouput range of 0 &#8211; 930 (from total darkness to direct shine of torchlight) for the photocell.</p>
<p>I changed the switch from last week to a much smaller one which could be inserted right into the breadboard, to get rid of the mess of the hookup wires. The output was quite straightforward in the arduino console window, so I decided to connect the output to the <a href="http://processing.org/reference/libraries/serial/index.html" target="_blank">processing</a>. </p>
<p>This is how it works:<br />
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="400" height="300" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://vimeo.com/moogaloop.swf?clip_id=1750802&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" /><embed type="application/x-shockwave-flash" width="400" height="300" src="http://vimeo.com/moogaloop.swf?clip_id=1750802&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" allowscriptaccess="always" allowfullscreen="true"></embed></object><br />
<a href="http://vimeo.com/1750802?pg=embed&amp;sec=1750802">Physical Computing Week 2</a> from <a href="http://vimeo.com/user758219?pg=embed&amp;sec=1750802">Leejay Xia</a> on <a href="http://vimeo.com?pg=embed&amp;sec=1750802">Vimeo</a>.</p>
<p>(Quick and Dirty) Code for Processing, it&#8217;s based on the example on their site</p>
<div class="codecolorer-container java dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">processing.serial.*</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;">// The serial port:</span><br />
Serial myPort<span style="color: #339933;">;</span><br />
<span style="color: #000066; font-weight: bold;">int</span> window <span style="color: #339933;">=</span> <span style="color: #cc66cc;">400</span><span style="color: #339933;">;</span><br />
<span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> values <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#91;</span>window <span style="color: #339933;">-</span> <span style="color: #cc66cc;">100</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
<span style="color: #000066; font-weight: bold;">int</span> index <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">void</span> setup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; size<span style="color: #009900;">&#40;</span>window,window<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; background<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; smooth<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #666666; font-style: italic;">// List all the available serial ports:</span><br />
&nbsp; println<span style="color: #009900;">&#40;</span>Serial.<span style="color: #006633;">list</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; myPort <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Serial<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>, Serial.<span style="color: #006633;">list</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span>, <span style="color: #cc66cc;">9600</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;</span>window <span style="color: #339933;">-</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><br />
&nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; values<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">void</span> draw<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>myPort.<span style="color: #006633;">available</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <br />
&nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #003399;">String</span> inBuffer <span style="color: #339933;">=</span> myPort.<span style="color: #006633;">readString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> vals <span style="color: #339933;">=</span> splitTokens<span style="color: #009900;">&#40;</span>inBuffer<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;</span>vals.<span style="color: #006633;">length</span><span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; values<span style="color: #009900;">&#91;</span>index<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#40;</span>vals<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//println(index+&quot;:&quot;+values[index]+&quot;/&quot;+vals[i]);</span><br />
&nbsp; &nbsp; &nbsp; index<span style="color: #339933;">++;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>index <span style="color: #339933;">&gt;=</span> window <span style="color: #339933;">-</span> <span style="color: #cc66cc;">100</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; index <span style="color: #339933;">=</span> index <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span>window <span style="color: #339933;">-</span> <span style="color: #cc66cc;">100</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; background<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> window <span style="color: #339933;">-</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">int</span> j <span style="color: #339933;">=</span> i <span style="color: #339933;">+</span> index<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>j <span style="color: #339933;">&gt;=</span> <span style="color: #009900;">&#40;</span>window <span style="color: #339933;">-</span> <span style="color: #cc66cc;">100</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; j <span style="color: #339933;">=</span> j <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span>window <span style="color: #339933;">-</span> <span style="color: #cc66cc;">100</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; stroke<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">255</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">90</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; line<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">50</span> <span style="color: #339933;">+</span> i, <span style="color: #009900;">&#40;</span>window <span style="color: #339933;">-</span> <span style="color: #cc66cc;">50</span><span style="color: #009900;">&#41;</span>, <span style="color: #cc66cc;">50</span> <span style="color: #339933;">+</span> i, <span style="color: #009900;">&#40;</span>window <span style="color: #339933;">-</span> <span style="color: #cc66cc;">50</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span>values<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span> <span style="color: #339933;">*</span> <span style="color: #009900;">&#40;</span>window <span style="color: #339933;">-</span> <span style="color: #cc66cc;">100</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #cc66cc;">1024</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; stroke<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">255</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">100</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; point<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">50</span> <span style="color: #339933;">+</span> i, <span style="color: #009900;">&#40;</span>window <span style="color: #339933;">-</span> <span style="color: #cc66cc;">50</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; point<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">50</span> <span style="color: #339933;">+</span> i, <span style="color: #009900;">&#40;</span>window <span style="color: #339933;">-</span> <span style="color: #cc66cc;">50</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span>values<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span> <span style="color: #339933;">*</span> <span style="color: #009900;">&#40;</span>window <span style="color: #339933;">-</span> <span style="color: #cc66cc;">100</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #cc66cc;">1024</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Notes-taking:</p>
<ul>
<li> I tried also the Thermistors but have not yet find a right resister to tune its output range.</li>
<li> In the current codes, the arduino board must be plugged before the processing applet runs.<br />
This is because the processing init code cannot find a usable serial port to initialize the object. And so far I didn&#8217;t see a possible way to initialize it during the draw() loop due to the lack of a try/catch machanism. More exploration to go!
</li>
<li>
The serial port transmits data much faster than the draw() function loops. Thus everytime we arrive in the draw() loop there might be a bunch of values waited in the buffer. These values need to be splited and stored accordingly. Of course a more complex protocal could be created to sample specific data or behavior.
</li>
</ul>
<p>More Photos:<br />
<a href="http://leejayxia.com/blog/wp-content/uploads/2008/09/dsc04616.jpg" rel="lightbox[100]"><img class="alignnone size-medium wp-image-103" title="dsc04616" src="http://leejayxia.com/blog/wp-content/uploads/2008/09/dsc04616-300x225.jpg" alt="" width="300" height="225" /></a> <a href="http://leejayxia.com/blog/wp-content/uploads/2008/09/dsc04614.jpg" rel="lightbox[100]"><img class="alignnone size-medium wp-image-101" title="dsc04614" src="http://leejayxia.com/blog/wp-content/uploads/2008/09/dsc04614-300x225.jpg" alt="" width="300" height="225" /></a> <a href="http://leejayxia.com/blog/wp-content/uploads/2008/09/dsc04617.jpg" rel="lightbox[100]"><img class="alignnone size-medium wp-image-104" title="dsc04617" src="http://leejayxia.com/blog/wp-content/uploads/2008/09/dsc04617-300x225.jpg" alt="" width="300" height="225" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://leejayxia.com/blog/physical-computing-week-2-analog/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Digital I/O with Arduino</title>
		<link>http://leejayxia.com/blog/digital-io-with-arduino/</link>
		<comments>http://leejayxia.com/blog/digital-io-with-arduino/#comments</comments>
		<pubDate>Wed, 10 Sep 2008 06:02:49 +0000</pubDate>
		<dc:creator>L.J</dc:creator>
				<category><![CDATA[Introduction to Physical Computing]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Fall 2008]]></category>
		<category><![CDATA[ITP]]></category>
		<category><![CDATA[Physical Computing]]></category>
		<category><![CDATA[Week1]]></category>

		<guid isPermaLink="false">http://leejayxia.com/blog/?p=4</guid>
		<description><![CDATA[I bought my first Arduino boards in 2007 and never touched them again ever since setting up the famous &#8220;blinking LED&#8221; code sample. It does recall some memory when I have my hands on the chips and boards and wires and stuff&#8230; again. The Arduino I have is an old NG(Nuova Generazione) rev C, which [...]]]></description>
			<content:encoded><![CDATA[<p>I bought my first <a href="http://www.arduino.cc/en/Main/Boards" target="_blank">Arduino boards</a> in 2007 and never touched them again ever since setting up the famous &#8220;blinking LED&#8221; code sample. It does recall some memory when I have my hands on the chips and boards and wires and stuff&#8230; again.</p>
<p>The Arduino I have is an old NG(Nuova Generazione) rev C, which is later replaced by the most popular &#8220;Diecimila&#8221;. <del datetime="2008-09-11T04:11:16+00:00">It comes with a less popular <a href="http://en.wikipedia.org/wiki/Image:Types-usb.svg" target="_blank">USB Type B</a> port, and t</del>The user would need to manually click the reset button before uploading the program to the board.</p>
<p>However there&#8217;s is still a good thing about it that it does provide a PIN 13 for LED with built-in resister. Hence it requires least effort to setup a minimum &#8220;Blinking LED&#8221; sample. You don&#8217;t even need a breadboard.</p>
<p><a href="http://leejayxia.com/blog/wp-content/uploads/2008/09/dsc04578.jpg" rel="lightbox[4]"><img class="alignnone size-medium wp-image-11" title="dsc04578" src="http://leejayxia.com/blog/wp-content/uploads/2008/09/dsc04578_400_300.jpg" alt="" /></a></p>
<p>Adding digital input is fun. I decided to leave the LED output as is now that it&#8217;s working fine with the preset PIN 13, in the good wishes that I would not mess up too much with the breadboard. </p>
<p><a href="http://leejayxia.com/blog/wp-content/uploads/2008/09/dsc04577.jpg" rel="lightbox[4]"><img class="alignnone size-medium wp-image-8" title="dsc04577" src="http://leejayxia.com/blog/wp-content/uploads/2008/09/dsc04577_400_300.jpg" alt="" width="400" height="300" /></a></p>
<p>B-O-O-M</p>
<p><a href="http://leejayxia.com/blog/wp-content/uploads/2008/09/dsc04583.jpg" rel="lightbox[4]"><img class="alignnone size-medium wp-image-13" title="dsc04583" src="http://leejayxia.com/blog/wp-content/uploads/2008/09/dsc04583_400_300.jpg" alt="" width="400" height="300" /></a></p>
<p>Check out the video as well!</p>
<p><object width="400" height="300"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=1764452&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=ff0179&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=1764452&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=ff0179&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="300"></embed></object></p>
<p><a href="http://leejayxia.com/blog/wp-content/uploads/2008/09/arduino_blinker_switch.3gp">arduino_blinker_switch</a></p>
<p>A small piece of code:</p>
<div class="codecolorer-container java dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000066; font-weight: bold;">int</span> ledPin <span style="color: #339933;">=</span> <span style="color: #cc66cc;">13</span><span style="color: #339933;">;</span> <br />
<span style="color: #000066; font-weight: bold;">int</span> switchPin <span style="color: #339933;">=</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">void</span> setup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
  pinMode<span style="color: #009900;">&#40;</span>ledPin, OUTPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>      <span style="color: #666666; font-style: italic;">// sets the digital pin as output</span><br />
  pinMode<span style="color: #009900;">&#40;</span>switchPin, INPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">void</span> loop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
  <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>digitalRead<span style="color: #009900;">&#40;</span>switchPin<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
  <span style="color: #009900;">&#123;</span><br />
    digitalWrite<span style="color: #009900;">&#40;</span>ledPin, HIGH<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   <span style="color: #666666; font-style: italic;">// sets the LED on</span><br />
    delay<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>                  <span style="color: #666666; font-style: italic;">// waits for a second</span><br />
    digitalWrite<span style="color: #009900;">&#40;</span>ledPin, LOW<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>    <span style="color: #666666; font-style: italic;">// sets the LED off</span><br />
    delay<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>                  <span style="color: #666666; font-style: italic;">// waits for a second</span><br />
  <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
]]></content:encoded>
			<wfw:commentRss>http://leejayxia.com/blog/digital-io-with-arduino/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="http://leejayxia.com/blog/wp-content/uploads/2008/09/arduino_blinker_switch.3gp" length="912207" type="video/3gpp" />
		</item>
	</channel>
</rss>

