<?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>C i b o M a h t o . c o m &#187; tech</title>
	<atom:link href="http://www.cibomahto.com/category/tech/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.cibomahto.com</link>
	<description>building making designing dreaming</description>
	<lastBuildDate>Thu, 25 Aug 2011 02:55:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Turn a Chumby into a tiny internet kiosk</title>
		<link>http://www.cibomahto.com/2011/08/turn-a-chumby-into-a-tiny-internet-kiosk/</link>
		<comments>http://www.cibomahto.com/2011/08/turn-a-chumby-into-a-tiny-internet-kiosk/#comments</comments>
		<pubDate>Thu, 25 Aug 2011 02:55:53 +0000</pubDate>
		<dc:creator>mahto</dc:creator>
				<category><![CDATA[tech]]></category>

		<guid isPermaLink="false">http://www.cibomahto.com/?p=1650</guid>
		<description><![CDATA[In a quest to earn a fine bottle of scotch (and help my friend Marty out with a project), I modified the Chumby web browser to be a full-screen kiosk. To make it work, just grab this file, unzip the &#8230; <a href="http://www.cibomahto.com/2011/08/turn-a-chumby-into-a-tiny-internet-kiosk/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.cibomahto.com/?attachment_id=1651" rel="attachment wp-att-1651"><img src="http://www.cibomahto.com/wp-content/uploads/2011/08/2011-08-24-22.27.04-600x450.jpg" alt="" title="SAMSUNG" width="600" height="450" class="alignnone size-medium wp-image-1651" /></a></p>
<p>In a quest to earn a fine bottle of scotch (and help my friend <a href="http://creatingwithcode.com/">Marty</a> out with a project), I modified the <a href="http://wiki.chumby.com/index.php/Web_Browser">Chumby web browser</a> to be a full-screen kiosk. To make it work, just <a href="http://cibomahto.com/files/insignia_infocast_fullscreen_browser.zip">grab this file</a>, unzip the contents into a usb stick or SD card, place the card in your Insignia, and reboot. You can change the URL that it loads by modifying the file debugchumby (use your desktop computer, the Chumby doesn&#8217;t seem to like writing to USB).</p>
<p>This can be used to make nice interfaces for the Chumby without having to learn flash or compile anything. Simply make a nice whiz-bang HTML page, and you should be good to go!</p>
<p>Source code for this super simple browser <a href='http://www.cibomahto.com/wp-content/uploads/2011/08/tinybrowser.zip'>is here</a>. Note that this is for the 8&#8243; Insignia Infocast branded machine. You can probably get it to work with the other Chumbys, but will need to recompile. Have fun!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cibomahto.com/2011/08/turn-a-chumby-into-a-tiny-internet-kiosk/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>The One-Hour Coasterbot</title>
		<link>http://www.cibomahto.com/2011/07/the-one-hour-coasterbot/</link>
		<comments>http://www.cibomahto.com/2011/07/the-one-hour-coasterbot/#comments</comments>
		<pubDate>Tue, 26 Jul 2011 04:05:26 +0000</pubDate>
		<dc:creator>mahto</dc:creator>
				<category><![CDATA[tech]]></category>

		<guid isPermaLink="false">http://www.cibomahto.com/?p=1631</guid>
		<description><![CDATA[Gareth just finished a Make: Projects version of the one-hour coasterbot build that I created for a contest last year. Thanks, Gareth!]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.cibomahto.com/?attachment_id=1639" rel="attachment wp-att-1639"><img src="http://www.cibomahto.com/wp-content/uploads/2011/07/DSC_3039-Modified.jpg" alt="" title="DSC_3039 (Modified)" width="600" height="450" class="alignnone size-full wp-image-1639" /></a></p>
<p>Gareth just finished a Make: Projects version of the <a href="http://makeprojects.com/Project/One-Hour-CoasterBot/1126/1">one-hour coasterbot build</a> that I created for a contest last year. Thanks, Gareth!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cibomahto.com/2011/07/the-one-hour-coasterbot/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Salt &amp; Pepper Creature (Work in Progress)</title>
		<link>http://www.cibomahto.com/2011/04/1622/</link>
		<comments>http://www.cibomahto.com/2011/04/1622/#comments</comments>
		<pubDate>Wed, 20 Apr 2011 02:14:51 +0000</pubDate>
		<dc:creator>mahto</dc:creator>
				<category><![CDATA[Blogroll]]></category>
		<category><![CDATA[tech]]></category>

		<guid isPermaLink="false">http://www.cibomahto.com/?p=1622</guid>
		<description><![CDATA[I&#8217;m working on a three part, printable model (top, bottom, actuator arm) that can be made into a little electronic puppet by adding a cheap servo and snapping it together. It&#8217;s an adaptation of DesignGlut&#8217;s Salt and Pepper Shakers. Model &#8230; <a href="http://www.cibomahto.com/2011/04/1622/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><object type="application/x-shockwave-flash" width="601" height="401" data="http://www.flickr.com/apps/video/stewart.swf?v=71377" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"><param name="flashvars" value="intl_lang=en-us&#038;photo_secret=462ac509b2&#038;photo_id=5636040233"></param><param name="movie" value="http://www.flickr.com/apps/video/stewart.swf?v=71377"></param><param name="bgcolor" value="#000000"></param><param name="allowFullScreen" value="true"></param><embed type="application/x-shockwave-flash" src="http://www.flickr.com/apps/video/stewart.swf?v=71377" bgcolor="#000000" allowfullscreen="true" flashvars="intl_lang=en-us&#038;photo_secret=462ac509b2&#038;photo_id=5636040233" height="401" width="601"></embed></object></p>
<p>I&#8217;m working on a three part, printable model (top, bottom, actuator arm) that can be made into a little electronic puppet by adding a cheap servo and snapping it together. It&#8217;s an adaptation of DesignGlut&#8217;s <a href="http://www.thingiverse.com/thing:859">Salt and Pepper Shakers</a>. Model files coming when I get back to my other computer.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cibomahto.com/2011/04/1622/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Physical build progress meter for 3d printer</title>
		<link>http://www.cibomahto.com/2011/02/physical-build-progress-meter-for-3d-printer/</link>
		<comments>http://www.cibomahto.com/2011/02/physical-build-progress-meter-for-3d-printer/#comments</comments>
		<pubDate>Sat, 05 Feb 2011 09:30:18 +0000</pubDate>
		<dc:creator>mahto</dc:creator>
				<category><![CDATA[Ridiculous]]></category>
		<category><![CDATA[tech]]></category>

		<guid isPermaLink="false">http://www.cibomahto.com/?p=1585</guid>
		<description><![CDATA[Yesterday I made this progress meter attachment for the 3d printer that I have at work, that rotates to show me how far along my print is: Love 3d printing with your Thing-o-Matic, but wish there were a better way &#8230; <a href="http://www.cibomahto.com/2011/02/physical-build-progress-meter-for-3d-printer/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.cibomahto.com/?attachment_id=1586" rel="attachment wp-att-1586"><img src="http://www.cibomahto.com/wp-content/uploads/2011/02/unicorn_build_progress_meter_display_medium-600x490.jpg" alt="" title="unicorn_build_progress_meter_display_medium" width="600" height="490" class="alignnone size-medium wp-image-1586" /></a></p>
<p>Yesterday I made this <a href="http://www.thingiverse.com/thing:6093">progress meter</a> attachment for the 3d printer that I have at work, that rotates to show me how far along my print is:</p>
<blockquote><p>Love 3d printing with your Thing-o-Matic, but wish there were a better way to see how your print is progressing? Well, today is your lucky day- if you&#8217;ve got a spare hobby servo (the one in the Unicorn works great), then you can make your very own progress gauge! </p></blockquote>
<p>Source code and directions on Thingiverse.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cibomahto.com/2011/02/physical-build-progress-meter-for-3d-printer/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>10 minute project: Traffic counter for router</title>
		<link>http://www.cibomahto.com/2011/01/10-minute-project-traffic-counter-for-router/</link>
		<comments>http://www.cibomahto.com/2011/01/10-minute-project-traffic-counter-for-router/#comments</comments>
		<pubDate>Thu, 27 Jan 2011 13:00:38 +0000</pubDate>
		<dc:creator>mahto</dc:creator>
				<category><![CDATA[tech]]></category>

		<guid isPermaLink="false">http://www.cibomahto.com/?p=1539</guid>
		<description><![CDATA[I&#8217;ve been joking about making a new case for my wireless router for a long time. The idea was that that would be shaped like a McDonalds store, with a little sign out front that says how many billion bytes &#8230; <a href="http://www.cibomahto.com/2011/01/10-minute-project-traffic-counter-for-router/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.cibomahto.com/2011/01/10-minute-project-traffic-counter-for-router/mcrouter/" rel="attachment wp-att-1541"><img src="http://www.cibomahto.com/wp-content/uploads/2011/01/mcrouter.jpg" alt="" title="mcrouter" width="600" height="424" class="alignnone size-full wp-image-1541" /></a></p>
<p>I&#8217;ve been joking about making a new case for my wireless router for a long time. The idea was that that would be shaped like a McDonalds store, with a little sign out front that says how many billion bytes (or whatever) have been served. Tonight, I decided to see how hard it would be to cobble together the technical portion of the project using an Asus WL-520 router running <a href="http://www.cibomahto.com/2008/05/xml-parsing-using-only-bash/">MightyOhm&#8217;s OpenWRT build</a> and an old display that I had sitting around.</p>
<p>Using <a href="http://www.cibomahto.com/2007/12/lcd-driver/">my python library</a> as a reference for how to use the display, and my <a href="http://www.cibomahto.com/2008/05/xml-parsing-using-only-bash/">XML parsing script for ash</a>, I was able to cobble together a working project quickly. My source code is after the break.</p>
<p>Now, to complete the vision, I just need to make some golden arches&#8230;<br />
<span id="more-1539"></span><br />
screen.sh is the script that figures out the amount of information transmitted by the network interface, and the second file is an example cron job to make an update every minute.</p>
<p>cat /root/screen.sh </p>
<pre>
#!/bin/ash

TTY_DEV=/dev/tts/0
NETWORK_DEVICE=wl0

# Configure the serial port
stty -F ${TTY_DEV} 9600 cs8

# Turn on the led backlight
echo -e "\x14\xff" > ${TTY_DEV}

INFO=`ifconfig ${NETWORK_DEVICE}`
TMP=${INFO#*TX\ bytes:}
TX_BYTES=${TMP%\ (*}

TX_MBYTES=$(($TX_BYTES/1000000))

echo -en "\x0C" > ${TTY_DEV}
echo -n "McRouter        " > ${TTY_DEV}
echo -n "Served " ${TX_MBYTES} "MB" > ${TTY_DEV}
</pre>
<p>cat /etc/crontabs/root </p>
<pre>
* * * * * /root/screen.sh
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.cibomahto.com/2011/01/10-minute-project-traffic-counter-for-router/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Sensor headphones, part 1</title>
		<link>http://www.cibomahto.com/2011/01/sensor-headphones-part-1/</link>
		<comments>http://www.cibomahto.com/2011/01/sensor-headphones-part-1/#comments</comments>
		<pubDate>Thu, 20 Jan 2011 08:09:11 +0000</pubDate>
		<dc:creator>mahto</dc:creator>
				<category><![CDATA[tech]]></category>

		<guid isPermaLink="false">http://www.cibomahto.com/?p=1517</guid>
		<description><![CDATA[For a while now, I&#8217;ve been wanting a pair of headphones that automatically pause your music when you remove them. I&#8217;d been dreaming up complicated ways to do this, but my friend Kyle reminded me that it is easy and &#8230; <a href="http://www.cibomahto.com/2011/01/sensor-headphones-part-1/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><iframe title="YouTube video player" class="youtube-player" type="text/html" width="600" height="366" src="http://www.youtube.com/embed/D7dG1sZpkm4?hl=en&#038;start=0&#038;fs=1&#038;rel=0&#038;showinfo=0&#038;ap=%2526fmt%3D18" frameborder="0"></iframe></p>
<p>For a while now, I&#8217;ve been wanting a pair of headphones that automatically pause your music when you remove them. I&#8217;d been dreaming up complicated ways to do this, but my friend Kyle reminded me that it is easy and I should just do it. So, I put together a quickie project to do just so! It&#8217;s based on an <a href="http://www.jameco.com/webapp/wcs/stores/servlet/ProductDisplay?langId=-1&#038;productId=1872628&#038;catalogId=10001">OPTEK OPB606A distance sensor</a> that I got from Jameco, which puts out a low voltage when an object is near it, and a high voltage when all is clear. I whipped together a really sketchy arduino+processing script to allow the sensor to turn the music on and off, and voilà, it&#8217;s done!</p>
<p>Well, almost. I left my headphones at work, so it will be more done tomorrow evening after I affix the sensor to them. But for now, you can whet your appetite on the circuit diagram aforementioned sketchy code, which are available after the break.<span id="more-1517"></span><br />
Here&#8217;s the circuit! There&#8217;s not much to it, except to use a 220 ohm resistor to limit the current supplied to the LED in the sensor, and a 10k ohm resistor to pull the output signal high when the sensor isn&#8217;t getting any light in:<br />
<a href="http://www.cibomahto.com/2011/01/sensor-headphones-part-1/samsung-2/" rel="attachment wp-att-1523"><img src="http://www.cibomahto.com/wp-content/uploads/2011/01/sensor_headphones_diagram-600x350.jpg" alt="" title="SAMSUNG" width="600" height="350" class="alignnone size-medium wp-image-1523" /></a></p>
<p>Here is the <a href="http://www.arduino.cc/">Arduino</a> portion of the sketchiness:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Connect the distance sensor to this input pin</span>
<span style="color: #339933;">#define sensorInputPin 0</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// This stores the state that the headphones were in the last</span>
<span style="color: #666666; font-style: italic;">// time we checked them</span>
boolean lastHeadphonesOn<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Return true if the headphones were just taken off or put back on.</span>
boolean checkHeadphoneState<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// If the sensor value is really high, it means that nothing</span>
  <span style="color: #666666; font-style: italic;">// is near it, so the headphones must not be on your head.</span>
  <span style="color: #993333;">int</span> sensorIn <span style="color: #339933;">=</span> analogRead<span style="color: #009900;">&#40;</span>sensorInputPin<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  boolean headphonesOn <span style="color: #339933;">=</span> sensorIn <span style="color: #339933;">&lt;</span> <span style="color: #0000dd;">800</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// If our results are different from the last time we checked,</span>
  <span style="color: #666666; font-style: italic;">// return true.</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>headphonesOn <span style="color: #339933;">!=</span> lastHeadphonesOn<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    lastHeadphonesOn <span style="color: #339933;">=</span> headphonesOn<span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">true</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Otherwise, return false.</span>
  lastHeadphonesOn <span style="color: #339933;">=</span> headphonesOn<span style="color: #339933;">;</span>
  <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> setup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  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>
<span style="color: #009900;">&#125;</span>  
&nbsp;
<span style="color: #993333;">void</span> loop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>checkHeadphoneState<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>lastHeadphonesOn<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #666666; font-style: italic;">// headphones just put on</span>
      Serial.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;headphones on!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #666666; font-style: italic;">// headphones just removed</span>
      Serial.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;headphones off!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> 
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>And the <a href="http://processing.org/">Processing</a> portion, to watch the serial port for headphone on/off messages, and control the <a href="http://banshee.fm/">Banshee</a> music player</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Tell processing how to use a serial port</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">processing.serial.*</span><span style="color: #339933;">;</span>
Serial myPort<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">void</span> setup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// Open up the first available serial port, and set it to 9600 baud</span>
  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>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">void</span> draw<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// Read from the serial port until we get a linefeed</span>
    <span style="color: #000066; font-weight: bold;">int</span> lf <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> inBuffer <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">200</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    myPort.<span style="color: #006633;">readBytesUntil</span><span style="color: #009900;">&#40;</span>lf, inBuffer<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// If we actually got some text, check if it contains a message we were</span>
    <span style="color: #666666; font-style: italic;">// waiting for</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>inBuffer <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #003399;">String</span> myString <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">String</span><span style="color: #009900;">&#40;</span>inBuffer<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>myString.<span style="color: #006633;">contains</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;headphones on!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// Hooray! Turn the music on</span>
        println<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Headphones on!!!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">// Run the Banshee music program with the play command specified.</span>
        <span style="color: #666666; font-style: italic;">// If banshee was already running, it starts up the music again.</span>
        <span style="color: #000000; font-weight: bold;">try</span><span style="color: #009900;">&#123;</span>
          <span style="color: #003399;">Runtime</span>.<span style="color: #006633;">getRuntime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">exec</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;banshee --play&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
          <span style="color: #000000; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span>java.<span style="color: #006633;">io</span>.<span style="color: #003399;">IOException</span> e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
          println<span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#125;</span>
      <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>myString.<span style="color: #006633;">contains</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;headphones off!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        println<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Headphones off!!!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">// Run the Banshee music program with the pause command specified.</span>
        <span style="color: #666666; font-style: italic;">// If banshee was already running, it just pauses the music.</span>
        <span style="color: #000000; font-weight: bold;">try</span><span style="color: #009900;">&#123;</span>
          <span style="color: #003399;">Runtime</span>.<span style="color: #006633;">getRuntime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">exec</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;banshee --pause&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
          <span style="color: #000000; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span>java.<span style="color: #006633;">io</span>.<span style="color: #003399;">IOException</span> e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
          println<span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.cibomahto.com/2011/01/sensor-headphones-part-1/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Robot plant</title>
		<link>http://www.cibomahto.com/2010/12/robot-plant/</link>
		<comments>http://www.cibomahto.com/2010/12/robot-plant/#comments</comments>
		<pubDate>Fri, 17 Dec 2010 22:21:01 +0000</pubDate>
		<dc:creator>mahto</dc:creator>
				<category><![CDATA[Journal]]></category>
		<category><![CDATA[Photo]]></category>
		<category><![CDATA[tech]]></category>

		<guid isPermaLink="false">http://www.cibomahto.com/?p=1511</guid>
		<description><![CDATA[My friend and I made this Robot Plant for a build series I&#8217;ve been running over at Make. Instructions, etc can be found there! There is also a contest with some pretty fabulous prizes that you can win if you &#8230; <a href="http://www.cibomahto.com/2010/12/robot-plant/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.cibomahto.com/2010/12/robot-plant/robot_plant/" rel="attachment wp-att-1512"><img src="http://www.cibomahto.com/wp-content/uploads/2010/12/robot_plant.jpg" alt="" title="robot_plant" width="600" height="614" class="alignnone size-full wp-image-1512" /></a></p>
<p><object type="application/x-shockwave-flash" width="600" height="401" data="http://www.flickr.com/apps/video/stewart.swf?v=71377" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"><param name="flashvars" value="intl_lang=en-us&#038;photo_secret=4205b72eb4&#038;photo_id=5265780128"></param><param name="movie" value="http://www.flickr.com/apps/video/stewart.swf?v=71377"></param><param name="bgcolor" value="#000000"></param><param name="allowFullScreen" value="true"></param><embed type="application/x-shockwave-flash" src="http://www.flickr.com/apps/video/stewart.swf?v=71377" bgcolor="#000000" allowfullscreen="true" flashvars="intl_lang=en-us&#038;photo_secret=4205b72eb4&#038;photo_id=5265780128" height="401" width="600"></embed></object></p>
<p>My friend and I made this <a href="http://blog.makezine.com/archive/2010/12/make_it_last_1.html">Robot Plant</a> for a <a href="http://makezine.com/makeitlast/index.csp">build series</a> I&#8217;ve been running over at Make. Instructions, etc can be found there! There is also a contest with some pretty fabulous prizes that you can win if you build some sort of plant yourself (and you should!).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cibomahto.com/2010/12/robot-plant/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Spoon Organ</title>
		<link>http://www.cibomahto.com/2010/11/spoon-organ/</link>
		<comments>http://www.cibomahto.com/2010/11/spoon-organ/#comments</comments>
		<pubDate>Sun, 21 Nov 2010 19:06:34 +0000</pubDate>
		<dc:creator>mahto</dc:creator>
				<category><![CDATA[Ridiculous]]></category>
		<category><![CDATA[tech]]></category>

		<guid isPermaLink="false">http://www.cibomahto.com/?p=1478</guid>
		<description><![CDATA[Everyone likes Spoon Organ! Spoon Organ is an instrument that I created to show at the Make Tokyo Meeting 06 this past weekend. The user can play musical tunes simply by touching a row of spoons sitting on a table, &#8230; <a href="http://www.cibomahto.com/2010/11/spoon-organ/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.cibomahto.com/2010/11/spoon-organ/spoon_organ/" rel="attachment wp-att-1479"><img src="http://www.cibomahto.com/wp-content/uploads/2010/11/spoon_organ.jpg" alt="" title="spoon_organ" width="600" height="412" class="alignnone size-full wp-image-1479" /></a></p>
<p><a href="http://www.cibomahto.com/2010/11/spoon-organ/spoon_organ_users/" rel="attachment wp-att-1480"><img src="http://www.cibomahto.com/wp-content/uploads/2010/11/spoon_organ_users.jpg" alt="" title="spoon_organ_users" width="600" height="383" class="alignnone size-full wp-image-1480" /></a><br />
<em>Everyone likes Spoon Organ!</em></p>
<p>Spoon Organ is an instrument that I created to show at the Make Tokyo Meeting 06 this past weekend. The user can play musical tunes simply by touching a row of spoons sitting on a table, with a fork added in for good measure. A microcontroller is used to detect changes in capacitance caused by a finger pressing against the metal, which are then sent to a computer using the MIDI protocol.</p>
<p>The project was conceived of and created while on <a href="http://www.hackersonaplane.info/hackers-in-japan-2010/">Hackers on a Plane 4</a>, using spare parts from the <a href="http://makezine.com/makeitlast/index.csp">Make It Last Build Series</a>, cables and connectors purchased in <a href="http://blog.makezine.com/archive/2010/09/video_guide_to_akihabara.html">Akihabara</a> (thanks, <a href="http://www.freaklabs.org/">Akiba</a>!), and soldering work completed at <a href="http://www.tokyohackerspace.org/">Tokyo Hackerspace</a>. Here is a short video of it running:<br />
<object type="application/x-shockwave-flash" width="600" height="338" data="http://www.flickr.com/apps/video/stewart.swf?v=71377" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"><param name="flashvars" value="intl_lang=en-us&#038;photo_secret=dec76900fc&#038;photo_id=5195904894&#038;hd_default=false"></param><param name="movie" value="http://www.flickr.com/apps/video/stewart.swf?v=71377"></param><param name="bgcolor" value="#000000"></param><param name="allowFullScreen" value="true"></param><embed type="application/x-shockwave-flash" src="http://www.flickr.com/apps/video/stewart.swf?v=71377" bgcolor="#000000" allowfullscreen="true" flashvars="intl_lang=en-us&#038;photo_secret=dec76900fc&#038;photo_id=5195904894&#038;hd_default=false" height="338" width="600"></embed></object></p>
<p>Read on for a schematic and source code.<br />
<span id="more-1478"></span><br />
<a href="http://www.cibomahto.com/2010/11/spoon-organ/spoon_organ_schematic/" rel="attachment wp-att-1487"><img src="http://www.cibomahto.com/wp-content/uploads/2010/11/spoon_organ_schematic.png" alt="" title="spoon_organ_schematic" width="600" height="429" class="alignnone size-full wp-image-1487" /></a><br />
The schematic for the project is pictured above. I&#8217;m using the <a href="http://techtrain.microchip.com/webseminars/ArchivedDetail.aspx?Active=188">CTMU</a> peripheral on the PIC controller to do the sensing; it&#8217;s pretty amazing and requires no extra parts to use any of ADC input pins as a touch sensor. I&#8217;m only using every other sensor, because early tests showed that there would be interference between the channels when used on a solderless breadboard. The spoons are connected to the board using shielded cable (nothing fancy, just some power supply cable), which I soldered to alligator clips on one end and breadboarding plugs (ok, just bits off the ends of resistors) to the other. The shield is grounded on the microcontroller side, and left unconnected on the other.</p>
<p>Here is the source code for the project (please note that it is a quick hack from another project, and includes lots of useless code):</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">/////////////////////////////////////////////////////////////////////////////</span>
<span style="color: #666666; font-style: italic;">// Include files</span>
<span style="color: #666666; font-style: italic;">// These lines allow us to use code routines (libraries) from other files,</span>
<span style="color: #666666; font-style: italic;">// so that we don't have to write everything by ourselves.</span>
<span style="color: #666666; font-style: italic;">/////////////////////////////////////////////////////////////////////////////</span>
&nbsp;
<span style="color: #339933;">#include &lt;p18lf25k22.h&gt;	    // This file includes definitions for all of the</span>
                            <span style="color: #666666; font-style: italic;">// registers on our chip</span>
<span style="color: #339933;">#include &lt;stdio.h&gt;          // For the sprintf() function</span>
&nbsp;
<span style="color: #339933;">#define __18LF25K80</span>
<span style="color: #339933;">#include &lt;i2c.h&gt;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/////////////////////////////////////////////////////////////////////////////</span>
<span style="color: #666666; font-style: italic;">// Pragma statements</span>
<span style="color: #666666; font-style: italic;">// These lines tell the microcontroller what configuration to use when it</span>
<span style="color: #666666; font-style: italic;">// when it turns on. The most important part for now is to tell the</span>
<span style="color: #666666; font-style: italic;">// microcontroller what to use for a clock input.</span>
<span style="color: #666666; font-style: italic;">/////////////////////////////////////////////////////////////////////////////</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Use the internal oscillator as a clock</span>
<span style="color: #339933;">#pragma config FOSC = INTIO67		// Use internal clock, don't output </span>
<span style="color: #666666; font-style: italic;">//#pragma config FOSC = INTIO7        // Use internal clock, output on RA6</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Configure it to run at 16 MHz</span>
<span style="color: #339933;">#pragma config PLLCFG = OFF</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Allow the program to turn on the watchdog timer. The watchdog is a</span>
<span style="color: #666666; font-style: italic;">// a special feature of the processor, that runs separately from the main</span>
<span style="color: #666666; font-style: italic;">// program and can be used to wake up the processor after a certain amount of time.</span>
<span style="color: #339933;">#pragma config WDTEN = OFF</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Set the watchdog timer prescaler to 1.</span>
<span style="color: #339933;">#pragma config WDTPS = 256</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">// Fix a compiler bug</span>
<span style="color: #339933;">#undef INTCON</span>
<span style="color: #339933;">#undef INTCONbits</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/////////////////////////////////////////////////////////////////////////////</span>
<span style="color: #666666; font-style: italic;">// Function declarations</span>
<span style="color: #666666; font-style: italic;">// Declare any user functions that you want to use here</span>
<span style="color: #666666; font-style: italic;">/////////////////////////////////////////////////////////////////////////////</span>
<span style="color: #993333;">void</span> main <span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #993333;">void</span> setup<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #993333;">void</span> loop<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">void</span> receive_interrupt<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> receiveCharacter <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>    <span style="color: #666666; font-style: italic;">// Stores the last character that was</span>
                                       <span style="color: #666666; font-style: italic;">// received by the serial port</span>
<span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> stayAwakeCount <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>      <span style="color: #666666; font-style: italic;">// 5 second countdown to keep the</span>
                                       <span style="color: #666666; font-style: italic;">// chip from sleeping</span>
&nbsp;
<span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> measureSwitch<span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> channel<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #339933;">#define PINCOUNT 8</span>
&nbsp;
<span style="color: #993333;">int</span> lastState<span style="color: #009900;">&#91;</span>PINCOUNT<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> offCount<span style="color: #009900;">&#91;</span>PINCOUNT<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Pins:</span>
<span style="color: #666666; font-style: italic;">// 2 4 7 14 21 23 25 15</span>
&nbsp;
<span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> inputADC<span style="color: #009900;">&#91;</span>PINCOUNT<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span>      <span style="color: #009900;">&#123;</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">4</span><span style="color: #339933;">,</span><span style="color: #0000dd;">15</span><span style="color: #339933;">,</span><span style="color: #0000dd;">12</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">8</span><span style="color: #339933;">,</span><span style="color: #0000dd;">11</span><span style="color: #339933;">,</span><span style="color: #0000dd;">16</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> inputPorts<span style="color: #009900;">&#91;</span>PINCOUNT<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span>    <span style="color: #009900;">&#123;</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">2</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> inputPins<span style="color: #009900;">&#91;</span>PINCOUNT<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span>     <span style="color: #009900;">&#123;</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">5</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">3</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">4</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">4</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> noteChannels<span style="color: #009900;">&#91;</span>PINCOUNT<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span>  <span style="color: #009900;">&#123;</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//unsigned char noteKeys[PINCOUNT] =      {49,51,54,56,58,61,63};</span>
<span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> noteKeys<span style="color: #009900;">&#91;</span>PINCOUNT<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span>      <span style="color: #009900;">&#123;</span><span style="color: #0000dd;">49</span><span style="color: #339933;">,</span><span style="color: #0000dd;">51</span><span style="color: #339933;">,</span><span style="color: #0000dd;">53</span><span style="color: #339933;">,</span><span style="color: #0000dd;">54</span><span style="color: #339933;">,</span><span style="color: #0000dd;">56</span><span style="color: #339933;">,</span><span style="color: #0000dd;">58</span><span style="color: #339933;">,</span><span style="color: #0000dd;">60</span><span style="color: #339933;">,</span><span style="color: #0000dd;">61</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #993333;">int</span> Vread<span style="color: #009900;">&#91;</span>PINCOUNT<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #339933;">#define PRESSED 0</span>
<span style="color: #339933;">#define RELEASED 1</span>
<span style="color: #339933;">#define NOCHANGE 2</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/////////////////////////////////////////////////////////////////////////////</span>
<span style="color: #666666; font-style: italic;">// Function definitions</span>
<span style="color: #666666; font-style: italic;">// Define any user functions that you want to use here</span>
<span style="color: #666666; font-style: italic;">/////////////////////////////////////////////////////////////////////////////</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Configure the high interrupt to call the high_isr() function</span>
<span style="color: #666666; font-style: italic;">// From MPLAB C18 C Compiler Users Guide, Page 29</span>
<span style="color: #339933;">#pragma code low_vector=0x08</span>
<span style="color: #993333;">void</span> low_interrupt <span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
_asm GOTO receive_interrupt _endasm
<span style="color: #009900;">&#125;</span>
<span style="color: #339933;">#pragma code /* return to the default code section */</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">// The main() function is where the program 'starts' when the microcontroller</span>
<span style="color: #666666; font-style: italic;">// is turned on. For this project, we will use it to call setup() and loop()</span>
<span style="color: #666666; font-style: italic;">// functions, then use those similar to an Arduino sketch.</span>
<span style="color: #993333;">void</span> main <span style="color: #009900;">&#40;</span> <span style="color: #993333;">void</span> <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// Call the setup function once to put everything in order</span>
    setup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Then call the loop() function over and over</span>
    <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        loop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">// Function to write a character string to the serial port, from:</span>
<span style="color: #666666; font-style: italic;">// C:\MCC18\src\pmc_common\USART\u1puts.c</span>
<span style="color: #993333;">void</span> puts1USART<span style="color: #009900;">&#40;</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>data <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">do</span>
    <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// Transmit a byte</span>
        <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>TXSTA1bits.<span style="color: #202020;">TRMT</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        TXREG1 <span style="color: #339933;">=</span> <span style="color: #339933;">*</span>data<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Write the data byte to the USART2</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span> <span style="color: #339933;">*</span>data<span style="color: #339933;">++</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">// Map function, from:</span>
<span style="color: #666666; font-style: italic;">// http://www.arduino.cc/en/Reference/Map</span>
<span style="color: #993333;">long</span> map<span style="color: #009900;">&#40;</span><span style="color: #993333;">long</span> x<span style="color: #339933;">,</span> <span style="color: #993333;">long</span> in_min<span style="color: #339933;">,</span> <span style="color: #993333;">long</span> in_max<span style="color: #339933;">,</span> <span style="color: #993333;">long</span> out_min<span style="color: #339933;">,</span> <span style="color: #993333;">long</span> out_max<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span>x <span style="color: #339933;">-</span> in_min<span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #009900;">&#40;</span>out_max <span style="color: #339933;">-</span> out_min<span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #009900;">&#40;</span>in_max <span style="color: #339933;">-</span> in_min<span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> out_min<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">// Function to write a single byte to a device on the i2c bus</span>
<span style="color: #993333;">void</span> i2cWriteByte<span style="color: #009900;">&#40;</span> <span style="color: #993333;">char</span> byte <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// Send the first byte of address, and wait for ack</span>
    SSPBUF <span style="color: #339933;">=</span> byte<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Wait for idle</span>
    <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span> SSPCON2 <span style="color: #339933;">&amp;</span> <span style="color: #208080;">0x1F</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span> SSPSTATbits.<span style="color: #202020;">R_W</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
        <span style="color: #b1b100;">continue</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">// This function is called once, when the microcontroller is turned on.</span>
<span style="color: #993333;">void</span> setup<span style="color: #009900;">&#40;</span> <span style="color: #993333;">void</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #993333;">int</span> i<span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Processor configuration</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Configure the oscillator to run at 16 MHz</span>
    OSCCONbits.<span style="color: #202020;">IRCF</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">111</span><span style="color: #339933;">;</span>      <span style="color: #666666; font-style: italic;">// 16 MHz</span>
<span style="color: #666666; font-style: italic;">//    OSCCONbits.IRCF = 101;      // 4 MHz</span>
&nbsp;
    ANSELA <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
    TRISA <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
    PORTA <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
&nbsp;
    ANSELB <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
    TRISB <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
    PORTB <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
&nbsp;
    ANSELC <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
    TRISC <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
    PORTC <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// ADC configuration</span>
    ADCON2bits.<span style="color: #202020;">ADFM</span><span style="color: #339933;">=</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>        <span style="color: #666666; font-style: italic;">// Right Justified</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Set the speed that the ADC should capture data</span>
<span style="color: #666666; font-style: italic;">//    ADCON2bits.ACQT=0b110;    // Acquisition time</span>
<span style="color: #666666; font-style: italic;">//    ADCON2bits.ADCS=0b010;    // Fosc/8 (?)</span>
&nbsp;
    ADCON2bits.<span style="color: #202020;">ACQT</span><span style="color: #339933;">=</span><span style="color: #208080;">0b111</span><span style="color: #339933;">;</span>    <span style="color: #666666; font-style: italic;">// Acquisition time</span>
    ADCON2bits.<span style="color: #202020;">ADCS</span><span style="color: #339933;">=</span><span style="color: #208080;">0b010</span><span style="color: #339933;">;</span>    <span style="color: #666666; font-style: italic;">// Fosc/32</span>
&nbsp;
&nbsp;
    ADCON0bits.<span style="color: #202020;">ADON</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>      <span style="color: #666666; font-style: italic;">// Turn the ADC on</span>
&nbsp;
&nbsp;
  <span style="color: #666666; font-style: italic;">// Serial port configuration</span>
    TRISCbits.<span style="color: #202020;">TRISC6</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>	  <span style="color: #666666; font-style: italic;">// Make TX pin an output</span>
    TRISCbits.<span style="color: #202020;">TRISC7</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>	  <span style="color: #666666; font-style: italic;">// and RX pin an input</span>
    ANSELCbits.<span style="color: #202020;">ANSC7</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>     <span style="color: #666666; font-style: italic;">// Specifically, an analog input</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Configure the serial port to run at 9600 baud</span>
    <span style="color: #666666; font-style: italic;">// (see manual, page 275)</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// for 16 MHz clock</span>
    SPBRG1 <span style="color: #339933;">=</span> <span style="color: #0000dd;">25</span><span style="color: #339933;">;</span>    
    TXSTA1bits.<span style="color: #202020;">BRGH</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>      <span style="color: #666666; font-style: italic;">// Baud rate select</span>
    BAUD1CONbits.<span style="color: #202020;">BRG16</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Turn on the serial port</span>
    RCSTA1bits.<span style="color: #202020;">CREN</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>      <span style="color: #666666; font-style: italic;">// Enable receive mode on the serial port</span>
    TXSTA1bits.<span style="color: #202020;">TXEN</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>      <span style="color: #666666; font-style: italic;">// Enable transmitter</span>
    RCSTA1bits.<span style="color: #202020;">SPEN</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>      <span style="color: #666666; font-style: italic;">// Enable receiver</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// CTMU configuration</span>
    CTMUCONH <span style="color: #339933;">=</span> <span style="color: #208080;">0x00</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">//make sure CTMU is disabled</span>
    CTMUCONL <span style="color: #339933;">=</span> <span style="color: #208080;">0x90</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">//CTMU continues to run when emulator is stopped,CTMU continues</span>
    <span style="color: #666666; font-style: italic;">//to run in idle mode,Time Generation mode disabled, Edges are blocked</span>
    <span style="color: #666666; font-style: italic;">//No edge sequence order, Analog current source not grounded, trigger</span>
    <span style="color: #666666; font-style: italic;">//output disabled, Edge2 polarity = positive level, Edge2 source =</span>
    <span style="color: #666666; font-style: italic;">//source 0, Edge1 polarity = positive level, Edge1 source = source 0,</span>
&nbsp;
    CTMUICONbits.<span style="color: #202020;">IRNG</span> <span style="color: #339933;">=</span> <span style="color: #208080;">0x01</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">// .55uA current source</span>
<span style="color: #666666; font-style: italic;">//    CTMUICONbits.ITRIM = 0b111111;	// half power</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Configure the pins we are going to use</span>
    <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</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> PINCOUNT<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        lastState<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: #339933;">;</span>
        offCount<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: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">switch</span><span style="color: #009900;">&#40;</span>inputPorts<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
          <span style="color: #b1b100;">case</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">:</span>  <span style="color: #666666; font-style: italic;">// A</span>
            ANSELA <span style="color: #339933;">=</span>  ANSELA <span style="color: #339933;">|</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">&lt;&lt;</span>inputPins<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//            TRISA = TRISA | 1&lt;&lt;inputPins[i];</span>
            <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
          <span style="color: #b1b100;">case</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">:</span>  <span style="color: #666666; font-style: italic;">// B</span>
            ANSELB <span style="color: #339933;">=</span>  ANSELB <span style="color: #339933;">|</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">&lt;&lt;</span>inputPins<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//            TRISB = TRISB | 1&lt;&lt;inputPins[i];</span>
            <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
          <span style="color: #b1b100;">case</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">:</span>  <span style="color: #666666; font-style: italic;">// C</span>
            ANSELC <span style="color: #339933;">=</span>  ANSELC <span style="color: #339933;">|</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">&lt;&lt;</span>inputPins<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//            TRISC = TRISC | 1&lt;&lt;inputPins[i];</span>
            <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">unsigned</span> <span style="color: #993333;">int</span> logCount <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>     <span style="color: #666666; font-style: italic;">// Number of samples that the logger has acquired</span>
<span style="color: #993333;">int</span> logInterval <span style="color: #339933;">=</span> <span style="color: #0000dd;">10</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Number of seconds between measurements</span>
<span style="color: #993333;">char</span> logging <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>     <span style="color: #666666; font-style: italic;">// Specifies whether we are actively logging or not</span>
<span style="color: #993333;">int</span> intervalCounter <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// This function is called repeatedly</span>
<span style="color: #993333;">int</span> in<span style="color: #339933;">;</span>
<span style="color: #993333;">char</span> buffer<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">100</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">void</span> loop<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> i<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</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> PINCOUNT<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">//i = 1;</span>
        in <span style="color: #339933;">=</span> measureSwitch<span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>in <span style="color: #339933;">!=</span> RELEASED<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                offCount<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: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>in <span style="color: #339933;">==</span> PRESSED <span style="color: #339933;">&amp;&amp;</span> in <span style="color: #339933;">!=</span> lastState<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                lastState<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> in<span style="color: #339933;">;</span>
&nbsp;
                <span style="color: #666666; font-style: italic;">// Note on</span>
                buffer<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #208080;">0x90</span> <span style="color: #339933;">+</span> noteChannels<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                buffer<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> noteKeys<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                buffer<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">127</span><span style="color: #339933;">;</span>
                buffer<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">3</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #208080;">0x00</span><span style="color: #339933;">;</span>
                puts1USART<span style="color: #009900;">&#40;</span>buffer<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//        sprintf(buffer,(const rom far char *)&quot;TOUCH_ON channel=%hu value=%i\r\n\x00&quot;, i, Vread[i]);</span>
<span style="color: #666666; font-style: italic;">//        puts1USART(buffer);</span>
&nbsp;
            <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>in <span style="color: #339933;">==</span> RELEASED <span style="color: #339933;">&amp;&amp;</span> in <span style="color: #339933;">!=</span> lastState<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>offCount<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">&lt;</span> <span style="color: #0000dd;">3</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    offCount<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">++;</span>
                <span style="color: #009900;">&#125;</span>
                <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
                    lastState<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> in<span style="color: #339933;">;</span>
                    offCount<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: #339933;">;</span>
&nbsp;
                    <span style="color: #666666; font-style: italic;">// Note off</span>
                    buffer<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #208080;">0x80</span> <span style="color: #339933;">+</span> noteChannels<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                    buffer<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> noteKeys<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                    buffer<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">127</span><span style="color: #339933;">;</span>
                    buffer<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">3</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #208080;">0x00</span><span style="color: #339933;">;</span>
                    puts1USART<span style="color: #009900;">&#40;</span>buffer<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//        sprintf(buffer,(const rom far char *)&quot;TOUCH_OFF channel=%hu value=%i\r\n\x00&quot;, i, Vread[i]);</span>
<span style="color: #666666; font-style: italic;">//        puts1USART(buffer);</span>
&nbsp;
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">// This function is called whenever a high interrupt occurs. For the</span>
<span style="color: #666666; font-style: italic;">// datalogger project, this only happens when the EUSART (serial port)</span>
<span style="color: #666666; font-style: italic;">// receives a character.</span>
<span style="color: #339933;">#pragma interruptlow receive_interrupt</span>
<span style="color: #993333;">void</span> receive_interrupt <span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// Read the character in from the serial module. If the serial port just</span>
    <span style="color: #666666; font-style: italic;">// woke up the microcontroller, this will be garbage.</span>
    receiveCharacter <span style="color: #339933;">=</span> RCREG<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// If we just woke up from sleeping, discard the first character because</span>
    <span style="color: #666666; font-style: italic;">// it is probably corrupted</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>stayAwakeCount <span style="color: #339933;">==</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        receiveCharacter <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Start a counter to wait 5 seconds before sleeping, in order to give</span>
    <span style="color: #666666; font-style: italic;">// the user time to send a serial command</span>
    stayAwakeCount <span style="color: #339933;">=</span> <span style="color: #0000dd;">5</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">// PIC 18lf22 datasheet, page 326</span>
&nbsp;
<span style="color: #339933;">#define COUNT 150                     //@ 16MHz = 125uS.</span>
<span style="color: #339933;">#define DELAY for(i=0;i&lt;COUNT;i++) {}</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/*
#define OPENSW 1000                   //Un-pressed switch value
#define TRIP 200                      //Difference between pressed
                                      //and un-pressed switch
#define HYST 65                       //amount to change
*/</span>
<span style="color: #339933;">#define TRIPOFF  1000                 // </span>
<span style="color: #339933;">#define TRIPON   800</span>
                                      <span style="color: #666666; font-style: italic;">//from pressed to un-pressed</span>
&nbsp;
&nbsp;
<span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> measureSwitch<span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> channel<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #993333;">int</span> i<span style="color: #339933;">,</span> j<span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">switch</span><span style="color: #009900;">&#40;</span>inputPorts<span style="color: #009900;">&#91;</span>channel<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
          <span style="color: #b1b100;">case</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">:</span>  <span style="color: #666666; font-style: italic;">// A</span>
            TRISA <span style="color: #339933;">=</span> TRISA <span style="color: #339933;">|</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">&lt;&lt;</span>inputPins<span style="color: #009900;">&#91;</span>channel<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
          <span style="color: #b1b100;">case</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">:</span>  <span style="color: #666666; font-style: italic;">// B</span>
            TRISB <span style="color: #339933;">=</span> TRISB <span style="color: #339933;">|</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">&lt;&lt;</span>inputPins<span style="color: #009900;">&#91;</span>channel<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
          <span style="color: #b1b100;">case</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">:</span>  <span style="color: #666666; font-style: italic;">// C</span>
            TRISC <span style="color: #339933;">=</span> TRISC <span style="color: #339933;">|</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">&lt;&lt;</span>inputPins<span style="color: #009900;">&#91;</span>channel<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
    ADCON0bits.<span style="color: #202020;">CHS</span> <span style="color: #339933;">=</span> inputADC<span style="color: #009900;">&#91;</span>channel<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//    ADCON0bits.ADON = 1;      // Turn the ADC on</span>
    DELAY<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">//assume CTMU and A/D have been setup correctly</span>
    <span style="color: #666666; font-style: italic;">//see Example 25-1 for CTMU &amp; A/D setup</span>
&nbsp;
    CTMUCONHbits.<span style="color: #202020;">CTMUEN</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>      <span style="color: #666666; font-style: italic;">// Enable the CTMU</span>
    CTMUCONLbits.<span style="color: #202020;">EDG1STAT</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>    <span style="color: #666666; font-style: italic;">// Set Edge status bits to zero</span>
    CTMUCONLbits.<span style="color: #202020;">EDG2STAT</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> 
    CTMUCONHbits.<span style="color: #202020;">IDISSEN</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>     <span style="color: #666666; font-style: italic;">//drain charge on the circuit</span>
    DELAY<span style="color: #339933;">;</span>
    DELAY<span style="color: #339933;">;</span>
&nbsp;
    CTMUCONHbits.<span style="color: #202020;">IDISSEN</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>     <span style="color: #666666; font-style: italic;">//end drain of circuit</span>
&nbsp;
    CTMUCONLbits.<span style="color: #202020;">EDG1STAT</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>    <span style="color: #666666; font-style: italic;">//Begin charging the circuit</span>
                                  <span style="color: #666666; font-style: italic;">//using CTMU current source</span>
    DELAY<span style="color: #339933;">;</span>                        <span style="color: #666666; font-style: italic;">//wait for 125us</span>
    CTMUCONLbits.<span style="color: #202020;">EDG1STAT</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>    <span style="color: #666666; font-style: italic;">//Stop charging circuit</span>
&nbsp;
    PIR1bits.<span style="color: #202020;">ADIF</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>            <span style="color: #666666; font-style: italic;">// Make sure adc interrupts are disabled</span>
    ADCON0bits.<span style="color: #202020;">GO</span><span style="color: #339933;">=</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>              <span style="color: #666666; font-style: italic;">//and begin A/D conv.</span>
    <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>PIR1bits.<span style="color: #202020;">ADIF</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>        <span style="color: #666666; font-style: italic;">//Wait for A/D convert complete</span>
&nbsp;
    Vread<span style="color: #009900;">&#91;</span>channel<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> ADRES<span style="color: #339933;">;</span>       <span style="color: #666666; font-style: italic;">//Get the value from the A/D</span>
&nbsp;
&nbsp;
    CTMUCONHbits.<span style="color: #202020;">CTMUEN</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>      <span style="color: #666666; font-style: italic;">// Disable the CTMU</span>
&nbsp;
    <span style="color: #b1b100;">switch</span><span style="color: #009900;">&#40;</span>inputPorts<span style="color: #009900;">&#91;</span>channel<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">case</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">:</span>  <span style="color: #666666; font-style: italic;">// A</span>
        TRISA <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">case</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">:</span>  <span style="color: #666666; font-style: italic;">// B</span>
        TRISB <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">case</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">:</span>  <span style="color: #666666; font-style: italic;">// C</span>
        TRISC <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>Vread<span style="color: #009900;">&#91;</span>channel<span style="color: #009900;">&#93;</span> <span style="color: #339933;">&lt;</span> TRIPON<span style="color: #009900;">&#41;</span> 
    <span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">//        sprintf(buffer,(const rom far char *)&quot;TOUCH_ON  channel=%hu value=%i\r\n\x00&quot;, channel, Vread[channel]);</span>
<span style="color: #666666; font-style: italic;">//        puts1USART(buffer);</span>
        <span style="color: #b1b100;">return</span> PRESSED<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>Vread<span style="color: #009900;">&#91;</span>channel<span style="color: #009900;">&#93;</span> <span style="color: #339933;">&gt;</span> TRIPOFF <span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">//        sprintf(buffer,(const rom far char *)&quot;TOUCH_OFF channel=%hu value=%i\r\n\x00&quot;, channel, Vread[channel]);</span>
<span style="color: #666666; font-style: italic;">//        puts1USART(buffer);</span>
        <span style="color: #b1b100;">return</span> RELEASED<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">else</span>
    <span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">//        sprintf(buffer,(const rom far char *)&quot;NO_CHANGE channel=%hu value=%i\r\n\x00&quot;, channel, Vread[channel]);</span>
<span style="color: #666666; font-style: italic;">//        puts1USART(buffer);</span>
        <span style="color: #b1b100;">return</span> NOCHANGE<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.cibomahto.com/2010/11/spoon-organ/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>LoL + Processing</title>
		<link>http://www.cibomahto.com/2010/08/lol-processing/</link>
		<comments>http://www.cibomahto.com/2010/08/lol-processing/#comments</comments>
		<pubDate>Thu, 12 Aug 2010 16:28:02 +0000</pubDate>
		<dc:creator>mahto</dc:creator>
				<category><![CDATA[tech]]></category>

		<guid isPermaLink="false">http://www.cibomahto.com/?p=1385</guid>
		<description><![CDATA[On the train back from NYC to Pittsburgh, I got the idea to hook up the LoL Shield directly to my computer, so that I could develop animations for it using a desktop graphics program. Using Jay Clegg&#8217;s Video Peggy &#8230; <a href="http://www.cibomahto.com/2010/08/lol-processing/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.cibomahto.com/2010/08/lol-processing/lol_framebuffer/" rel="attachment wp-att-1389"><img src="http://www.cibomahto.com/wp-content/uploads/2010/08/lol_framebuffer.jpg" alt="" title="lol_framebuffer" width="600" height="378" class="alignnone size-full wp-image-1389" /></a></p>
<p>On the train back from NYC to Pittsburgh, I got the idea to hook up the <a href="http://jimmieprodgers.com/kits/lolshield/">LoL Shield</a> directly to my computer, so that I could develop animations for it using a desktop graphics program. Using Jay Clegg&#8217;s <a href="http://www.planetclegg.com/projects/QC-Peggy.html">Video Peggy</a> project as a starting point, I wrote up a little framebuffer sketch for the Arduino, along with some <a href="http://processing.org/">Processing</a> code to grab a region of the computer screen, scale it, and send it over to the LoL Shield for display. Pretty simple, but could be useful. Source code is after the break. A version of this project might be included with the next LoL Shield library release.<span id="more-1385"></span></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">processing.serial.*</span><span style="color: #339933;">;</span>
&nbsp;
LolShieldBuffer lolShield<span style="color: #339933;">;</span>
PFont fontA<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">void</span> setup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  size<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">14</span>, <span style="color: #cc66cc;">9</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Load the font. Fonts must be placed within the data </span>
  <span style="color: #666666; font-style: italic;">// directory of your sketch. A font must first be created</span>
  <span style="color: #666666; font-style: italic;">// using the 'Create Font...' option in the Tools menu.</span>
  fontA <span style="color: #339933;">=</span> loadFont<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;LucidaSans-9.vlw&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Set the font and its size (in units of pixels)</span>
  textFont<span style="color: #009900;">&#40;</span>fontA, <span style="color: #cc66cc;">9</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// I know that the first port in the serial list on my mac</span>
  <span style="color: #666666; font-style: italic;">// is always my  FTDI adaptor, so I open Serial.list()[0].</span>
  <span style="color: #666666; font-style: italic;">// On Windows machines, this generally opens COM1.</span>
  <span style="color: #666666; font-style: italic;">// Open whatever port is the one you're using.</span>
  <span style="color: #003399;">String</span> portName <span style="color: #339933;">=</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: #339933;">;</span>
  print<span style="color: #009900;">&#40;</span>portName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  lolShield <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> LolShieldBuffer<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>, portName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<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>
&nbsp;
<span style="color: #000066; font-weight: bold;">void</span> draw<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  background<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&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>
&nbsp;
  text<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;The time is now &quot;</span> <span style="color: #339933;">+</span> hour<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;:&quot;</span> <span style="color: #339933;">+</span> minute<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, i, <span style="color: #cc66cc;">8</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//  lolShield.sendWindow(mouseX,mouseY, 14, 9);</span>
  lolShield.<span style="color: #006633;">sendWindow</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">14</span>, <span style="color: #cc66cc;">9</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  i<span style="color: #339933;">--;</span>
  <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">&lt;</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">130</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">14</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span>
  delay<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">50</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>You want to put this code on your Arduino:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &quot;Charliplexing.h&quot;</span>
<span style="color: #339933;">#include &quot;Font.h&quot;</span>
<span style="color: #339933;">#include &quot;WProgram.h&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Inspired by Video Peggy:</span>
<span style="color: #666666; font-style: italic;">// http://www.planetclegg.com/projects/QC-Peggy.html</span>
&nbsp;
<span style="color: #993333;">void</span> setup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>                    <span style="color: #666666; font-style: italic;">// run once, when the sketch starts</span>
<span style="color: #009900;">&#123;</span>
  Serial.<span style="color: #202020;">begin</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">115200</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  LedSign<span style="color: #339933;">::</span><span style="color: #202020;">Init</span><span style="color: #009900;">&#40;</span>DOUBLE_BUFFER<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//  LedSign::Init();</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">int</span> state <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> 
<span style="color: #993333;">int</span> counter <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #993333;">const</span> uint8_t DISP_BUFFER_SIZE <span style="color: #339933;">=</span> <span style="color: #0000dd;">9</span><span style="color: #339933;">*</span><span style="color: #0000dd;">2</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">void</span> loop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>                     <span style="color: #666666; font-style: italic;">// run over and over again</span>
<span style="color: #009900;">&#123;</span> 
  <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span>Serial.<span style="color: #202020;">available</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
  uint8_t c <span style="color: #339933;">=</span> Serial.<span style="color: #202020;">read</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// very simple state machine to look for 6 byte start of frame</span>
  <span style="color: #666666; font-style: italic;">// marker and copy bytes that follow into buffer</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>state <span style="color: #339933;">&lt;</span> <span style="color: #0000dd;">6</span><span style="color: #009900;">&#41;</span> 
  <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// must wait for 0xdeadbeef to start frame.</span>
    <span style="color: #666666; font-style: italic;">// note, I look for two more bytes after that, but</span>
    <span style="color: #666666; font-style: italic;">// they are reserved for future use. </span>
&nbsp;
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>state <span style="color: #339933;">==</span> <span style="color: #0000dd;">0</span> <span style="color: #339933;">&amp;&amp;</span> c <span style="color: #339933;">==</span> <span style="color: #208080;">0x12</span><span style="color: #009900;">&#41;</span> state<span style="color: #339933;">++;</span>
    <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>state <span style="color: #339933;">==</span><span style="color: #0000dd;">1</span> <span style="color: #339933;">&amp;&amp;</span> c <span style="color: #339933;">==</span> <span style="color: #208080;">0x34</span><span style="color: #009900;">&#41;</span> state<span style="color: #339933;">++;</span>
    <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>state <span style="color: #339933;">==</span><span style="color: #0000dd;">2</span> <span style="color: #339933;">&amp;&amp;</span> c <span style="color: #339933;">==</span> <span style="color: #208080;">0x56</span><span style="color: #009900;">&#41;</span> state<span style="color: #339933;">++;</span>
    <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>state <span style="color: #339933;">==</span><span style="color: #0000dd;">3</span> <span style="color: #339933;">&amp;&amp;</span> c <span style="color: #339933;">==</span> <span style="color: #208080;">0x78</span><span style="color: #009900;">&#41;</span> state<span style="color: #339933;">++;</span>
    <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>state <span style="color: #339933;">==</span><span style="color: #0000dd;">4</span> <span style="color: #339933;">&amp;&amp;</span> c <span style="color: #339933;">==</span> <span style="color: #208080;">0x1</span><span style="color: #009900;">&#41;</span> state<span style="color: #339933;">++;</span>
    <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>state <span style="color: #339933;">==</span><span style="color: #0000dd;">5</span><span style="color: #009900;">&#41;</span>  <span style="color: #666666; font-style: italic;">// dont care what 6th byte is </span>
    <span style="color: #009900;">&#123;</span>
      state<span style="color: #339933;">++;</span>
      counter <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">else</span> state <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// error: reset to look for start of frame</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">else</span> 
  <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// inside of a frame, so write to the buffer</span>
    uint8_t row <span style="color: #339933;">=</span> counter <span style="color: #339933;">/</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">;</span>
    uint8_t col <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>counter <span style="color: #339933;">%</span> <span style="color: #0000dd;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #0000dd;">8</span><span style="color: #339933;">;</span>
    uint8_t length <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>col<span style="color: #339933;">==</span><span style="color: #0000dd;">0</span><span style="color: #339933;">?</span><span style="color: #0000dd;">8</span><span style="color: #339933;">:</span><span style="color: #0000dd;">6</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>uint8_t colOffset <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>  colOffset <span style="color: #339933;">&lt;</span> length <span style="color: #339933;">;</span> colOffset<span style="color: #339933;">++</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      LedSign<span style="color: #339933;">::</span><span style="color: #202020;">Set</span><span style="color: #009900;">&#40;</span>col<span style="color: #339933;">+</span>colOffset<span style="color: #339933;">,</span> row<span style="color: #339933;">,</span> c <span style="color: #339933;">&gt;&gt;</span> <span style="color: #009900;">&#40;</span><span style="color: #0000dd;">7</span> <span style="color: #339933;">-</span> colOffset<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    counter<span style="color: #339933;">++;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>counter <span style="color: #339933;">&gt;=</span> DISP_BUFFER_SIZE<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #666666; font-style: italic;">// buffer filled, so reset everything to wait for next frame</span>
      state <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
      LedSign<span style="color: #339933;">::</span><span style="color: #202020;">Flip</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Put this code in a new tab in your Processing project, called LolShieldBuffer:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">processing.serial.*</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> LolShieldBuffer
<span style="color: #009900;">&#123;</span>
  Serial serial<span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000066; font-weight: bold;">int</span> ledWidth <span style="color: #339933;">=</span> <span style="color: #cc66cc;">14</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">int</span> ledHeight <span style="color: #339933;">=</span> <span style="color: #cc66cc;">9</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">int</span> ledFrameSize <span style="color: #339933;">=</span> <span style="color: #cc66cc;">9</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
  LolShieldBuffer<span style="color: #009900;">&#40;</span>PApplet parent, <span style="color: #003399;">String</span> portName<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    serial <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Serial<span style="color: #009900;">&#40;</span>parent, portName, <span style="color: #cc66cc;">115200</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000066; font-weight: bold;">void</span> sendWindow<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> x, <span style="color: #000066; font-weight: bold;">int</span> y, <span style="color: #000066; font-weight: bold;">int</span> w, <span style="color: #000066; font-weight: bold;">int</span> h<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    PImage img <span style="color: #339933;">=</span> get<span style="color: #009900;">&#40;</span>x, y, w, h<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//    img.resize(ledWidth, ledHeight);</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">char</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> frame <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000066; font-weight: bold;">char</span><span style="color: #009900;">&#91;</span>ledFrameSize<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Grab a 14x9 window</span>
    <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> row <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> row <span style="color: #339933;">&lt;</span> ledHeight<span style="color: #339933;">;</span> row<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000066; font-weight: bold;">char</span> buf <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
      <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> col <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> col <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">8</span><span style="color: #339933;">;</span> col<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        buf <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">char</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>buf <span style="color: #339933;">&lt;&lt;</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        buf <span style="color: #339933;">|=</span> <span style="color: #009900;">&#40;</span>brightness<span style="color: #009900;">&#40;</span>img.<span style="color: #006633;">pixels</span><span style="color: #009900;">&#91;</span>row<span style="color: #339933;">*</span>ledWidth<span style="color: #339933;">+</span>col<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">127</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
      frame<span style="color: #009900;">&#91;</span>row<span style="color: #339933;">*</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> buf<span style="color: #339933;">;</span>
&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> col <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> col <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">6</span><span style="color: #339933;">;</span> col<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        buf <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">char</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>buf <span style="color: #339933;">&lt;&lt;</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        buf <span style="color: #339933;">|=</span> <span style="color: #009900;">&#40;</span>brightness<span style="color: #009900;">&#40;</span>img.<span style="color: #006633;">pixels</span><span style="color: #009900;">&#91;</span>row<span style="color: #339933;">*</span>ledWidth<span style="color: #339933;">+</span><span style="color: #cc66cc;">8</span><span style="color: #339933;">+</span>col<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">127</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
      buf <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">char</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>buf <span style="color: #339933;">&lt;&lt;</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      frame<span style="color: #009900;">&#91;</span>row<span style="color: #339933;">*</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> buf<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    sendFrame<span style="color: #009900;">&#40;</span>frame<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
  <span style="color: #000066; font-weight: bold;">void</span> sendFrame<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">char</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> frame<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> magicNumber <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>0x12, 0x34, 0x56, 0x78, 0x1, 0x0<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
    serial.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span>magicNumber<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// TODO: Drop 9*2 magic number</span>
    <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><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> index <span style="color: #339933;">&lt;</span> ledFrameSize<span style="color: #339933;">;</span> index<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      serial.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span>frame<span style="color: #009900;">&#91;</span>index<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.cibomahto.com/2010/08/lol-processing/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Programming the LoL Shield using animated GIFs</title>
		<link>http://www.cibomahto.com/2010/08/programming-the-lol-shield-using-animated-gifs/</link>
		<comments>http://www.cibomahto.com/2010/08/programming-the-lol-shield-using-animated-gifs/#comments</comments>
		<pubDate>Thu, 12 Aug 2010 05:07:12 +0000</pubDate>
		<dc:creator>mahto</dc:creator>
				<category><![CDATA[tech]]></category>

		<guid isPermaLink="false">http://www.cibomahto.com/?p=1369</guid>
		<description><![CDATA[A couple of weeks ago, I was hacking on the LoL Shield with Nathan Rosenquist, when we realized that it was really time consuming to use the spreadsheet program to build animations. Never fear, a quick python script later and &#8230; <a href="http://www.cibomahto.com/2010/08/programming-the-lol-shield-using-animated-gifs/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><object width="600" height="406"><param name="movie" value="http://www.youtube.com/v/YJX4p--a90E?fs=1&amp;hl=en_US"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/YJX4p--a90E?fs=1&amp;hl=en_US" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="600" height="406"></embed></object><br />
A couple of weeks ago, I was hacking on the <a href="http://jimmieprodgers.com/kits/lolshield/">LoL Shield</a> with <a href="http://twitter.com/freeradicalx">Nathan Rosenquist</a>, when we realized that it was really time consuming to use the spreadsheet program to build animations. Never fear, a quick python script later and we could generate animations automatically from animated gifs.<br />
Using the program, you can take black &#038; white 14&#215;9 GIF animations of (probably) any length, such as the following one by Nathan:<br />
<a href="http://www.cibomahto.com/2010/08/programming-the-lol-shield-using-animated-gifs/ripple/" rel="attachment wp-att-1370"><img src="http://www.cibomahto.com/wp-content/uploads/2010/08/ripple.gif" alt="" title="ripple" width="14" height="9" class="alignnone size-full wp-image-1370" /></a></p>
<p>and get some code ready for the LoLing:</p>
<pre>
uint16_t ripple[][9] PROGMEM = {
 { 520 , 1028 , 2050 , 2050 , 2114 , 2050 , 2050 , 1028 , 520 , },
 { 2050 , 4097 , 4097 , 8256 , 8352 , 8256 , 4097 , 4097 , 2050 , },
 { 8192 , 8192 , 224 , 272 , 272 , 272 , 224 , 8192 , 8192 , },
 { 0 , 224 , 272 , 520 , 520 , 520 , 272 , 224 , 0 , },
 { 224 , 272 , 520 , 1028 , 1028 , 1028 , 520 , 272 , 224 , },
};
</pre>
<p>Here&#8217;s the python source, have fun! It requires Python and the Python Imaging Library (PIL):</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/python</span>
<span style="color: #808080; font-style: italic;"># Python script to convert a 14x9 pixel animated gif into a format that can</span>
<span style="color: #808080; font-style: italic;"># be displayed on the LoLShield.</span>
<span style="color: #808080; font-style: italic;">#</span>
<span style="color: #808080; font-style: italic;"># Requires Python and the Python Imaging Library (PIL)</span>
<span style="color: #808080; font-style: italic;"># It would be nice if this was available using a more common language.</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>, <span style="color: #dc143c;">os</span>, Image
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> ImageSequence:
    <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, im<span style="color: black;">&#41;</span>:
        <span style="color: #008000;">self</span>.<span style="color: black;">im</span> = im
    <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__getitem__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, ix<span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">try</span>:
            <span style="color: #ff7700;font-weight:bold;">if</span> ix:
                <span style="color: #008000;">self</span>.<span style="color: black;">im</span>.<span style="color: black;">seek</span><span style="color: black;">&#40;</span>ix<span style="color: black;">&#41;</span>
            <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">self</span>.<span style="color: black;">im</span>
        <span style="color: #ff7700;font-weight:bold;">except</span> <span style="color: #008000;">EOFError</span>:
            <span style="color: #ff7700;font-weight:bold;">raise</span> <span style="color: #008000;">IndexError</span> <span style="color: #808080; font-style: italic;"># end of sequence</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Open image</span>
filename = <span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>
filenameBase = <span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">splitext</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">split</span><span style="color: black;">&#40;</span>filename<span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>
im = Image.<span style="color: #008000;">open</span><span style="color: black;">&#40;</span>filename<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Print the variable declaration</span>
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;uint16_t &quot;</span> + filenameBase + <span style="color: #483d8b;">&quot;[][9] PROGMEM = {&quot;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># For each frame in the image, convert it to black &amp; white, then into the</span>
<span style="color: #808080; font-style: italic;"># LoLShield format</span>
<span style="color: #ff7700;font-weight:bold;">for</span> frame <span style="color: #ff7700;font-weight:bold;">in</span> ImageSequence<span style="color: black;">&#40;</span>im<span style="color: black;">&#41;</span>:
    <span style="color: #808080; font-style: italic;"># Convert to black and white</span>
    converted = frame.<span style="color: black;">convert</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;1&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot; {&quot;</span>,
    frameString = converted.<span style="color: black;">tostring</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;"># For each row in the image</span>
    <span style="color: #ff7700;font-weight:bold;">for</span> row <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span> <span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span>, <span style="color: #ff4500;">9</span><span style="color: black;">&#41;</span>:
        charA = <span style="color: #008000;">ord</span><span style="color: black;">&#40;</span>frameString<span style="color: black;">&#91;</span>row<span style="color: #66cc66;">*</span><span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
        charB = <span style="color: #008000;">ord</span><span style="color: black;">&#40;</span>frameString<span style="color: black;">&#91;</span>row<span style="color: #66cc66;">*</span><span style="color: #ff4500;">2</span> + <span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
&nbsp;
        rowTotal = <span style="color: #ff4500;">0</span>
        <span style="color: #808080; font-style: italic;"># Handle the first 8 bits</span>
        <span style="color: #ff7700;font-weight:bold;">for</span> col <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span> <span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span>, <span style="color: #ff4500;">8</span><span style="color: black;">&#41;</span>:
            shiftAmount = <span style="color: #ff4500;">7</span>-col
            rowTotal += <span style="color: black;">&#40;</span><span style="color: black;">&#40;</span>charA <span style="color: #66cc66;">&gt;&gt;</span> shiftAmount<span style="color: black;">&#41;</span> <span style="color: #66cc66;">&amp;</span> <span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">*</span> <span style="color: #ff4500;">2</span><span style="color: #66cc66;">**</span>col
        <span style="color: #808080; font-style: italic;"># Then the next 6</span>
        <span style="color: #ff7700;font-weight:bold;">for</span> col <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span> <span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span>, <span style="color: #ff4500;">6</span><span style="color: black;">&#41;</span>:
            shiftAmount = <span style="color: #ff4500;">7</span>-col
            rowTotal += <span style="color: black;">&#40;</span><span style="color: black;">&#40;</span>charB <span style="color: #66cc66;">&gt;&gt;</span> shiftAmount<span style="color: black;">&#41;</span> <span style="color: #66cc66;">&amp;</span> <span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">*</span> <span style="color: #ff4500;">2</span><span style="color: #66cc66;">**</span><span style="color: black;">&#40;</span>col+<span style="color: #ff4500;">8</span><span style="color: black;">&#41;</span>
        <span style="color: #808080; font-style: italic;"># And output the total for this row</span>
        <span style="color: #ff7700;font-weight:bold;">print</span> rowTotal, <span style="color: #483d8b;">&quot;,&quot;</span>,
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;},&quot;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;};&quot;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.cibomahto.com/2010/08/programming-the-lol-shield-using-animated-gifs/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

