<?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>Standing On The Shoulders Of Ants &#187; Electronics</title>
	<atom:link href="http://blog.defsdoor.org/category/electronics/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.defsdoor.org</link>
	<description>It&#039;s the little guys that counts</description>
	<lastBuildDate>Tue, 10 Apr 2012 21:24:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Arduino Button Debounce</title>
		<link>http://blog.defsdoor.org/2012/01/13/arduino-button-debounce/</link>
		<comments>http://blog.defsdoor.org/2012/01/13/arduino-button-debounce/#comments</comments>
		<pubDate>Fri, 13 Jan 2012 09:04:11 +0000</pubDate>
		<dc:creator>defsdoor</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Electronics]]></category>
		<category><![CDATA[arduino]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[electronics]]></category>

		<guid isPermaLink="false">http://blog.defsdoor.org/?p=42</guid>
		<description><![CDATA[A simple reusable button debounce routine for Arduino projects.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m currently working on a project to hack my daughter&#8217;s &#8220;Stars&#8221; tortoise.  It uses the shell of the tortoise as a mask to project stars on to the ceiling.  It can project 3 different colours &#8211; selected by buttons on it&#8217;s back.</p>
<p>I plan to replace the internals with a simple Arduino based circuit that has one (or more) RGB LEDs and can offer colour cycling options as well as static colours.</p>
<p>As part of this I need to manage button presses etc.. so I abstracted a simple button handler that also copes with debounce.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">struct</span> button <span style="color: #009900;">&#123;</span>
  byte pin<span style="color: #339933;">;</span>
  byte debounce<span style="color: #339933;">;</span>
  byte released<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #339933;">#define NOTPRESSED 0</span>
<span style="color: #339933;">#define PRESSED 1</span>
<span style="color: #339933;">#define DEBOUNCE 2</span>
<span style="color: #339933;">#define RELEASED 3</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Debounce delay in approx millisecs</span>
<span style="color: #339933;">#define BOUNCE 200</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Main loop delay in millisecs (used by delay)</span>
<span style="color: #339933;">#define DELAY 10</span>
&nbsp;
<span style="color: #339933;">/</span> Two example buttons
<span style="color: #993333;">struct</span> button modebutton <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> modepin<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: #993333;">struct</span> button selectbutton <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> selectpin<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>
&nbsp;
<span style="color: #666666; font-style: italic;">// Button Handler</span>
<span style="color: #993333;">int</span> buttonHandler<span style="color: #009900;">&#40;</span><span style="color: #993333;">struct</span> button <span style="color: #339933;">*</span> b<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> b<span style="color: #339933;">-&gt;</span>debounce <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>        <span style="color: #666666; font-style: italic;">// Debounce delay</span>
    b<span style="color: #339933;">-&gt;</span>debounce<span style="color: #339933;">--;</span>
    <span style="color: #b1b100;">return</span><span style="color: #009900;">&#40;</span> DEBOUNCE <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: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> digitalRead<span style="color: #009900;">&#40;</span>b<span style="color: #339933;">-&gt;</span>pin<span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> HIGH <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span> b<span style="color: #339933;">-&gt;</span>released <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>  <span style="color: #666666; font-style: italic;">// Button has been released</span>
        b<span style="color: #339933;">-&gt;</span>debounce <span style="color: #339933;">=</span> BOUNCE <span style="color: #339933;">/</span> DELAY<span style="color: #339933;">;</span>
        b<span style="color: #339933;">-&gt;</span>released <span style="color: #339933;">=</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span><span style="color: #009900;">&#40;</span> PRESSED <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: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>                 <span style="color: #666666; font-style: italic;">// Button released</span>
      b<span style="color: #339933;">-&gt;</span>released <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">return</span><span style="color: #009900;">&#40;</span> RELEASED <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: #b1b100;">return</span><span style="color: #009900;">&#40;</span> NOTPRESSED <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;">// example usage</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> buttonHandler<span style="color: #009900;">&#40;</span> <span style="color: #339933;">&amp;</span>modebutton <span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> PRESSED <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  mode <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>mode <span style="color: #339933;">+</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span> <span style="color: #0000dd;">3</span><span style="color: #339933;">;</span></pre></div></div>

<p>It&#8217;s not object oriented &#8211; that would be overkill and I rarely use OOP on what are essentially simple programs with an enforced small footprint.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.defsdoor.org/2012/01/13/arduino-button-debounce/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Monochron Clock</title>
		<link>http://blog.defsdoor.org/2012/01/11/monochron-clock/</link>
		<comments>http://blog.defsdoor.org/2012/01/11/monochron-clock/#comments</comments>
		<pubDate>Wed, 11 Jan 2012 22:30:26 +0000</pubDate>
		<dc:creator>defsdoor</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Electronics]]></category>

		<guid isPermaLink="false">http://blog.defsdoor.org/?p=36</guid>
		<description><![CDATA[Monochron clock from ladyada.net]]></description>
			<content:encoded><![CDATA[<p>I just built one of these -</p>
<p><a title="Monochron Clock from LadyAda" href="http://www.ladyada.net/make/monochron/index.html"><br />
<img class="size-full wp-image-39 aligncenter" title="monochron_t" src="http://blog.defsdoor.org/wp-content/uploads/2012/01/monochron_t.jpg" alt="" width="500" height="385" /><br />
</a></p>
<p style="text-align: left;">A couple of soldering issues initially but all working well in the end.</p>
<p>Now considering changing the display to this -</p>
<p><img class="aligncenter" title="Space Invaders" src="http://www.adafruit.com/adablog/wp-content/uploads/2010/03/SANY3163-1a.jpg" alt="" width="550" height="482" /></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.defsdoor.org/2012/01/11/monochron-clock/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

