<?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>adafruit industries blog &#187; code</title>
	<atom:link href="http://www.adafruit.com/adablog/?feed=rss2&#038;category_name=code" rel="self" type="application/rss+xml" />
	<link>http://www.adafruit.com/blog</link>
	<description>electronics, open source hardware, hacking and more...</description>
	<lastBuildDate>Tue, 07 Feb 2012 23:10:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2</generator>
		<item>
		<title>New year’s disco ball: first signs of software</title>
		<link>http://www.adafruit.com/blog/2011/12/22/new-year%e2%80%99s-disco-ball-first-signs-of-software/</link>
		<comments>http://www.adafruit.com/blog/2011/12/22/new-year%e2%80%99s-disco-ball-first-signs-of-software/#comments</comments>
		<pubDate>Thu, 22 Dec 2011 19:56:40 +0000</pubDate>
		<dc:creator>PhilB</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[leds-lcds]]></category>
		<category><![CDATA[projects]]></category>
		<category><![CDATA[3D]]></category>
		<category><![CDATA[geometry]]></category>
		<category><![CDATA[led]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[new year]]></category>
		<category><![CDATA[pixels]]></category>
		<category><![CDATA[polyhedra]]></category>
		<category><![CDATA[processing]]></category>

		<guid isPermaLink="false">http://www.adafruit.com/blog/?p=22953</guid>
		<description><![CDATA[Set your calculator to “maths”… Yesterday two basic criteria for our New Year&#8217;s LED project were established: Our “ball” will actually be an icosahedron — a 20-sided shape — for ease of assembly. Each face will have six LEDs, for 120 LEDs total. To create meaningful patterns on the ball, rather than just random blinking, [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center"><img class="size-full wp-image-22954 aligncenter" src="http://www.adafruit.com/adablog/wp-content/uploads/2011/12/ico-screen.jpg" alt="" width="600" height="300" /></p>
<p>Set your calculator to “maths”…</p>
<p><span id="more-22953"></span></p>
<p>Yesterday two basic criteria for our <a href="http://www.adafruit.com/blog/2011/12/16/a-little-bit-of-times-square-on-your-desk/">New Year&rsquo;s LED project</a> were established:</p>
<ol>
<li>Our “ball” will actually be an icosahedron — a 20-sided shape — for ease of assembly. Each face will have six LEDs, for 120 LEDs total.</li>
<li>To create meaningful patterns on the ball, rather than just random blinking, it&rsquo;s necessary to know the coordinates of every LED. Therefore, a software model will need to approximate the physical thing.</li>
</ol>
<p>The first step to finding the LED coordinates is to establish the positions of each of the 12 vertices of the icosahedron, even though there are no LEDs there. Once those points are known, all the LEDs can be located through interpolation.</p>
<p>There are a number of ways of constructing an icosahedron…the Greeks were working up the math in 400 B.C., the Scots <em>might</em> have hammered it out in the late Neolithic Age…though some protozoa and viruses had us all beat by half a billion years or so.</p>
<p style="text-align: center"><img class="size-full wp-image-22955 aligncenter" src="http://www.adafruit.com/adablog/wp-content/uploads/2011/12/history.jpg" alt="" width="330" height="110" /></p>
<p>Our “ball” will hang from one vertex at the top, so we&rsquo;ll follow a construction method to suit. When viewed down the vertical axis, there&rsquo;s a clear 5-fold symmetry:</p>
<p style="text-align: center"><img class="size-full wp-image-22956 aligncenter" src="http://www.adafruit.com/adablog/wp-content/uploads/2011/12/symmetry.png" alt="" width="400" height="200" /></p>
<p>Starting with just the radius of those “spokes” from the center (we&rsquo;ll use a value of 1.0 — the units are arbitrary), a couple formulas are all that&rsquo;s needed to find the 3D position of one vertex, and from that to replicate all the remaining vertices by revolving around the center axis. <a href="http://en.wikipedia.org/wiki/Icosahedron#Dimensions">Wikipedia can help with the maths</a>!</p>
<p>From those vertices we can then identify edges and faces. Using two edge vectors from each face, the triangular 1-2-3 layout of the LEDs can be interpolated across this. Wrapped up in just a short Processing sketch, we now have a tumbling 3D icosahedron with LED dots in the desired places! Later, we&rsquo;ll issue colors based on each LED&rsquo;s location.</p>
<p><a href="https://github.com/adafruit/Adafruit-X2-Time-Ball/tree/master/Processing/Ico">A test sketch for Processing is available from the project&rsquo;s Github repository</a>. This does not yet communicate with an Arduino or the LEDs; it is strictly for validating the geometry. It&rsquo;s a good visual match for the model on the table!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.adafruit.com/adablog/?feed=rss2&#038;p=22953</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Lauren Ipsum: Computer Science for Kids</title>
		<link>http://www.adafruit.com/blog/2011/10/10/lauren-ipsum-computer-science-for-kids/</link>
		<comments>http://www.adafruit.com/blog/2011/10/10/lauren-ipsum-computer-science-for-kids/#comments</comments>
		<pubDate>Mon, 10 Oct 2011 19:20:45 +0000</pubDate>
		<dc:creator>adafruit</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[educators]]></category>

		<guid isPermaLink="false">http://www.adafruit.com/blog/2011/10/10/lauren-ipsum-computer-science-for-kids/</guid>
		<description><![CDATA[Lauren Ipsum: Computer Science for Kids. Lauren Ipsum is a children&#8217;s story about computer science. In 20 chapters and ~35K words, she encounters dozens of ideas from timing attacks to algorithm design, the subtle power of names, and how to get a fair flip out of even the most unfair coin. The book is mostly [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.adafruit.com/adablog/wp-content/uploads/2011/10/photo-full.jpg" height="420" width="560" border="0" hspace="2" vspace="2" alt="Photo-Full" /></p>
<p><a href="http://www.laurenipsum.org/mostly-lost">Lauren Ipsum: Computer Science for Kids</a>.</p>
<blockquote><p>
Lauren Ipsum is a children&#8217;s story about computer science. In 20 chapters and ~35K words, she encounters dozens of ideas from timing attacks to algorithm design, the subtle power of names, and how to get a fair flip out of even the most unfair coin.</p>
<p>The book is mostly written, and Ytaelena is working on the illustrations and layout. We&#8217;ve been working on this project over nights &#038; weekends for about a year and a half. In return for a signed pre-sale copy of the book, your pledges will go towards translating the book into Spanish, Portuguese, and other languages.
</p></blockquote>
<p><a href="http://www.kickstarter.com/projects/512752850/lauren-ipsum-computer-science-for-kids">Read more</a>&#8230;</p>
<p>160 pages, dozens of illustrations. Perfect for kids. Available in paperback, Kindle and iPad in December 2011.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.adafruit.com/adablog/?feed=rss2&#038;p=19997</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Javascript PC Emulator &#8211; Linux in a browser</title>
		<link>http://www.adafruit.com/blog/2011/05/18/javascript-pc-emulator-linux-in-a-browser/</link>
		<comments>http://www.adafruit.com/blog/2011/05/18/javascript-pc-emulator-linux-in-a-browser/#comments</comments>
		<pubDate>Wed, 18 May 2011 17:38:18 +0000</pubDate>
		<dc:creator>adafruit</dc:creator>
				<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://www.adafruit.com/blog/2011/05/18/javascript-pc-emulator-linux-in-a-browser/</guid>
		<description><![CDATA[Javascript PC Emulator &#8211; Linux in a browser&#8230; This PC emulator is written in Javascript. The emulated hardware consists in: • a 32 bit x86 compatible CPU • a 8259 Programmble Interrupt Controller • a 8254 Programmble Interrupt Timer • a 16450 UART. The code is written in pure Javascript using Typed Arrays which are [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.adafruit.com/adablog/wp-content/uploads/2011/05/PT_101041.jpg" height="399" width="600" border="0" hspace="2" vspace="2" alt="Pt 101041" /></p>
<p><a href="http://bellard.org/jslinux/">Javascript PC Emulator &#8211; Linux in a browser</a>&#8230;</p>
<blockquote><p>This PC emulator is written in Javascript. The emulated hardware consists in:<br />
	•	a 32 bit x86 compatible CPU<br />
	•	a 8259 Programmble Interrupt Controller<br />
	•	a 8254 Programmble Interrupt Timer<br />
	•	a 16450 UART.</p>
<p>The code is written in pure Javascript using Typed Arrays which are available in recent browsers. It was tested with Firefox 4 and Google Chrome 11 on Linux, Window and Mac (it does not work with Chrome 12 beta. As far as I know, it is a bug in the browser). In any case, a fast Javascript engine is needed to have good performance.</p></blockquote>
<p><a href="http://bellard.org/jslinux/tech.html">Tech notes here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.adafruit.com/adablog/?feed=rss2&#038;p=14854</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>&#8220;Invent Your Own Computer Games with Python&#8221; &#8211; programming book for kids</title>
		<link>http://www.adafruit.com/blog/2010/06/11/invent-your-own-computer-games-with-python-programming-book-for-kids/</link>
		<comments>http://www.adafruit.com/blog/2010/06/11/invent-your-own-computer-games-with-python-programming-book-for-kids/#comments</comments>
		<pubDate>Fri, 11 Jun 2010 12:26:55 +0000</pubDate>
		<dc:creator>adafruit</dc:creator>
				<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://www.adafruit.com/blog/2010/06/11/invent-your-own-computer-games-with-python-programming-book-for-kids/</guid>
		<description><![CDATA[&#8220;Invent Your Own Computer Games with Python&#8221; &#8211; programming book for kids via BB. &#8220;Invent Your Own Computer Games with Python&#8221; is a free book that teaches you how to program in the Python programming language. Each chapter gives you the complete source code for a new game, and then teaches the programming concepts from [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.adafruit.com/adablog/wp-content/uploads/2010/06/517FAE-uPHL._SS500_.jpg" height="500" width="500" border="0" hspace="4" vspace="4" alt="517Fae-Uphl. Ss500 " /><br />
<a href="http://inventwithpython.com/">&#8220;Invent Your Own Computer Games with Python&#8221;</a> &#8211; programming book for kids via <a href="http://www.boingboing.net/2010/06/10/cc-licensed-book-on.html?utm_source=feedburner&amp;utm_medium=feed&amp;utm_campaign=Feed%3A+boingboing%2FiBag+%28Boing+Boing%29">BB</a>.</p>
<blockquote><p>
&#8220;Invent Your Own Computer Games with Python&#8221; is a free book that teaches you how to program in the Python programming language. Each chapter gives you the complete source code for a new game, and then teaches the programming concepts from the example.</p>
<p>&#8220;Invent with Python&#8221; was written to be understandable by kids as young as 10 to 12 years old, although it is great for anyone of any age who has never programmed before.</p>
<p>This second edition has revised and expanded content, including using the Pygame library to make games with graphics, animation, and sound.
</p></blockquote>
<p>You can buy it or read/download it online CC version.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.adafruit.com/adablog/?feed=rss2&#038;p=4944</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Example code for multi-button checker with debouncing</title>
		<link>http://www.adafruit.com/blog/2009/10/20/example-code-for-multi-button-checker-with-debouncing/</link>
		<comments>http://www.adafruit.com/blog/2009/10/20/example-code-for-multi-button-checker-with-debouncing/#comments</comments>
		<pubDate>Tue, 20 Oct 2009 18:21:38 +0000</pubDate>
		<dc:creator>ladyada</dc:creator>
				<category><![CDATA[arduino]]></category>
		<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://www.adafruit.com/blog/?p=1868</guid>
		<description><![CDATA[If you have a lot of button inputs for a project, keeping track of them (whether they&#8217;re pressed, just pressed or just released) and debouncing can get a bit hairy. here is some sample code that will keep track of as many buttons as you&#8217;d like. The example shows 6. To change the pins or [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.adafruit.com/adablog/wp-content/uploads/2009/10/6button.jpg" alt="6button" title="6button" width="550" height="458" class="alignnone size-full wp-image-1873" /></p>
<p>If you have a lot of button inputs for a project, keeping track of them (whether they&#8217;re pressed, just pressed or just released) and debouncing can get a bit hairy. here is some sample code that will keep track of as many buttons as you&#8217;d like. The example shows 6. To change the pins or number of buttons, just put them in the array called &#8220;buttons&#8221; and the rest of the code will automatically adjust. (The code is in Arduino-ese but its pretty much just straight up C)<br />
Enjoy!</p>
<pre style="border: 1px solid #CCCCCC; background-color: #f5f5f5; font-family: Fixed, monospace; font-size: 95%;">
#define DEBOUNCE 10  <font color = "#777755">// button debouncer, how many ms to debounce, 5+ ms is usually plenty</font>

<font color = "#777755">// here is where we define the buttons that we'll use. button "1" is the first, button "6" is the 6th, etc</font>
<font color = "#996600">byte</font> buttons[] = {14, 15, 16, 17, 18, 19}; <font color = "#777755">// the analog 0-5 pins are also known as 14-19</font>
<font color = "#777755">// This handy macro lets us determine how big the array up above is, by checking the size</font>
#define NUMBUTTONS sizeof(buttons)
<font color = "#777755">// we will track if a button is just pressed, just released, or 'currently pressed' </font>
<font color = "#996600">byte</font> pressed[NUMBUTTONS], justpressed[NUMBUTTONS], justreleased[NUMBUTTONS];

<font color = "#CC6600">void</font> <font color = "#993300"><b>setup</b></font>() {
  <font color = "#996600">byte</font> i;

  <font color = "#777755">// set up serial port</font>
  <font color = "#996600">Serial</font>.<font color = "#996600">begin</font>(9600);
  <font color = "#996600">Serial</font>.<font color = "#996600">print</font>(<font color = "#CC0000">"Button checker with "</font>);
  <font color = "#996600">Serial</font>.<font color = "#996600">print</font>(NUMBUTTONS, <font color = "#CC0000">DEC</font>);
  <font color = "#996600">Serial</font>.<font color = "#996600">println</font>(<font color = "#CC0000">" buttons"</font>);

  <font color = "#777755">// pin13 LED</font>
  <font color = "#996600">pinMode</font>(13, <font color = "#CC0000">OUTPUT</font>);

  <font color = "#777755">// Make input &#038; enable pull-up resistors on switch pins</font>
  <font color = "#CC6600">for</font> (i=0; i< NUMBUTTONS; i++) {
    <font color = "#996600">pinMode</font>(buttons[i], <font color = "#CC0000">INPUT</font>);
    <font color = "#996600">digitalWrite</font>(buttons[i], <font color = "#CC0000">HIGH</font>);
  }
}

<font color = "#CC6600">void</font> check_switches()
{
  <font color = "#CC6600">static</font> <font color = "#996600">byte</font> previousstate[NUMBUTTONS];
  <font color = "#CC6600">static</font> <font color = "#996600">byte</font> currentstate[NUMBUTTONS];
  <font color = "#CC6600">static</font> <font color = "#996600">long</font> lasttime;
  <font color = "#996600">byte</font> index;

  <font color = "#CC6600">if</font> (<font color = "#996600">millis</font>() < lasttime) {
     <font color = "#777755">// we wrapped around, lets just try again</font>
     lasttime = <font color = "#996600">millis</font>();
  }

  <font color = "#CC6600">if</font> ((lasttime + DEBOUNCE) > <font color = "#996600">millis</font>()) {
    <font color = "#777755">// not enough time has passed to debounce</font>
    <font color = "#CC6600">return</font>;
  }
  <font color = "#777755">// ok we have waited DEBOUNCE milliseconds, lets reset the timer</font>
  lasttime = <font color = "#996600">millis</font>();

  <font color = "#CC6600">for</font> (index = 0; index < NUMBUTTONS; index++) {
    justpressed[index] = 0;       <font color = "#777755">// when we start, we clear out the "just" indicators</font>
    justreleased[index] = 0;

    currentstate[index] = <font color = "#996600">digitalRead</font>(buttons[index]);   <font color = "#777755">// read the button</font>

    <font color = "#777755">/*     </font>
<font color = "#777755">    Serial.print(index, DEC);</font>
<font color = "#777755">    Serial.print(": cstate=");</font>
<font color = "#777755">    Serial.print(currentstate[index], DEC);</font>
<font color = "#777755">    Serial.print(", pstate=");</font>
<font color = "#777755">    Serial.print(previousstate[index], DEC);</font>
<font color = "#777755">    Serial.print(", press=");</font>
<font color = "#777755">    */</font>

    <font color = "#CC6600">if</font> (currentstate[index] == previousstate[index]) {
      <font color = "#CC6600">if</font> ((pressed[index] == <font color = "#CC0000">LOW</font>) &#038;&#038; (currentstate[index] == <font color = "#CC0000">LOW</font>)) {
          <font color = "#777755">// just pressed</font>
          justpressed[index] = 1;
      }
      <font color = "#CC6600">else</font> <font color = "#CC6600">if</font> ((pressed[index] == <font color = "#CC0000">HIGH</font>) &#038;&#038; (currentstate[index] == <font color = "#CC0000">HIGH</font>)) {
          <font color = "#777755">// just released</font>
          justreleased[index] = 1;
      }
      pressed[index] = !currentstate[index];  <font color = "#777755">// remember, digital HIGH means NOT pressed</font>
    }
    <font color = "#777755">//Serial.println(pressed[index], DEC);</font>
    previousstate[index] = currentstate[index];   <font color = "#777755">// keep a running tally of the buttons</font>
  }
}

<font color = "#CC6600">void</font> <font color = "#993300"><b>loop</b></font>() {
  check_switches();      <font color = "#777755">// when we check the switches we'll get the current state</font>

  <font color = "#CC6600">for</font> (<font color = "#996600">byte</font> i = 0; i < NUMBUTTONS; i++) {
    <font color = "#CC6600">if</font> (justpressed[i]) {
      <font color = "#996600">Serial</font>.<font color = "#996600">print</font>(i, <font color = "#CC0000">DEC</font>);
      <font color = "#996600">Serial</font>.<font color = "#996600">println</font>(<font color = "#CC0000">" Just pressed"</font>);
      <font color = "#777755">// remember, check_switches() will CLEAR the 'just pressed' flag</font>
    }
    <font color = "#CC6600">if</font> (justreleased[i]) {
      <font color = "#996600">Serial</font>.<font color = "#996600">print</font>(i, <font color = "#CC0000">DEC</font>);
      <font color = "#996600">Serial</font>.<font color = "#996600">println</font>(<font color = "#CC0000">" Just released"</font>);
      <font color = "#777755">// remember, check_switches() will CLEAR the 'just pressed' flag</font>
    }
    <font color = "#CC6600">if</font> (pressed[i]) {
      <font color = "#996600">Serial</font>.<font color = "#996600">print</font>(i, <font color = "#CC0000">DEC</font>);
      <font color = "#996600">Serial</font>.<font color = "#996600">println</font>(<font color = "#CC0000">" pressed"</font>);
      <font color = "#777755">// is the button pressed down at this moment</font>
    }
  }
}
</pre>
<p>if you want, you can even run the button checker in the background, which can make for a very easy interface. Remember that you&#8217;ll need to clear &#8220;just pressed&#8221;, etc. after checking or it will be &#8220;stuck&#8221; on</p>
<pre style="border: 1px solid #CCCCCC; background-color: #f5f5f5; font-family: Fixed, monospace; font-size: 95%;">
#define DEBOUNCE 10  <font color = "#777755">// button debouncer, how many ms to debounce, 5+ ms is usually plenty</font>

<font color = "#777755">// here is where we define the buttons that we'll use. button "1" is the first, button "6" is the 6th, etc</font>
<font color = "#996600">byte</font> buttons[] = {14, 15, 16, 17, 18, 19}; <font color = "#777755">// the analog 0-5 pins are also known as 14-19</font>
<font color = "#777755">// This handy macro lets us determine how big the array up above is, by checking the size</font>
#define NUMBUTTONS sizeof(buttons)
<font color = "#777755">// we will track if a button is just pressed, just released, or 'currently pressed' </font>
<font color = "#996600">volatile byte</font> pressed[NUMBUTTONS], justpressed[NUMBUTTONS], justreleased[NUMBUTTONS];

<font color = "#CC6600">void</font> <font color = "#993300"><b>setup</b></font>() {
  <font color = "#996600">byte</font> i;

  <font color = "#777755">// set up serial port</font>
  <font color = "#996600">Serial</font>.<font color = "#996600">begin</font>(9600);
  <font color = "#996600">Serial</font>.<font color = "#996600">print</font>(<font color = "#CC0000">"Button checker with "</font>);
  <font color = "#996600">Serial</font>.<font color = "#996600">print</font>(NUMBUTTONS, <font color = "#CC0000">DEC</font>);
  <font color = "#996600">Serial</font>.<font color = "#996600">println</font>(<font color = "#CC0000">" buttons"</font>);

  <font color = "#777755">// pin13 LED</font>
  <font color = "#996600">pinMode</font>(13, <font color = "#CC0000">OUTPUT</font>);

  <font color = "#777755">// Make input &#038; enable pull-up resistors on switch pins</font>
  <font color = "#CC6600">for</font> (i=0; i< NUMBUTTONS; i++) {
    <font color = "#996600">pinMode</font>(buttons[i], <font color = "#CC0000">INPUT</font>);
    <font color = "#996600">digitalWrite</font>(buttons[i], <font color = "#CC0000">HIGH</font>);
  }

  <font color = "#777755">// Run timer2 interrupt every 15 ms </font>
  TCCR2A = 0;
  TCCR2B = 1&lt;&lt;CS22 | 1&lt;&lt;CS21 | 1&lt;&lt;CS20;

  <font color = "#777755">//Timer2 Overflow Interrupt Enable</font>
  TIMSK2 |= 1&lt;&lt;TOIE2;

}

SIGNAL(TIMER2_OVF_vect) {
  check_switches();
}

<font color = "#CC6600">void</font> check_switches()
{
  <font color = "#CC6600">static</font> <font color = "#996600">byte</font> previousstate[NUMBUTTONS];
  <font color = "#CC6600">static</font> <font color = "#996600">byte</font> currentstate[NUMBUTTONS];
  <font color = "#CC6600">static</font> <font color = "#996600">long</font> lasttime;
  <font color = "#996600">byte</font> index;

  <font color = "#CC6600">if</font> (<font color = "#996600">millis</font>() < lasttime) {
     <font color = "#777755">// we wrapped around, lets just try again</font>
     lasttime = <font color = "#996600">millis</font>();
  }

  <font color = "#CC6600">if</font> ((lasttime + DEBOUNCE) > <font color = "#996600">millis</font>()) {
    <font color = "#777755">// not enough time has passed to debounce</font>
    <font color = "#CC6600">return</font>;
  }
  <font color = "#777755">// ok we have waited DEBOUNCE milliseconds, lets reset the timer</font>
  lasttime = <font color = "#996600">millis</font>();

  <font color = "#CC6600">for</font> (index = 0; index < NUMBUTTONS; index++) {

    currentstate[index] = <font color = "#996600">digitalRead</font>(buttons[index]);   <font color = "#777755">// read the button</font>

    <font color = "#777755">/*     </font>
<font color = "#777755">    Serial.print(index, DEC);</font>
<font color = "#777755">    Serial.print(": cstate=");</font>
<font color = "#777755">    Serial.print(currentstate[index], DEC);</font>
<font color = "#777755">    Serial.print(", pstate=");</font>
<font color = "#777755">    Serial.print(previousstate[index], DEC);</font>
<font color = "#777755">    Serial.print(", press=");</font>
<font color = "#777755">    */</font>

    <font color = "#CC6600">if</font> (currentstate[index] == previousstate[index]) {
      <font color = "#CC6600">if</font> ((pressed[index] == <font color = "#CC0000">LOW</font>) &#038;&#038; (currentstate[index] == <font color = "#CC0000">LOW</font>)) {
          <font color = "#777755">// just pressed</font>
          justpressed[index] = 1;
      }
      <font color = "#CC6600">else</font> <font color = "#CC6600">if</font> ((pressed[index] == <font color = "#CC0000">HIGH</font>) &#038;&#038; (currentstate[index] == <font color = "#CC0000">HIGH</font>)) {
          <font color = "#777755">// just released</font>
          justreleased[index] = 1;
      }
      pressed[index] = !currentstate[index];  <font color = "#777755">// remember, digital HIGH means NOT pressed</font>
    }
    <font color = "#777755">//Serial.println(pressed[index], DEC);</font>
    previousstate[index] = currentstate[index];   <font color = "#777755">// keep a running tally of the buttons</font>
  }
}

<font color = "#CC6600">void</font> <font color = "#993300"><b>loop</b></font>() {
  <font color = "#CC6600">for</font> (<font color = "#996600">byte</font> i = 0; i < NUMBUTTONS; i++) {
    <font color = "#CC6600">if</font> (justpressed[i]) {
      justpressed[i] = 0;
      <font color = "#996600">Serial</font>.<font color = "#996600">print</font>(i, <font color = "#CC0000">DEC</font>);
      <font color = "#996600">Serial</font>.<font color = "#996600">println</font>(<font color = "#CC0000">" Just pressed"</font>);
      <font color = "#777755">// remember, check_switches() will CLEAR the 'just pressed' flag</font>
    }
    <font color = "#CC6600">if</font> (justreleased[i]) {
      justreleased[i] = 0;
      <font color = "#996600">Serial</font>.<font color = "#996600">print</font>(i, <font color = "#CC0000">DEC</font>);
      <font color = "#996600">Serial</font>.<font color = "#996600">println</font>(<font color = "#CC0000">" Just released"</font>);
      <font color = "#777755">// remember, check_switches() will CLEAR the 'just pressed' flag</font>
    }
    <font color = "#CC6600">if</font> (pressed[i]) {
      <font color = "#996600">Serial</font>.<font color = "#996600">print</font>(i, <font color = "#CC0000">DEC</font>);
      <font color = "#996600">Serial</font>.<font color = "#996600">println</font>(<font color = "#CC0000">" pressed"</font>);
      <font color = "#777755">// is the button pressed down at this moment</font>
    }
  }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.adafruit.com/adablog/?feed=rss2&#038;p=1868</wfw:commentRss>
		<slash:comments>26</slash:comments>
		</item>
		<item>
		<title>Add a watch crystal to a Boarduino</title>
		<link>http://www.adafruit.com/blog/2008/04/12/add-a-watch-crystal-to-a-boarduino/</link>
		<comments>http://www.adafruit.com/blog/2008/04/12/add-a-watch-crystal-to-a-boarduino/#comments</comments>
		<pubDate>Sat, 12 Apr 2008 17:48:28 +0000</pubDate>
		<dc:creator>ladyada</dc:creator>
				<category><![CDATA[arduino]]></category>
		<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://www.ladyada.net/rant/2008/04/add-a-watch-crystal-to-a-boarduino/</guid>
		<description><![CDATA[If you want to make a clock with an Arduino/Boarduino/AVR, there is a way to hook up a precision 32khz watch crystal mtbf0 shows you how! pictured above is his LCD clockduino! Trialex followed up with a really-big-7-segment clock (in the same thread)]]></description>
			<content:encoded><![CDATA[<p><img src="http://farm3.static.flickr.com/2208/2207635811_a084c2d8e9.jpg" alt="" /><br />
If you want to make a clock with an Arduino/Boarduino/AVR, there is a way to hook up a precision 32khz watch crystal<br />
<a href="http://www.ladyada.net/forums/viewtopic.php?t=4418"><br />
mtbf0 shows you how!</a> pictured above is his LCD clockduino!</p>
<p>Trialex followed up with a really-big-7-segment clock (in the same thread)<br />
<a href='http://www.adafruit.com/adablog/wp-content/uploads/2008/04/dsc01341smallmu7.jpg' title='dsc01341smallmu7.jpg'><img src='http://www.adafruit.com/adablog/wp-content/uploads/2008/04/dsc01341smallmu7-150x112.jpg' alt='dsc01341smallmu7.jpg' /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.adafruit.com/adablog/?feed=rss2&#038;p=144</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>SpokePOVsoft update</title>
		<link>http://www.adafruit.com/blog/2007/07/17/spokepovsoft-update/</link>
		<comments>http://www.adafruit.com/blog/2007/07/17/spokepovsoft-update/#comments</comments>
		<pubDate>Tue, 17 Jul 2007 22:42:54 +0000</pubDate>
		<dc:creator>ladyada</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[spokepov]]></category>

		<guid isPermaLink="false">http://www.ladyada.net/rant/2007/07/spokepovsoft-update/</guid>
		<description><![CDATA[I had a bug that caused serial port support to suddenly stop working and there was a corrupt .dmg file so here is a new set of packages with some updates! Port delay is definable. SpokePOV used to &#8216;guess&#8217; what the correct delay is but I think it might be wiser to have the user [...]]]></description>
			<content:encoded><![CDATA[<p><a href='http://www.ladyada.net/make/spokepov/' title='multibank.gif'><img src='http://www.adafruit.com/adablog/wp-content/uploads/2007/07/multibank.gif' alt='multibank.gif' /></a><br />
I had a bug that caused serial port support to suddenly stop working and there was a corrupt .dmg file so here is a new set of packages with some updates!</p>
<ul>
<li>Port delay is definable. SpokePOV used to &#8216;guess&#8217; what the correct delay is but I think it might be wiser to have the user tweak it as necessary</li>
<li>Support for up to 32 banks of memory. What you need so much for I have no idea but hey, its there now!</li>
<li>Windows version now comes with a spiffy installer. Just like Real Software!</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.adafruit.com/adablog/?feed=rss2&#038;p=85</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>S3 makes website hosting reasonable again</title>
		<link>http://www.adafruit.com/blog/2007/04/02/s3-makes-website-hosting-reasonable-again/</link>
		<comments>http://www.adafruit.com/blog/2007/04/02/s3-makes-website-hosting-reasonable-again/#comments</comments>
		<pubDate>Tue, 03 Apr 2007 03:09:33 +0000</pubDate>
		<dc:creator>ladyada</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[kits]]></category>
		<category><![CDATA[projects]]></category>
		<category><![CDATA[site updates]]></category>

		<guid isPermaLink="false">http://www.ladyada.net/rant/2007/04/s3-makes-website-hosting-reasonable-again/</guid>
		<description><![CDATA[Amazon&#8217;s S3 (Simple Storage Service) isn&#8217;t new, but its certainly gaining traction. Its a wonderful product for people who have a lot of content on their site (images, video, downloads, pdfs) but not a lot of money. Data storage costs $0.15 per GB-Month (prorated), and $0.20 per GB. No minimums, rounded up to the nearest [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.amazon.com/gp/browse.html?node=16427261">Amazon&rsquo;s S3 (Simple Storage Service)</a> isn&rsquo;t new, but its certainly gaining traction. Its a wonderful product for people who have a lot of content on their site (images, video, downloads, pdfs) but not a lot of money. Data storage costs $0.15 per GB-Month (prorated), and $0.20 per GB. No minimums, rounded up to the nearest cent.</p>
<p>There are a lot of great providers out there (I use <a href="http://www.laughingsquid.net">Laughing Squid</a> and highly recommend it) but even LS&rsquo;s ‘largest&rsquo; package is too small for <a href="http://www.ladyada.net">ladyada.net</a>… What to do? Easy: Host all that bulky content at S3, then use <a href="http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html">mod_rewrite</a> to reroute it over to S3. (You could also do it with php, asp or similar for higher &rsquo;security&rsquo; but mod_rewrite is lighter and good enough for me)</p>
<p><img src="http://www.ladyada.net/images/mintyboost/assemblyv12/inductorusbplace_t.jpg" alt="" width=200 /><br />
For example, this image has the url reference “http://www.ladyada.net/images/mintyboost/assemblyv12/inductorusbplace_t.jpg” but if you access that url in your browser, it is automatically rewritten by apache to http://s3.amazonaws.com/ladyadanet_mintyboost/assemblyv12/inductorusbplace_t.jpg</p>
<p>(same with my research pdf, a big pdf that easily accounted for 500M a day of traffic at its peak! http://www.ladyada.net/media/common/thesis.pdf -> http://s3.amazonaws.com/ladyadanet_common/thesis.pdf , S3 doesn&rsquo;t care what the data is or how its encoded)</p>
<p>Of course mod_rewrite is not necessary, you can always just directly reference s3.amazonaws.com but that makes it harder to move the content around if you decide to eventually go with another service (or if s3 goes away one day!)</p>
<p>OK so, what&rsquo;s the point and what does this have to do with electronics, eh? Well one of the killer apps of open source and public domain electronics is documentation. That means media. And media storage, backup and transfer is extremely expensive for the everyday person. It becomes increasingly difficult to host a project when one digg-storm or slashdotting makes that ‘free&rsquo; webpage account go down.</p>
<p>Edit: I use the <a href="http://www.rjonna.com/ext/s3fox.php">Firefox S3 plugin</a> to upload and set the access control on my files.</p>
<p>Are you using S3 or something similar for your projects, kits or documentation? Leave a comment or email! Its always interesting to see what other people are doing in this space.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.adafruit.com/adablog/?feed=rss2&#038;p=72</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>You have defeated IE6! You gain 12 EXP and 4 GOLD!</title>
		<link>http://www.adafruit.com/blog/2007/02/16/you-have-defeated-ie6-you-gain-12-exp-and-4-gold/</link>
		<comments>http://www.adafruit.com/blog/2007/02/16/you-have-defeated-ie6-you-gain-12-exp-and-4-gold/#comments</comments>
		<pubDate>Fri, 16 Feb 2007 10:02:09 +0000</pubDate>
		<dc:creator>ladyada</dc:creator>
				<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://www.ladyada.net/rant/?p=49</guid>
		<description><![CDATA[I finally got around to rewriting the flickrnotes code i wrote to support IE6/7 as well as overlib. Ironically, as a side effect, I had to do this funky opacity thing because in IE you cant have onMouseOver() on an &#8216;empty&#8217; DIV or SPAN tag unless it has a background color. However, background colors with [...]]]></description>
			<content:encoded><![CDATA[<p>I finally got around to rewriting the flickrnotes code i wrote to support IE6/7 as well as overlib. Ironically, as a side effect, I had to do this funky opacity thing because in IE you cant have onMouseOver() on an &#8216;empty&#8217; DIV or SPAN tag unless it has a background color. However, background colors with opacity work just fine.<br />
Hence:<br />
<script language="Javascript" src="http://www.ladyada.net/flickrnotes.php?156025389"></script><noscript><a href="http://www.flickr.com/photos/ladyada/156025389/"> <img src="http://static.flickr.com/61/156025389_9c75f4fa5c.jpg" /> </a> </noscript><br />
One could always just keep the Opacity 0% and mess with outlines but i kinda got to liking this look.</p>
<p><a href="http://www.ladyada.net/flickrnotes.txt">Download it here</a>  (and rename it to a .php) you will need <a href="http://www.bosrup.com/web/overlib/">overlib.js</a> (4.21 is what i use) installed too. <a href="http://www.ladyada.net/flickrtest.html">An example page is here, read the source for an example.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.adafruit.com/adablog/?feed=rss2&#038;p=49</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Updated MIDIsense software, now for Mac too!</title>
		<link>http://www.adafruit.com/blog/2007/01/11/updated-midisense-software-now-for-mac-too/</link>
		<comments>http://www.adafruit.com/blog/2007/01/11/updated-midisense-software-now-for-mac-too/#comments</comments>
		<pubDate>Fri, 12 Jan 2007 04:53:42 +0000</pubDate>
		<dc:creator>ladyada</dc:creator>
				<category><![CDATA[announce]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[kits]]></category>
		<category><![CDATA[midisense]]></category>

		<guid isPermaLink="false">http://www.ladyada.net/rant/?p=45</guid>
		<description><![CDATA[I fixed some icky problems (in wxMIDI!) and now the MIDIsense software is crosscompiling nicely between Mac and Windows, therefore there is now fast and updated software for both platforms. Rad! Download it now!]]></description>
			<content:encoded><![CDATA[<p><img src="http://ladyada.net/images/midisense/soft/mainscreen.gif" /></p>
<p>I fixed some icky problems (in wxMIDI!) and now the MIDIsense software is crosscompiling nicely between Mac and Windows, therefore there is now fast and updated software for both platforms. Rad! <a href="http://www.ladyada.net/make/midisense/download.html">Download it now!</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.adafruit.com/adablog/?feed=rss2&#038;p=606</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Windows MIDIsense software</title>
		<link>http://www.adafruit.com/blog/2006/10/21/windows-midisense-software/</link>
		<comments>http://www.adafruit.com/blog/2006/10/21/windows-midisense-software/#comments</comments>
		<pubDate>Sat, 21 Oct 2006 23:27:16 +0000</pubDate>
		<dc:creator>ladyada</dc:creator>
				<category><![CDATA[announce]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[kits]]></category>
		<category><![CDATA[midisense]]></category>

		<guid isPermaLink="false">http://www.ladyada.net/rant/?p=36</guid>
		<description><![CDATA[If you wanted to try out the MIDIsense hardware but didn&#8217;t have a Mac, well I finally finished porting the wxpython code to C++ and its all much faster and more reliable. I also improved the interface and robustness. Try it out and let me know how it goes, available for download from sourceforge]]></description>
			<content:encoded><![CDATA[<p><script language="Javascript" src="http://www.ladyada.net/flickrnotes.php?275674969"></script><noscript><a href="http://www.flickr.com/photos/ladyada/275674969/"> <img xsrc="http://static.flickr.com/82/275674969_3f9a5f23a6.jpg" /> </a> </noscript></p>
<p>If you wanted to try out the MIDIsense hardware but didn&#8217;t have a Mac, well I finally finished porting the wxpython code to C++ and its all much faster and more reliable. I also improved the interface and robustness. Try it out and let me know how it goes, <a href="http://sourceforge.net/project/showfiles.php?group_id=159370 ">available for download from sourceforge</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.adafruit.com/adablog/?feed=rss2&#038;p=597</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>embed flickr photos!</title>
		<link>http://www.adafruit.com/blog/2006/02/20/embed-flickr-photos/</link>
		<comments>http://www.adafruit.com/blog/2006/02/20/embed-flickr-photos/#comments</comments>
		<pubDate>Mon, 20 Feb 2006 05:58:02 +0000</pubDate>
		<dc:creator>ladyada</dc:creator>
				<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://www.ladyada.net/rant/?p=4</guid>
		<description><![CDATA[This weekend I stayed indoors because it was insanely cold, and hacked javascript/php to create a php script that allows one to embed flickr photos into webpages and have the notes show up. Like in midisense sensor soldering instructions (mouseover in the assembly pictures). If you want to grab it, its available for download: flickrnotes.txt [...]]]></description>
			<content:encoded><![CDATA[<p>This weekend I stayed indoors because it was insanely cold, and hacked javascript/php to create a php script that allows one to embed flickr photos into webpages and have the notes show up. Like in <a href="http://www.ladyada.net/make/midisense/makesensor.html">midisense sensor soldering instructions</a> (mouseover in the assembly pictures). If you want to grab it, its available for download: <a href="http://www.ladyada.net/library/flickrnotes.txt">flickrnotes.txt</a> (rename it php of course) you&#8217;ll need php installed, as well as commandline curl (usually /usr/bin/curl) although im sure it could be modifed to use something else. some work has to be done, i intend to one day integrate it with overLIB which makes nice popups. regardless, hooray for notes!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.adafruit.com/adablog/?feed=rss2&#038;p=4</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

