<?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>DANDUINO</title>
	<atom:link href="http://danplows.com/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://danplows.com/blog</link>
	<description>An Arduino resource by evangelist Dan Plows</description>
	<lastBuildDate>Mon, 30 Apr 2012 21:56:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Android controlled papercraft head [Code+Video]</title>
		<link>http://danplows.com/blog/android-controlled-papercraft-head-codevideo/</link>
		<comments>http://danplows.com/blog/android-controlled-papercraft-head-codevideo/#comments</comments>
		<pubDate>Mon, 30 Apr 2012 21:55:57 +0000</pubDate>
		<dc:creator>Dan Plows</dc:creator>
				<category><![CDATA[Android]]></category>

		<guid isPermaLink="false">http://danplows.com/blog/?p=266</guid>
		<description><![CDATA[Controlling my papercraft head over bluetooth with a custom Android app connected to an Arduino and a servo. Code: #include &#60;SoftwareSerial.h&#62; #include &#60;MeetAndroid.h&#62; #include &#60;Servo.h&#62; Servo spin; // horizontal //Servo tilt; // vertical int spinPos = 0; //int tiltPos = 0; // TX = digital pin 2, RX = digital pin 3 SoftwareSerial portOne(2, 3); [...]]]></description>
			<content:encoded><![CDATA[<p>Controlling my papercraft head over bluetooth with a custom Android app connected to an Arduino and a servo.<br />
<span id="more-266"></span><br />
<iframe width="420" height="315" src="http://www.youtube.com/embed/Q-VR20Xprq4" frameborder="0" allowfullscreen></iframe></p>
<p><strong>Code:</strong><br />
<code>#include &lt;SoftwareSerial.h&gt;<br />
#include &lt;MeetAndroid.h&gt;<br />
#include &lt;Servo.h&gt; </p>
<p>Servo spin; // horizontal<br />
//Servo tilt; // vertical<br />
int spinPos = 0;<br />
//int tiltPos = 0;</p>
<p>// TX = digital pin 2, RX = digital pin 3<br />
SoftwareSerial portOne(2, 3);<br />
MeetAndroid meetAndroid;</p>
<p>void setup()<br />
{<br />
  Serial.begin(57600);<br />
  spin.attach(9);<br />
  //tilt.attach(10);<br />
  // Start the software serial port<br />
  portOne.begin(57600);<br />
  portOne.listen();<br />
  // sync with android app<br />
  /*meetAndroid.registerFunction(stringValue, '^'); // keyboard<br />
  meetAndroid.registerFunction(stringValue, '`'); // backspace*/<br />
  meetAndroid.registerFunction(stringValue, '~'); // mouse<br />
}</p>
<p>void loop()<br />
{<br />
  // while there is data coming in...<br />
  while (portOne.available() &gt; 0) {<br />
    // read value of character<br />
    char c = portOne.read();<br />
    Serial.print(c);<br />
    Serial.println();<br />
    if(c == 'L' &amp;&amp; spinPos &gt; 0){<br />
      spinPos -= 10;<br />
      spin.write(spinPos);<br />
    }<br />
    else if(c == 'R' &amp;&amp; spinPos &lt; 180){<br />
      spinPos += 10;<br />
      spin.write(spinPos);<br />
    }<br />
    /*else if(c == 'U' &amp;&amp; tiltPos &gt; 0){<br />
      tiltPos -= 10;<br />
      tilt.write(tiltPos);<br />
    }<br />
    else if(c == 'D' &amp;&amp; tiltPos &lt; 180){<br />
      tiltPos += 10;<br />
      tilt.write(tiltPos);<br />
    }*/<br />
  }<br />
}</p>
<p>void stringValue(byte flag, byte numOfValues){}</code></p>
]]></content:encoded>
			<wfw:commentRss>http://danplows.com/blog/android-controlled-papercraft-head-codevideo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Control Keyboard &amp; Mouse w/ Android app via Arduino [VIDEO]</title>
		<link>http://danplows.com/blog/control-keyboard-mouse-w-android-app-via-arduino-video/</link>
		<comments>http://danplows.com/blog/control-keyboard-mouse-w-android-app-via-arduino-video/#comments</comments>
		<pubDate>Mon, 30 Apr 2012 21:34:39 +0000</pubDate>
		<dc:creator>Dan Plows</dc:creator>
				<category><![CDATA[Android]]></category>

		<guid isPermaLink="false">http://danplows.com/blog/?p=263</guid>
		<description><![CDATA[Demonstrating my Android app that controls my computer&#8217;s keyboard and mouse functionality via Bluetooth and an Arduino. Want to build this project? View my step-by-step Instructable at http://www.instructables.com/id/Control-Keyboard-Mouse-w-Android-app-via-Arduin/.]]></description>
			<content:encoded><![CDATA[<p>Demonstrating my Android app that controls my computer&#8217;s keyboard and mouse functionality via Bluetooth and an Arduino.</p>
<p>Want to build this project? View my step-by-step Instructable at <a href="http://www.instructables.com/id/Control-Keyboard-Mouse-w-Android-app-via-Arduin/" target="_blank">http://www.instructables.com/id/Control-Keyboard-Mouse-w-Android-app-via-Arduin/</a>.</p>
<p><span id="more-263"></span><br />
<iframe width="420" height="315" src="http://www.youtube.com/embed/K5vy6fJHUSA" frameborder="0" allowfullscreen></iframe></p>
]]></content:encoded>
			<wfw:commentRss>http://danplows.com/blog/control-keyboard-mouse-w-android-app-via-arduino-video/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My First Robot&#8217;s Progression [VIDEOS]</title>
		<link>http://danplows.com/blog/my-first-robots-progression/</link>
		<comments>http://danplows.com/blog/my-first-robots-progression/#comments</comments>
		<pubDate>Mon, 30 Apr 2012 21:24:10 +0000</pubDate>
		<dc:creator>Dan Plows</dc:creator>
				<category><![CDATA[Robots]]></category>

		<guid isPermaLink="false">http://danplows.com/blog/?p=251</guid>
		<description><![CDATA[This post lists videos in chronological order to show my first robot&#8217;s progression over time. 1. First steps :&#8217;) 2. Programmed (pre-determined) turns 3. Simple turns with custom Android app over Bluetooth 4. Avoiding object with a PING))) ultrasonic sensor 5. Robot&#8217;s perspective while avoiding objects 6. Choosing which way to turn (based on distance)]]></description>
			<content:encoded><![CDATA[<p>This post lists videos in chronological order to show my first robot&#8217;s progression over time.</p>
<p><span id="more-251"></span></p>
<p>1. First steps :&#8217;)</p>
<p><iframe width="420" height="315" src="http://www.youtube.com/embed/20j02At9JEU" frameborder="0" allowfullscreen></iframe></p>
<hr style="width:500px;" />
<p>2. Programmed (pre-determined) turns</p>
<p><iframe width="420" height="315" src="http://www.youtube.com/embed/arfMBLxows0" frameborder="0" allowfullscreen></iframe></p>
<hr style="width:500px;" />
<p>3. Simple turns with custom Android app over Bluetooth</p>
<p><iframe width="420" height="315" src="http://www.youtube.com/embed/yBknWrqEtlQ" frameborder="0" allowfullscreen></iframe></p>
<hr style="width:500px;" />
<p>4. Avoiding object with a PING))) ultrasonic sensor</p>
<p><iframe width="420" height="315" src="http://www.youtube.com/embed/CvZIwSKaEvQ" frameborder="0" allowfullscreen></iframe></p>
<hr style="width:500px;" />
<p>5. Robot&#8217;s perspective while avoiding objects</p>
<p><iframe width="420" height="315" src="http://www.youtube.com/embed/P-hr47gOhqk" frameborder="0" allowfullscreen></iframe></p>
<hr style="width:500px;" />
<p>6. Choosing which way to turn (based on distance)<br />
<iframe width="420" height="315" src="http://www.youtube.com/embed/pYbW_ZkDlIU" frameborder="0" allowfullscreen></iframe></p>
]]></content:encoded>
			<wfw:commentRss>http://danplows.com/blog/my-first-robots-progression/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Control Servos with a Nintendo NES Controller</title>
		<link>http://danplows.com/blog/control-servos-with-a-nintendo-nes-controller/</link>
		<comments>http://danplows.com/blog/control-servos-with-a-nintendo-nes-controller/#comments</comments>
		<pubDate>Sat, 09 Jul 2011 23:57:33 +0000</pubDate>
		<dc:creator>Dan Plows</dc:creator>
				<category><![CDATA[Nintendo Controller]]></category>

		<guid isPermaLink="false">http://danplows.com/blog/?p=226</guid>
		<description><![CDATA[If you&#8217;ve read my two previous posts How to Hook Up Servos and Hack a Nintendo (NES) Controller, combining the two is simple. This post details how to control 2 servos with a NES controller. Wiring There&#8217;s only one +5V pin on the Arduino (UNO). You&#8217;ll need to use the power rail(s) on a breadboard [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve read my two previous posts <a href="http://danplows.com/blog/how-to-hook-up-servos/">How to Hook Up Servos</a> and <a href="http://danplows.com/blog/hack-a-nintendo-nes-controller/">Hack a Nintendo (NES) Controller</a>, combining the two is simple. This post details how to control 2 servos with a NES controller.</p>
<p><span id="more-226"></span></p>
<p><strong>Wiring</strong></p>
<p>There&#8217;s only one +5V pin on the Arduino (UNO). You&#8217;ll need to use the power rail(s) on a breadboard and some extra jumper wires in order to provide power from the Arduino to the 2 servos and the NES controller. Other than that, you&#8217;ll hook up the parts normally.</p>
<div class="yoxview"><div id="attachment_232" class="wp-caption aligncenter" style="width: 310px"><a href="http://danplows.com/blog/wp-content/uploads/2011/07/nes_servo.jpg"><img src="http://danplows.com/blog/wp-content/uploads/2011/07/nes_servo-300x168.jpg" alt="nes_servos" title="2 Servos and NES controller wired to Arduino" width="300" height="168" class="size-medium wp-image-232" /></a><p class="wp-caption-text">2 Servos and NES controller wired to an Arduino (a mess)</p></div></div>
<p><strong>Code</strong></p>
<p><code>#include &lt;NESpad.h&gt;<br />
#include &lt;Servo.h&gt;</p>
<p>NESpad nintendo = NESpad(2,3,4);<br />
Servo myServo;<br />
Servo otherServo;</p>
<p>byte state = 0;<br />
int pos = 1; // myServo<br />
int val = 1; // otherServo</p>
<p>void setup() {<br />
  myServo.attach(9);<br />
  otherServo.attach(10);<br />
  Serial.begin(9600);<br />
}</p>
<p>void loop() {</p>
<p>  delay(5);</p>
<p>  state = nintendo.buttons();</p>
<p>  // Left<br />
  if (state &amp; NES_LEFT){<br />
      if(pos &gt; 1){<br />
        pos = pos - 10;<br />
        myServo.write(pos);<br />
        delay(15);<br />
        Serial.println(pos);<br />
      }<br />
  }</p>
<p>  //Right<br />
  if (state &amp; NES_RIGHT){<br />
      if(pos &lt; 179){<br />
        pos = pos + 10;<br />
        myServo.write(pos);<br />
        delay(15);<br />
        Serial.println(pos);<br />
      }<br />
  }</p>
<p>  //B<br />
  if (state &amp; NES_B){<br />
    if(val &gt; 1){<br />
      val = val - 10;<br />
      otherServo.write(val);<br />
      delay(15);<br />
      Serial.println(val);<br />
    }  </p>
<p>  }</p>
<p>  // A<br />
  if (state &amp; NES_A){<br />
    if(val &lt; 179){<br />
      val = val + 10;<br />
      otherServo.write(val);<br />
      delay(15);<br />
      Serial.println(val);<br />
    }<br />
  }</p>
<p>}</code></p>
<p><strong>Video</strong></p>
<p><iframe width="480" height="390" src="http://www.youtube.com/embed/N0Lu1C_j6dA" frameborder="0" allowfullscreen></iframe></p>
]]></content:encoded>
			<wfw:commentRss>http://danplows.com/blog/control-servos-with-a-nintendo-nes-controller/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Hook Up &gt; Servos</title>
		<link>http://danplows.com/blog/how-to-hook-up-servos/</link>
		<comments>http://danplows.com/blog/how-to-hook-up-servos/#comments</comments>
		<pubDate>Sat, 09 Jul 2011 23:14:12 +0000</pubDate>
		<dc:creator>Dan Plows</dc:creator>
				<category><![CDATA[How To Hook Up Parts]]></category>

		<guid isPermaLink="false">http://danplows.com/blog/?p=216</guid>
		<description><![CDATA[A Servo, short for &#8220;servomechanism&#8221;, can rotate 180 or continuous 360 (depending on the type). Servos consist of a motor &#038; a potentiometer and can easily be hooked up to an Arduino. This post details how. Parts Hobby/Micro Servo (HiTec HS-322HD is used in this post) 3 Jumper Wires (red, black, &#38; yellow) Arduino USB [...]]]></description>
			<content:encoded><![CDATA[<p>A Servo, short for &#8220;servomechanism&#8221;, can rotate 180 or continuous 360 (depending on the type). Servos consist of a motor &#038; a potentiometer and can easily be hooked up to an Arduino. This post details how.</p>
<p><span id="more-216"></span></p>
<p><strong>Parts</strong></p>
<ul>
<li>Hobby/Micro Servo (HiTec HS-322HD is used in this post)</li>
<li>3 Jumper Wires (red, black, &amp; yellow)</li>
<li>Arduino</li>
<li>USB cable (A to B)</li>
</ul>
<p><strong>Steps</strong></p>
<ol>
<li>Typical (hobby) servos have 3 wires with a female header at the end. Insert a jumper wire into each of the header pins.</li>
<li>Hook the RED wire up to +5V on the Arduino and hook up the BLACK wire to GROUND on the Arduino.</li>
<li>The YELLOW wire is for data. Hook it up to a Digital Pin (8) on the Arduino.</li>
<div class="yoxview"><div id="attachment_218" class="wp-caption aligncenter" style="width: 310px"><a href="http://danplows.com/blog/wp-content/uploads/2011/07/servo.jpg"><img src="http://danplows.com/blog/wp-content/uploads/2011/07/servo-300x187.jpg" alt="servo" title="servo" width="300" height="187" class="size-medium wp-image-218" /></a><p class="wp-caption-text">A servo wired to an Arduino</p></div></div>
<li>The servo library included in the Arduino IDE makes controlling servos very simple. Just include the servo library header file, declare a Servo object, attach your servo to a pin in the setup, then call the &#8216;write&#8217; method on your servo object in order to change the servo&#8217;s position (rotation) <em>Note: Remember to delay for at least 15ms after calling the &#8216;write&#8217; method to give the servo time to move</em>.</li>
<li>Connect the Arduino to your computer with a USB cable (A to B) and upload the code below. Or, just simply go to File > Examples > Servo > Sweep in the Arduino IDE (same as below).</li>
</ol>
<p><strong>Code</strong></p>
<p><code>#include &lt;Servo.h&gt; </p>
<p>Servo myservo;  // create servo object to control a servo<br />
                // a maximum of eight servo objects can be created </p>
<p>int pos = 0;    // variable to store the servo position </p>
<p>void setup()<br />
{<br />
  myservo.attach(8);  // attaches the servo on pin 9 to the servo object<br />
} </p>
<p>void loop()<br />
{<br />
  for(pos = 0; pos &lt; 180; pos += 1)  // goes from 0 degrees to 180 degrees<br />
  {                                  // in steps of 1 degree<br />
    myservo.write(pos);              // tell servo to go to position in variable 'pos'<br />
    delay(15);                       // waits 15ms for the servo to reach the position<br />
  }<br />
  for(pos = 180; pos&gt;=1; pos-=1)     // goes from 180 degrees to 0 degrees<br />
  {<br />
    myservo.write(pos);              // tell servo to go to position in variable 'pos'<br />
    delay(15);                       // waits 15ms for the servo to reach the position<br />
  }<br />
} </code></p>
<p><strong>A Step Further</strong></p>
<p>If you&#8217;ve read my previous post, <a href="http://danplows.com/blog/hack-a-nintendo-nes-controller/">Hack a Nintendo (NES) Controller</a>, you can now combine your knowledge to control servos with a NES controller. See the video below from <a href="http://www.youtube.com/user/itstheplowsta" target="_blank">my YouTube channel</a>.</p>
<p>
<iframe width="480" height="390" src="http://www.youtube.com/embed/N0Lu1C_j6dA" frameborder="0" allowfullscreen></iframe>
</p>
<p><strong>Code From Video</strong>
<p><code>#include &lt;NESpad.h&gt;<br />
#include &lt;Servo.h&gt;</p>
<p>NESpad nintendo = NESpad(2,3,4);<br />
Servo myServo;<br />
Servo otherServo;</p>
<p>byte state = 0;<br />
int pos = 1; // myServo<br />
int val = 1; // otherServo</p>
<p>void setup() {<br />
  myServo.attach(9);<br />
  otherServo.attach(10);<br />
  Serial.begin(9600);<br />
}</p>
<p>void loop() {</p>
<p>  delay(5);</p>
<p>  state = nintendo.buttons();</p>
<p>  // Left<br />
  if (state &amp; NES_LEFT){<br />
      if(pos &gt; 1){<br />
        pos = pos - 10;<br />
        myServo.write(pos);<br />
        delay(15);<br />
        Serial.println(pos);<br />
      }<br />
  }</p>
<p>  //Right<br />
  if (state &amp; NES_RIGHT){<br />
      if(pos &lt; 179){<br />
        pos = pos + 10;<br />
        myServo.write(pos);<br />
        delay(15);<br />
        Serial.println(pos);<br />
      }<br />
  }</p>
<p>  //B<br />
  if (state &amp; NES_B){<br />
    if(val &gt; 1){<br />
      val = val - 10;<br />
      otherServo.write(val);<br />
      delay(15);<br />
      Serial.println(val);<br />
    }  </p>
<p>  }</p>
<p>  // A<br />
  if (state &amp; NES_A){<br />
    if(val &lt; 179){<br />
      val = val + 10;<br />
      otherServo.write(val);<br />
      delay(15);<br />
      Serial.println(val);<br />
    }<br />
  }</p>
<p>}</code></p>
]]></content:encoded>
			<wfw:commentRss>http://danplows.com/blog/how-to-hook-up-servos/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Hack a Nintendo (NES) Controller</title>
		<link>http://danplows.com/blog/hack-a-nintendo-nes-controller/</link>
		<comments>http://danplows.com/blog/hack-a-nintendo-nes-controller/#comments</comments>
		<pubDate>Wed, 06 Jul 2011 02:57:38 +0000</pubDate>
		<dc:creator>Dan Plows</dc:creator>
				<category><![CDATA[Nintendo Controller]]></category>

		<guid isPermaLink="false">http://danplows.com/blog/?p=180</guid>
		<description><![CDATA[The Nintendo (NES) Controller is a familiar classic. It&#8217;s simplicity makes it easy to hack and re-purpose for your own needs. This post details how to easily read the button-state values into an Arduino. Parts Nintendo (NES) Controller 5 Jumper Wires (red, black, white, orange, &#38; yellow) Arduino USB cable (A to B) Steps Before [...]]]></description>
			<content:encoded><![CDATA[<p>The Nintendo (NES) Controller is a familiar classic. It&#8217;s simplicity makes it easy to hack and re-purpose for your own needs. This post details how to easily read the button-state values into an Arduino.<br />
<span id="more-180"></span></p>
<p><strong>Parts</strong></p>
<ul>
<li>Nintendo (NES) Controller</li>
<li>5 Jumper Wires (red, black, white, orange, &amp; yellow)</li>
<li>Arduino</li>
<li>USB cable (A to B)</li>
</ul>
<p><strong>Steps</strong></p>
<ol>
<li>Before you begin, see the diagram showing the Nintendo pin-out below. (<em><a href="http://pinouts.ru/Game/snescontroller_pinout.shtml" target="_blank">Pinouts.ru</a> is also a great source</em>)</li>
<div class="yoxview"><div id="attachment_182" class="wp-caption aligncenter" style="width: 310px"><a href="http://danplows.com/blog/wp-content/uploads/2011/07/nes_pinout.jpg"><img class="size-medium wp-image-182" title="NES Pin-out" src="http://danplows.com/blog/wp-content/uploads/2011/07/nes_pinout-300x178.jpg" alt="NES Pinout" width="300" height="178" /></a><p class="wp-caption-text">Pin-out for an NES Controller</p></div></div>
<li>Now that you understand the pins on the Nintendo controller, hook up your jumper wires by using arrow&#8217;s colors from the photo above. (<em>Note: The pins are fairly deep, be sure that your wires are deep enough and snug to insure a strong connection</em>)</li>
<li>As for the other ends of the wires, place the RED wire from +5V on the Nintendo controller to 5V on the Arduino. Place the BLACK wire from GROUND on the NES controller to GROUND on the Arduino. Pretty straight forward.</li>
<li>Place the ORANGE wire from STROBE on the NES controller to Digital Pin 2 on the Arduino.</li>
<li>Place the WHITE wire from CLOCK on the NES controller to Digital Pin 3 on the Arduino.</li>
<li>Place the YELLOW wire from DATA on the NES controller to Digital Pin 4 on the Arduino.</li>
<div class="yoxview"><div id="attachment_194" class="wp-caption aligncenter" style="width: 310px"><a href="http://danplows.com/blog/wp-content/uploads/2011/07/nes_wired.jpg"><img src="http://danplows.com/blog/wp-content/uploads/2011/07/nes_wired-300x168.jpg" alt="NES Wired" title="nes_wired" width="300" height="168" class="size-medium wp-image-194" /></a><p class="wp-caption-text">NES controller wired to Arduino</p></div></div>
<li>Download the <a href='http://danplows.com/blog/wp-content/uploads/2011/07/NESpad_1.3.zip'>NESpad_1.3</a> library by <a href="http://code.google.com/p/nespad/" target="_blank">rahjix</a>. Unzip the folder into your &#8220;libraries&#8221; folder within your Arduino projects folder (ie. &#8230;/Documents/Arduino/libraries). If this is your first library, you may need to create a &#8220;libraries&#8221; folder, as I did. This handy library will do all the hard work dealing with the pulses, enabling you to simply check for Boolean values such as &#8220;NES_A&#8221; rather than dealing with binary. Besides, why reinvent the wheel?</li>
<li>To be sure you installed the library correctly, restart your Arduino software and go to &#8220;Sketch > Import Library&#8221; and make sure NESpad is on the list.</li>
<div class="yoxview"><div id="attachment_196" class="wp-caption aligncenter" style="width: 310px"><a href="http://danplows.com/blog/wp-content/uploads/2011/07/nes_import.jpg"><img src="http://danplows.com/blog/wp-content/uploads/2011/07/nes_import-300x201.jpg" alt="NES Import Library" title="nes_import" width="300" height="201" class="size-medium wp-image-196" /></a><p class="wp-caption-text">Import the NES Library after installation</p></div></div>
<li>Copy &amp; paste the following code into the Arduino software:</li>
<p><code>#include &lt;NESpad.h&gt;</p>
<p>// put your own strobe/clock/data pin numbers here -- see the pinout in readme.txt<br />
NESpad nintendo = NESpad(2,3,4);</p>
<p>byte state = 0;</p>
<p>/* A button gets marked as true as soon as it is pressed. That way<br />
 we know to not "press" it again */<br />
boolean a = false; //A      Button<br />
boolean b = false; //B      Button<br />
boolean u = false; //Up     Button<br />
boolean d = false; //Down   Button<br />
boolean l = false; //Left   Button<br />
boolean r = false; //Right  Button<br />
boolean s = false; //Start  Button<br />
boolean e = false; //Select Button</p>
<p>/* We will pass on this array whenever a key is released. Once the<br />
 key is released we will turn that 0 into a 1. That way in our java program<br />
 we will know exactly which keys we just released. The keys will always go<br />
 in this order:        a,b,u,d, l,r,s,e */<br />
int keysReleased[] = {<br />
  0,0,0,0, 0,0,0,0};</p>
<p>/* We will set this to true only when a button has been released. This will<br />
 stop us from sending the keysReleased array every loop to our java robot */<br />
boolean isReleased = false;</p>
<p>void setup() {<br />
  Serial.begin(9600);<br />
}</p>
<p>void loop() {</p>
<p>  delay(5);</p>
<p>  state = nintendo.buttons();</p>
<p>  // A<br />
  if (state &amp; NES_A){<br />
    if(!a){<br />
      a = true; //Make sure the button is only pressed once<br />
      Serial.println('A'); //Print the button to be picked up by our robot<br />
    }<br />
  }<br />
  //Key might have been released so we check and if so change the<br />
  //value in our released array<br />
  else if (a == true){<br />
    a = false;<br />
    keysReleased[0] = 1;<br />
    isReleased = true;<br />
  }</p>
<p>  // B<br />
  if (state &amp; NES_B){<br />
    if(!b){<br />
      b = true; //Make sure the button is only pressed once<br />
      Serial.println('B'); //Print the button to be picked up by our robot<br />
    }<br />
  }<br />
  //Key might have been released so we check and if so change the<br />
  //value in our released array<br />
  else if (b == true){<br />
    b = false;<br />
    keysReleased[1] = 1;<br />
    isReleased = true;<br />
  }</p>
<p>  // Up<br />
  if (state &amp; NES_UP){<br />
    if(!u){<br />
      u = true; //Make sure the button is only pressed once<br />
      Serial.println('U'); //Print the button to be picked up by our robot<br />
    }<br />
  }<br />
  //Key might have been released so we check and if so change the<br />
  //value in our released array<br />
  else if (u == true){<br />
    u = false;<br />
    keysReleased[2] = 1;<br />
    isReleased = true;<br />
  }</p>
<p>  // Down<br />
  if (state &amp; NES_DOWN){<br />
    if(!d){<br />
      d = true; //Make sure the button is only pressed once<br />
      Serial.println('D'); //Print the button to be picked up by our robot<br />
    }<br />
  }<br />
  //Key might have been released so we check and if so change the<br />
  //value in our released array<br />
  else if (d == true){<br />
    d = false;<br />
    keysReleased[3] = 1;<br />
    isReleased = true;<br />
  }</p>
<p>  // Left<br />
  if (state &amp; NES_LEFT){<br />
    if(!l){<br />
      l = true; //Make sure the button is only pressed once<br />
      Serial.println('L'); //Print the button to be picked up by our robot<br />
    }<br />
  }<br />
  //Key might have been released so we check and if so change the<br />
  //value in our released array<br />
  else if (l == true){<br />
    l = false;<br />
    keysReleased[4] = 1;<br />
    isReleased = true;<br />
  }</p>
<p>  //Right<br />
  if (state &amp; NES_RIGHT){<br />
    if(!r){<br />
      r = true; //Make sure the button is only pressed once<br />
      Serial.println('R'); //Print the button to be picked up by our robot<br />
    }<br />
  }<br />
  //Key might have been released so we check and if so change the<br />
  //value in our released array<br />
  else if (r == true){<br />
    r = false;<br />
    keysReleased[5] = 1;<br />
    isReleased = true;<br />
  }</p>
<p>  //Start<br />
  if (state &amp; NES_START){<br />
    if(!s){<br />
      s = true; //Make sure the button is only pressed once<br />
      Serial.println('S'); //Print the button to be picked up by our robot<br />
    }<br />
  }<br />
  //Key might have been released so we check and if so change the<br />
  //value in our released array<br />
  else if (s == true){<br />
    s = false;<br />
    keysReleased[6] = 1;<br />
    isReleased = true;<br />
  }</p>
<p>  //Select<br />
  if (state &amp; NES_SELECT){<br />
    if(!e){<br />
      e = true; //Make sure the button is only pressed once<br />
      Serial.println('E'); //Print the button to be picked up by our robot<br />
    }<br />
  }<br />
  //Key might have been released so we check and if so change the<br />
  //value in our released array<br />
  else if (e == true){<br />
    e = false;<br />
    keysReleased[7] = 1;<br />
    isReleased = true;<br />
  }</p>
<p>  /* If a key has been released then our java robot needs to know about it. So what we<br />
   are going to do is to iterate over our array if a key has been released and print out the<br />
   position in the array of that key. So for example if "Up" has been released we will<br />
   see that our array looks like this [0,0,1,0, 0,0,0,0]. So then we will print 2 to the java robot<br />
   so it knows that "Up" has been released. Likewise we would print 7 for the start button on release. */<br />
  if(isReleased){<br />
    isReleased = false; //Reset the boolean<br />
    for(int i=0; i &lt; 8; i++){<br />
      if(keysReleased[i] == 1){<br />
        keysReleased[i] = 0; //Reset the button listener<br />
        Serial.println(i);<br />
      }<br />
    }<br />
  }<br />
}</code></p>
<li>Connect the Arduino to your computer via the USB cable (A to B) and upload the code to your board.</li>
<li>Once uploaded, open up the Serial Monitor within the Arduino Software. Notice when a button on the NES controller is PRESSED, the corresponding letter is printed to the monitor. (<em>Note: If you&#8217;re getting very sporadic results, such as a bunch of letters and numbers rapdily filling the Serial Monitor, you most likely have a lose connection between your wire(s) and the NES controller&#8217;s pins. Be sure they are tight enough.</em>)</li>
</ol>
<p><strong>Explanation</strong></p>
<p>When a button is RELEASED, a unique number is displayed for each button. This number corresponds to the buttons position in the array that holds the binary number received from the NES controller. In other words, the Arduino is receiving 8-bit binary numbers from the the NES controller, ie. 10000100. The order is as follows: A, B, Up, Down, Left, Right, Start, Select. 1 stands for an &#8220;on&#8221; bit (button pressed), and 0 stands for an &#8220;off&#8221; bit (button NOT pressed); therefore, in the example 10000100, the &#8216;A&#8217; and &#8216;Right&#8217; buttons are pressed. Now the numbers that display after a button is released should make sense. When the &#8216;A&#8217; button is PRESSED, &#8216;A&#8217; is printed to the Serial Monitor. Once &#8216;A&#8217; is RELEASED, &#8217;0&#8242; is printed to the Serial Monitor (since arrays start at 0 and &#8216;A&#8217; is the first bit). Feel free to modify the code to something possibly more useful, such as an uppercase letter (A) when pressed and a lowercase letter (a) when released for example.</p>
<p><strong>Video</strong></p>
<p><iframe width="480" height="390" src="http://www.youtube.com/embed/KpyeQF71Mcc" frameborder="0" allowfullscreen></iframe></p>
<p><strong>A Step Further</strong></p>
<p>More posts coming soon detailing possible uses for this knowledge. Until then, you can <a href="http://www.youtube.com/user/itstheplowsta" target="_blank">view my NES/Arduino projects on my YouTube channel</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://danplows.com/blog/hack-a-nintendo-nes-controller/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to Hook Up &gt; Accelerometers (Memsic 2125)</title>
		<link>http://danplows.com/blog/how-to-hook-up-accelerometers-memsic-2125/</link>
		<comments>http://danplows.com/blog/how-to-hook-up-accelerometers-memsic-2125/#comments</comments>
		<pubDate>Wed, 08 Jun 2011 00:31:50 +0000</pubDate>
		<dc:creator>Dan Plows</dc:creator>
				<category><![CDATA[How To Hook Up Parts]]></category>

		<guid isPermaLink="false">http://danplows.com/blog/?p=161</guid>
		<description><![CDATA[Every one knows accelerometers from Wii controllers and smart phones. Being fairly inexpensive, they&#8217;re a prime candidate for including in a DIY project. I&#8217;ll detail how to hook up a Memsic 2125 (most common) dual-axis accelerometer and measure its tilt in this post. Parts Memsic 2125 dual-axis accelerometer ($30) 4 Jumper Wires (yellow, orange, red [...]]]></description>
			<content:encoded><![CDATA[<p>Every one knows accelerometers from Wii controllers and smart phones. Being fairly inexpensive, they&#8217;re a prime candidate for including in a DIY project. I&#8217;ll detail how to hook up a <a href="http://www.parallax.com/Store/Sensors/AccelerationTilt/tabid/172/ProductID/93/CategoryID/47/List/0/Level/a/Default.aspx?SortField=ProductName,ProductName" target="_blank">Memsic 2125</a> (most common) dual-axis accelerometer and measure its tilt in this post.</p>
<p><span id="more-161"></span></p>
<p><strong>Parts</strong></p>
<ul>
<li>Memsic 2125 dual-axis accelerometer ($30)</li>
<li>4 Jumper Wires (yellow, orange, red &amp; black)</li>
<li>Breadboard</li>
<li>Arduino</li>
<li>USB cable (A to B)</li>
</ul>
<p><strong>Steps</strong></p>
<ol>
<li>The Memsic 2125 accelerometer has 6 leads. Place it into your breadboard, over the gap to prevent a short. <em>I will referring to the leads assuming that the accelerometer is rotated so that you can read &#8220;Mx2125&#8243; normally on the mini <a href="http://en.wikipedia.org/wiki/Printed_circuit_board" target="_blank">pcb</a>. Make sure you don&#8217;t have it upside-down. <a onclick="if(!confirm('Open this file with Google Docs?'))return true;window.location='http://docs.google.com/gview?url='+this.href;return false;" href="http://www.radioshack.com/graphics/uc/rsk/Support/ProductManuals/2760029_PM_EN.pdf" target="_blank">You can find specs here.</a></em></li>
<li>The UPPER-RIGHT lead is positive and should be wired (red) to 5V on the Arduino.</li>
<li>The LOWER-LEFT lead is negative and should be wired (black) to Ground on the Arduino.</li>
<li>The MIDDLE pin on the RIGHT will provide the X values and should be wired (yellow) to a Digital Pin (8) on the Arduino.</li>
<li>The MIDDLE pin on the LEFT will provide the Y values and should be wired (orange) to a Digital Pin (9) on the Arduino.</li>
<div class="yoxview"><div id="attachment_178" class="wp-caption aligncenter" style="width: 310px"><a href="http://danplows.com/blog/wp-content/uploads/2011/06/accelerometer.jpg"><img class="size-medium wp-image-178" title="accelerometer" src="http://danplows.com/blog/wp-content/uploads/2011/06/accelerometer-300x157.jpg" alt="accelerometer" width="300" height="157" /></a><p class="wp-caption-text">Memsic 2125 Dual Axis Accelerometer wired up.</p></div></div>
<li>Connect the Arduino to your computer with the USB cable (A to B).</li>
<li>The code below simply reads in the X and Y of the accelerometer and outputs those values to the Serial Monitor within the Arduino software. Once uploaded to your board, open the Serial Monitor. You should be able to tilt the accelerometer and see the respective X and Y values change.</li>
</ol>
<p><strong>Code</strong></p>
<p><code>const int xPin = 8; // X input from accelerometer<br />
const int yPin = 9; // Y input accelerometer</code></p>
<p><code>int xPulse, yPulse; // read from accelerometer<br />
int xVal, yVal; // converted value</code></p>
<p><code>void setup() {<br />
Serial.begin(9600);<br />
pinMode(xPin, INPUT);<br />
pinMode(yPin, INPUT);<br />
}</p>
<p>void loop() {</p>
<p>// read x &amp;amp; y values<br />
xPulse = pulseIn(xPin,HIGH);<br />
yPulse = pulseIn(yPin,HIGH);</p>
<p>xVal = ((xPulse / 10) - 500) * 8;<br />
yVal = ((yPulse / 10) - 500) * 8;</p>
<p>Serial.print(xVal);<br />
Serial.print("\t");<br />
Serial.print(yVal);<br />
Serial.println()<br />
</code></p>
<p>&nbsp;</p>
<p><code> delay(100);<br />
}</code></p>
<p><strong>Conclusion</strong></p>
<p>Now that the values are being read in properly, it becomes easy to integrate for your own purpose by using basic if-else statements and comparison operators.</p>
]]></content:encoded>
			<wfw:commentRss>http://danplows.com/blog/how-to-hook-up-accelerometers-memsic-2125/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Hook Up &gt; Photo Resistors</title>
		<link>http://danplows.com/blog/how-to-hook-up-photo-resistors/</link>
		<comments>http://danplows.com/blog/how-to-hook-up-photo-resistors/#comments</comments>
		<pubDate>Wed, 25 May 2011 01:11:05 +0000</pubDate>
		<dc:creator>Dan Plows</dc:creator>
				<category><![CDATA[How To Hook Up Parts]]></category>

		<guid isPermaLink="false">http://danplows.com/blog/?p=140</guid>
		<description><![CDATA[Photo resistors measure light. The amount of light varies the resistance and determines a value between 0 and 1023. This post details how to hook one up to an Arduino. Parts Photo Resistor Resistor (10k) 3 Jumper wires (yellow, red &#038; black) Breadboard Arduino USB cable (A to B) Steps A typical photo resistor has [...]]]></description>
			<content:encoded><![CDATA[<p>Photo resistors measure light. The amount of light varies the resistance and determines a value between 0 and 1023. This post details how to hook one up to an Arduino.<br />
<span id="more-140"></span><br />
<strong>Parts</strong></p>
<ul>
<li>Photo Resistor</li>
<li>Resistor (10k)</li>
<li>3 Jumper wires (yellow, red &#038; black)</li>
<li>Breadboard</li>
<li>Arduino</li>
<li>USB cable (A to B)</li>
</ul>
<p><strong>Steps</strong></p>
<ol>
<li>A typical photo resistor has 2 leads. Choose one lead to be positive and one lead to be negative. Place it on the breadboard.</li>
<li>Place a (yellow) wire in the same row as the positive lead and wire it to an Analog pin (0) on the Arduino. Leave room for 1 lead of a resistor.</li>
<li>Place a one lead of a (10k) resistor in between the (yellow) wire to the analog pin and the positive lead of the photo resistor.</li>
<li>Place the other lead of the (10k) resistor a few rows up/down and wire (red) it to 5V on the Arduino.</li>
<li>Place a (black) wire in the same row as the negative lead of the photo resistor and wire it to Ground on the Arduino.</li>
<div class="yoxview"><div id="attachment_142" class="wp-caption aligncenter" style="width: 310px"><a href="http://danplows.com/blog/wp-content/uploads/2011/05/photoresistor.jpg"><img src="http://danplows.com/blog/wp-content/uploads/2011/05/photoresistor-300x211.jpg" alt="photo resistor" title="photoresistor" width="300" height="211" class="size-medium wp-image-142" /></a><p class="wp-caption-text">A photo resistor wired up.</p></div></div>
<li>Connect the Arduino to your computer with the USB cable (A to B).</li>
<li>The code below simply reads in the value of the photo resistor and outputs that value to the Serial Monitor within the Arduino software. <em>Note: With the lights on, mine reads a value around 250. With the lights off, mine reads a value around 900.</em></li>
</ol>
<p><strong>Code</strong></p>
<p>
<code>int lightPin = 0;</p>
<p>void setup()<br />
{<br />
  Serial.begin(9600);<br />
}</p>
<p>void loop()<br />
{<br />
  Serial.println(analogRead(lightPin));<br />
  delay(100);<br />
}</code></p>
]]></content:encoded>
			<wfw:commentRss>http://danplows.com/blog/how-to-hook-up-photo-resistors/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Hook Up &gt; Buzzers</title>
		<link>http://danplows.com/blog/how-to-hook-up-buzzers/</link>
		<comments>http://danplows.com/blog/how-to-hook-up-buzzers/#comments</comments>
		<pubDate>Tue, 24 May 2011 20:09:51 +0000</pubDate>
		<dc:creator>Dan Plows</dc:creator>
				<category><![CDATA[How To Hook Up Parts]]></category>

		<guid isPermaLink="false">http://danplows.com/blog/?p=132</guid>
		<description><![CDATA[Buzzers allow for simple audio output. Running them at different speeds allow for a variety of tones. This post details how to hook one up to an Arduino. Parts Buzzer 2 Jumper Wires (yellow &#38; black) Breadboard Arduino USB cable (A to B) Steps A typical (piezo) buzzer has 2 leads. To no surprise, 1 [...]]]></description>
			<content:encoded><![CDATA[<p>Buzzers allow for simple audio output. Running them at different speeds allow for a variety of tones. This post details how to hook one up to an Arduino.</p>
<p><span id="more-132"></span></p>
<p><strong>Parts</strong></p>
<ul>
<li>Buzzer</li>
<li>2 Jumper Wires (yellow &amp; black)</li>
<li>Breadboard</li>
<li>Arduino</li>
<li>USB cable (A to B)</li>
</ul>
<p><strong>Steps</strong></p>
<ol>
<li>A typical (piezo) buzzer has 2 leads. To no surprise, 1 is positive and 1 is negative. These should be labeled on and/or under the buzzer.</li>
<li>Place it on you breadboard and place a (yellow) wire from the positive lead to a digital pin (4).</li>
<li>Place a (black) wire from the negative lead to a ground pin.</li>
<div class="yoxview"><div id="attachment_136" class="wp-caption aligncenter" style="width: 310px"><a href="http://danplows.com/blog/wp-content/uploads/2011/05/buzzer.jpg"><img src="http://danplows.com/blog/wp-content/uploads/2011/05/buzzer-300x261.jpg" alt="buzzer" title="buzzer" width="300" height="261" class="size-medium wp-image-136" /></a><p class="wp-caption-text">A buzzer wired up.</p></div></div>
<li>Connect the Arduino to your computer using the USB cable (A to B).</li>
<li>The code below will repeatedly turn the buzzer on HIGH and LOW (on and off) with 2000 microseconds intervals, which is 2 milliseconds or 0.002 seconds. Upload it to your board and enjoy the constant low tone.</li>
</ol>
<p><strong>Code</strong></p>
<p>
<code>int buzzPin = 2;</code></p>
<p><code>void setup()<br />
{<br />
pinMode(buzzPin, OUTPUT);<br />
}<br />
</code></p>
<p><code>void loop()<br />
{<br />
digitalWrite(buzzPin, HIGH);<br />
delayMicroseconds(2000);<br />
digitalWrite(buzzPin, LOW);<br />
delayMicroseconds(2000);<br />
}</code>
</p>
<p><strong>Explanation</strong></p>
<p>Turning the buzzer on and off rapidly causes the buzzer to vibrate and make sound. While the above code is looping infinitely, using a <a href="http://code.wikia.com/wiki/For_loop" target="_blank">for loop</a> will give you more control over the duration. <em>You&#8217;ll want to loop it at least a couple dozen times for a brief (1-2 second) sound.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://danplows.com/blog/how-to-hook-up-buzzers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Hook Up &gt; Soft Pots</title>
		<link>http://danplows.com/blog/how-to-hook-up-a-soft-pot/</link>
		<comments>http://danplows.com/blog/how-to-hook-up-a-soft-pot/#comments</comments>
		<pubDate>Tue, 17 May 2011 23:23:45 +0000</pubDate>
		<dc:creator>Dan Plows</dc:creator>
				<category><![CDATA[How To Hook Up Parts]]></category>

		<guid isPermaLink="false">http://danplows.com/blog/?p=89</guid>
		<description><![CDATA[A soft pot works just like a regular potentiometer; however, instead of turning a dial, you slide (your finger) up and down the strip to change the values. This post details how to hook up to an Arduino. Parts Soft Pot 3 Jumper wires (yellow, red &#038; black) Breadboard Arduino USB cable (A to B) [...]]]></description>
			<content:encoded><![CDATA[<p>A soft pot works just like a regular potentiometer; however, instead of turning a dial, you slide (your finger) up and down the strip to change the values. This post details how to hook up to an Arduino.<br />
<span id="more-89"></span><br />
<strong>Parts</strong></p>
<ul>
<li>Soft Pot</li>
<li>3 Jumper wires (yellow, red &#038; black)</li>
<li>Breadboard</li>
<li>Arduino</li>
<li>USB cable (A to B)</li>
</ul>
<p><em>If you&#8217;ve already read my post on <a href="how-to-hook-up-a-potentiometer/">How to Hook Up A Potentiometer</a>, then all you need to know is which lead is which (You can even use the same code). See step 1 below.</em></p>
<p><strong>Steps</strong></p>
<ol>
<li>A typical soft pot has 3 leads. Like a regular potentiometer, the outer leads are for power and the middle lead is for the value. However, unlike a regular potentiometer, the outer leads are predetermined as positive and negative. On my soft pot (by <a href="http://www.spectrasymbol.com/" target="_blank">Spectra Symbol</a>), the film is clear and you can see the traces from the leads. The one that traces all the way to the opposite end of the leads is positive. Obviously, the other one is negative.</li>
<li>With each lead in separate rows on the breadboard, place (red) wire from the positive lead of the soft pot to a 5V pin on the Arduino.</li>
<li>Place (black) wire from the negative lead of the soft pot to a Ground pin on the Arduino.</li>
<li>Place (yellow) wire from the middle lead of the soft pot to an Analog pin (0) on the Arduino.</li>
<div class="yoxview"><div id="attachment_103" class="wp-caption aligncenter" style="width: 310px"><a href="http://danplows.com/blog/wp-content/uploads/2011/05/softpot.jpg"><img src="http://danplows.com/blog/wp-content/uploads/2011/05/softpot-300x122.jpg" alt="Soft Pot" title="Soft Pot" width="300" height="122" class="size-medium wp-image-103" /></a><p class="wp-caption-text">A soft pot wired up.</p></div></div>
<li>Connect the Arduino to your computer using the USB cable (A to B).</li>
<li>The code below reads in the value of the soft pot&#8217;s pin and prints it to the Serial Monitor (within the Arduino software). Upload it to your board. Lay the soft pot on a firm, flat surface and slowly slide your finger up and down while watching the values change in the Serial Monitor.</li>
</ol>
<p><strong>Code</strong></p>
<p>
<code>int softPot = 0;</p>
<p>void setup()<br />
{<br />
  Serial.begin(9600);<br />
  pinMode(softPot, INPUT);<br />
}</p>
<p>void loop()<br />
{<br />
  Serial.println(analogRead(softPot));<br />
  delay(100);<br />
}</code>
</p>
<p><strong>Explanation</strong></p>
<p>The soft pot works by changing the resistance depending on where pressure is positioned along the strip. For more information: <a href="http://www.spectrasymbol.com/how-it-works-softpot" target="_blank">http://www.spectrasymbol.com/how-it-works-softpot</a></p>
]]></content:encoded>
			<wfw:commentRss>http://danplows.com/blog/how-to-hook-up-a-soft-pot/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

