
<?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>unthink media</title>
	<atom:link href="http://blog.unthinkmedia.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.unthinkmedia.com</link>
	<description>creativity + technology</description>
	<lastBuildDate>Thu, 02 Sep 2010 03:54:20 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Using getDefinitionByName() with External Library SWCs</title>
		<link>http://blog.unthinkmedia.com/2010/09/01/using-getdefinitionbyname-with-external-library-swcs/</link>
		<comments>http://blog.unthinkmedia.com/2010/09/01/using-getdefinitionbyname-with-external-library-swcs/#comments</comments>
		<pubDate>Thu, 02 Sep 2010 03:39:57 +0000</pubDate>
		<dc:creator>Alex Britez</dc:creator>
				<category><![CDATA[Flex/Flash]]></category>
		<category><![CDATA[programing]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://blog.unthinkmedia.com/?p=745</guid>
		<description><![CDATA[In a recent project I was forced to dynamically generating UI Elements in flex from Strings.  This is typically done using getDefinitionByName() as shown bellow.  Although this works, in my app I never really know what the string is, nor do I know what the Class is named or where it is located. [...]]]></description>
			<content:encoded><![CDATA[<p>In a recent project I was forced to dynamically generating UI Elements in flex from Strings.  This is typically done using getDefinitionByName() as shown bellow.  Although this works, in my app I never really know what the string is, nor do I know what the Class is named or where it is located.  This becomes an issue since you must make reference to the Class somewhere in your code before it is available to the Flex framework.</p>
<p>This example shows the typical use of getDefinitionByName() with out any external SWC.  Notice the imports and class references on the top of the Script block.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Application</span> <span style="color: #000066;">xmlns:mx</span>=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> <span style="color: #000066;">layout</span>=<span style="color: #ff0000;">&quot;vertical&quot;</span> <span style="color: #000066;">xmlns:controls</span>=<span style="color: #ff0000;">&quot;com.controls.*&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #339933;">&lt;![CDATA[</span>
<span style="color: #339933;">			import flash.utils.getDefinitionByName;</span>
&nbsp;
<span style="color: #339933;">                       //You must import the classes and instantiate them</span>
<span style="color: #339933;">			import com.controls.TestControlA;TestControlA;</span>
<span style="color: #339933;">			import com.controls.TestControlB;TestControlB;</span>
&nbsp;
<span style="color: #339933;">			private function loadTestClass(name:String):void</span>
<span style="color: #339933;">			{</span>
<span style="color: #339933;">			var ClassReference:Class = getDefinitionByName(name) as Class;</span>
<span style="color: #339933;">           		var s:DisplayObject = (new ClassReference() as DisplayObject)</span>
<span style="color: #339933;">           		testContainer.addChild(s);</span>
<span style="color: #339933;">			}</span>
<span style="color: #339933;">		]]&gt;</span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:Script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:VBox</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;testContainer&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:HBox</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;buttonBar&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #808080; font-style: italic;">&lt;!--You have to place the entire package location in the string--&gt;</span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Button</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;Test A&quot;</span> <span style="color: #000066;">click</span>=<span style="color: #ff0000;">&quot;loadTestClass('com.controls.TestControlA')&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Button</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;Test B&quot;</span> <span style="color: #000066;">click</span>=<span style="color: #ff0000;">&quot;loadTestClass('com.controls.TestControlB')&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:HBox<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:Application<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>This won&#8217;t work since I need to make a reference to Classes that I won&#8217;t know the names of till run-time. My first step was to move a control into an external SWC, however I still am forced to make reference to the class so it becomes available, or I will get an error. This is a no go.</p>
<p><span id="more-745"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Application</span> <span style="color: #000066;">xmlns:mx</span>=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> <span style="color: #000066;">layout</span>=<span style="color: #ff0000;">&quot;vertical&quot;</span> <span style="color: #000066;">xmlns:controls</span>=<span style="color: #ff0000;">&quot;com.controls.*&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #339933;">&lt;![CDATA[</span>
<span style="color: #339933;">			import flash.utils.getDefinitionByName;</span>
&nbsp;
<span style="color: #339933;">//You must import the classes and instantiate them</span>
<span style="color: #339933;">			import com.controls.TestControlA;TestControlA;</span>
<span style="color: #339933;">			import com.controls.TestControlB;TestControlB;</span>
<span style="color: #339933;">                        import com.controls.TestControlB;TestControlC; //Located in an External SWC</span>
&nbsp;
<span style="color: #339933;">			private function loadTestClass(name:String):void</span>
<span style="color: #339933;">			{</span>
<span style="color: #339933;">			var ClassReference:Class = getDefinitionByName(name) as Class;</span>
<span style="color: #339933;">           		var s:DisplayObject = (new ClassReference() as DisplayObject)</span>
<span style="color: #339933;">           		testContainer.addChild(s);</span>
<span style="color: #339933;">			}</span>
<span style="color: #339933;">		]]&gt;</span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:Script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:VBox</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;testContainer&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:HBox</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;buttonBar&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span></span>
                <span style="color: #808080; font-style: italic;">&lt;!--You have to place the entire package location in the string--&gt;</span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Button</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;Test A&quot;</span> <span style="color: #000066;">click</span>=<span style="color: #ff0000;">&quot;loadTestClass('com.controls.TestControlA')&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Button</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;Test B&quot;</span> <span style="color: #000066;">click</span>=<span style="color: #ff0000;">&quot;loadTestClass('com.controls.TestControlB')&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Button</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;Test C&quot;</span> <span style="color: #000066;">click</span>=<span style="color: #ff0000;">&quot;loadTestClass('com.controls.TestControlC')&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:HBox<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:Application<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>The solution was actually pretty simple. If Flex is asking for a reference then why not just give it one.  In the Library Project i create an additional Module file which i then loaded into my Shell application. Once the module is loaded then getDefinitionByName() works!</p>
<p>Shell Flex Application</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Application</span> <span style="color: #000066;">xmlns:mx</span>=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> <span style="color: #000066;">layout</span>=<span style="color: #ff0000;">&quot;vertical&quot;</span> <span style="color: #000066;">xmlns:controls</span>=<span style="color: #ff0000;">&quot;com.controls.*&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #339933;">&lt;![CDATA[</span>
<span style="color: #339933;">			import flash.utils.getDefinitionByName;</span>
<span style="color: #339933;">			import com.controls.TestControlA;TestControlA;</span>
<span style="color: #339933;">			import com.controls.TestControlB;TestControlB;</span>
<span style="color: #339933;">			import com.controls.TestControlC;TestControlC;//Located in an External SWC</span>
<span style="color: #339933;">                       //NO REFEREANCE TO TestControlD</span>
&nbsp;
<span style="color: #339933;">			private function loadTestClass(name:String):void</span>
<span style="color: #339933;">			{</span>
<span style="color: #339933;">				var ClassReference:Class = getDefinitionByName(name) as Class;</span>
<span style="color: #339933;">           		var s:DisplayObject = (new ClassReference() as DisplayObject)</span>
<span style="color: #339933;">           		testContainer.addChild(s);</span>
<span style="color: #339933;">			}</span>
<span style="color: #339933;">		]]&gt;</span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:Script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;controls:ExternalClassModule</span> <span style="color: #000066;">creationComplete</span>=<span style="color: #ff0000;">&quot;buttonBar.visible=true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:VBox</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;testContainer&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:HBox</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;buttonBar&quot;</span> <span style="color: #000066;">visible</span>=<span style="color: #ff0000;">&quot;false&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Button</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;Test A&quot;</span> <span style="color: #000066;">click</span>=<span style="color: #ff0000;">&quot;loadTestClass('com.controls.TestControlA')&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Button</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;Test B&quot;</span> <span style="color: #000066;">click</span>=<span style="color: #ff0000;">&quot;loadTestClass('com.controls.TestControlB')&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Button</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;Test C&quot;</span> <span style="color: #000066;">click</span>=<span style="color: #ff0000;">&quot;loadTestClass('com.controls.TestControlC')&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Button</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;Test D&quot;</span> <span style="color: #000066;">click</span>=<span style="color: #ff0000;">&quot;loadTestClass('com.controls.TestControlD')&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:HBox<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:Application<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Module in External Library Project</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Module</span> <span style="color: #000066;">xmlns:mx</span>=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> <span style="color: #000066;">layout</span>=<span style="color: #ff0000;">&quot;absolute&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #339933;">&lt;![CDATA[</span>
<span style="color: #339933;">			import com.controls.TestControlD;TestControlD;</span>
<span style="color: #339933;">		]]&gt;</span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:Script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:Module<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<div class='fb_like_button' style='padding-top:5px;padding-bottom:5px'><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fblog.unthinkmedia.com%2F2010%2F09%2F01%2Fusing-getdefinitionbyname-with-external-library-swcs%2F&#038;layout=standart&#038;show_faces=true&#038;width=450&#038;action=like&#038;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:65px;"></iframe></div>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Using+getDefinitionByName%28%29+with+External+Library+SWCs+http://bit.ly/cbdnbS" title="Post to Twitter"><img class="nothumb" src="http://blog.unthinkmedia.com/wp-content/plugins/tweet-this/icons/tt-twitter-micro3.png" alt="Post to Twitter" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.unthinkmedia.com/2010/09/01/using-getdefinitionbyname-with-external-library-swcs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Handling External SWF Events in Flex using SWFLoader</title>
		<link>http://blog.unthinkmedia.com/2010/08/18/handeling-external-swf-events-in-flex-using-swfloader/</link>
		<comments>http://blog.unthinkmedia.com/2010/08/18/handeling-external-swf-events-in-flex-using-swfloader/#comments</comments>
		<pubDate>Thu, 19 Aug 2010 02:19:19 +0000</pubDate>
		<dc:creator>Alex Britez</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.unthinkmedia.com/?p=729</guid>
		<description><![CDATA[It has been a while since i&#8217;ve written about Flex development so I figured i would post up some useful code for anyone interested.  Recently I have been dealing with a lot of 3rd party code which relies on a huge amount of external SWF assets which load into Flex using SWFLoader.  The [...]]]></description>
			<content:encoded><![CDATA[<p>It has been a while since i&#8217;ve written about Flex development so I figured i would post up some useful code for anyone interested.  Recently I have been dealing with a lot of 3rd party code which relies on a huge amount of external SWF assets which load into Flex using SWFLoader.  The issue i ran into is that the developer getting access to &lt;mx:Application /&gt; from external SWF using the MovieClip(root) approach. This approach is a slight change to the old _root of the gloomy AS2 days. This created an extremely tightly coupled app, with mysterious methods scattered around the Flex project.  There was no way of knowing who was calling these methods, if they where deprecated, or if it was actually being used by some external SWF. Did I mention that there are 60 SWFs all with code in the timeline. It is like finding a needle in a haystack. Unfortunately for me, I wasn&#8217;t aware how tightly coupled these external swfs where and quickly proceeded to break the application whenever I attempted to refactor any code.</p>
<p>Obviously, calling &lt;mx:Application /&gt; to fake the old _root method of communicating with nested SWFs is not exactly the best way to go about this. Instead I favor using and Event driven approach. </p>
<p>This the code to create a simple external SWF with 5 textfields.  Each textfield is clickable and will dispatch a custom event which broadcast the value of the textfield.<br />
<span id="more-729"></span><br />
SWF Code</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">package</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">import</span> com.<span style="color: #660066;">events</span>.<span style="color: #660066;">ExternalSwfEvents</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">import</span> flash.<span style="color: #660066;">display</span>.<span style="color: #660066;">Sprite</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">import</span> flash.<span style="color: #660066;">events</span>.<span style="color: #660066;">MouseEvent</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">import</span> flash.<span style="color: #660066;">text</span>.<span style="color: #660066;">TextField</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">public</span> <span style="color: #003366; font-weight: bold;">class</span> SampleSWF <span style="color: #003366; font-weight: bold;">extends</span> Sprite
	<span style="color: #009900;">&#123;</span>
		<span style="color: #003366; font-weight: bold;">public</span> <span style="color: #003366; font-weight: bold;">function</span> SampleSWF<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i<span style="color: #339933;">:</span>int<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span><span style="color: #CC0000;">5</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				<span style="color: #003366; font-weight: bold;">var</span> tf<span style="color: #339933;">:</span>TextField <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> TextField<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				tf.<span style="color: #660066;">autoSize</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;left&quot;</span><span style="color: #339933;">;</span>
				tf.<span style="color: #660066;">text</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;Click me from External SWF &quot;</span> <span style="color: #339933;">+</span> i<span style="color: #339933;">;</span>
				tf.<span style="color: #660066;">y</span> <span style="color: #339933;">=</span> tf.<span style="color: #660066;">height</span> <span style="color: #339933;">*</span> i<span style="color: #339933;">;</span>
				tf.<span style="color: #660066;">selectable</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
				tf.<span style="color: #660066;">addEventListener</span><span style="color: #009900;">&#40;</span>MouseEvent.<span style="color: #660066;">CLICK</span><span style="color: #339933;">,</span> handleClick<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">addChild</span><span style="color: #009900;">&#40;</span>tf<span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #003366; font-weight: bold;">private</span> <span style="color: #003366; font-weight: bold;">function</span> handleClick<span style="color: #009900;">&#40;</span>event<span style="color: #339933;">:</span>MouseEvent<span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">void</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #003366; font-weight: bold;">var</span> tf<span style="color: #339933;">:</span>TextField <span style="color: #339933;">=</span> event.<span style="color: #660066;">target</span> <span style="color: #000066; font-weight: bold;">as</span> TextField<span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">//Make sure you set bubbles &amp; cancelable to true		</span>
<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">dispatchEvent</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">new</span> ExternalSwfEvents<span style="color: #009900;">&#40;</span>ExternalSwfEvents.<span style="color: #660066;">TEXT_CLICKED</span><span style="color: #339933;">,</span> tf.<span style="color: #660066;">text</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><em><br />
Take notice of the comment that states &#8220;Make sure you set bubbles &#038; cancelable to true&#8221;.  It is necessary to bubble this event because it may be nested several layers deep inside of the SWF</em>.</p>
<p>Custom Event named ExternalSwfEvents.as:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">package</span> com.<span style="color: #660066;">events</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">import</span> flash.<span style="color: #660066;">events</span>.<span style="color: #660066;">Event</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">public</span> <span style="color: #003366; font-weight: bold;">class</span> ExternalSwfEvents <span style="color: #003366; font-weight: bold;">extends</span> Event
	<span style="color: #009900;">&#123;</span>
		<span style="color: #003366; font-weight: bold;">public</span> static <span style="color: #003366; font-weight: bold;">const</span> TEXT_CLICKED<span style="color: #339933;">:</span>String <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;textClicked&quot;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #003366; font-weight: bold;">private</span> <span style="color: #003366; font-weight: bold;">var</span> value<span style="color: #339933;">:</span>String<span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #003366; font-weight: bold;">public</span> <span style="color: #003366; font-weight: bold;">function</span> ExternalSwfEvents<span style="color: #009900;">&#40;</span>type<span style="color: #339933;">:</span>String<span style="color: #339933;">,</span> value<span style="color: #339933;">:</span>String<span style="color: #339933;">,</span> bubbles<span style="color: #339933;">:</span>Boolean<span style="color: #339933;">=</span><span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">,</span> cancelable<span style="color: #339933;">:</span>Boolean<span style="color: #339933;">=</span><span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #003366; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span>type<span style="color: #339933;">,</span> bubbles<span style="color: #339933;">,</span> cancelable<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">value</span> <span style="color: #339933;">=</span> value<span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>So at this moment, the external SWF has no idea that it is an external app, nor does it know who or where the Flex application is.  All it knows is that it has some data stored in &#8220;value&#8221; that it would like to share with the world. If someone decided to listen for it, then they will be able to know what the contents of &#8220;value&#8221; are.  If not then no worries, it&#8217;s there if I ever decide I want to know what &#8220;value&#8221; is.</p>
<p>In my example I am going to load this file in Flex using SWFLoader.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Application</span> <span style="color: #000066;">backgroundColor</span>=<span style="color: #ff0000;">&quot;#FF0000&quot;</span> <span style="color: #000066;">xmlns:mx</span>=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> <span style="color: #000066;">layout</span>=<span style="color: #ff0000;">&quot;absolute&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #339933;">&lt;![CDATA[</span>
<span style="color: #339933;">			import com.events.ExternalSwfEvents;</span>
<span style="color: #339933;">			import mx.controls.Alert;</span>
&nbsp;
<span style="color: #339933;">			private function swfReady(event:Event):void</span>
<span style="color: #339933;">			{</span>
<span style="color: #339933;">				trace(&quot;COMPLETE&quot;);</span>
<span style="color: #339933;">				mySWF.content.addEventListener(ExternalSwfEvents.TEXT_CLICKED, handleEvent);</span>
<span style="color: #339933;">			}</span>
&nbsp;
&nbsp;
<span style="color: #339933;">			private function handleEvent(event:ExternalSwfEvents):void</span>
<span style="color: #339933;">			{</span>
<span style="color: #339933;">				Alert.show(&quot;You Clicked: &quot; + event.value);</span>
<span style="color: #339933;">			}</span>
<span style="color: #339933;">		]]&gt;</span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:Script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:SWFLoader</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;mySWF&quot;</span> <span style="color: #000066;">complete</span>=<span style="color: #ff0000;">&quot;swfReady(event)&quot;</span> <span style="color: #000066;">source</span>=<span style="color: #ff0000;">&quot;assets/SampleSWF.swf&quot;</span>  <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:Application<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Using this approach I know exactly what handleEvent is doing. I also know exactly what it will be receiving and when it will be receiving it.  A much nicer and cleaner approach to the
<div class='fb_like_button' style='padding-top:5px;padding-bottom:5px'><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fblog.unthinkmedia.com%2F2010%2F08%2F18%2Fhandeling-external-swf-events-in-flex-using-swfloader%2F&#038;layout=standart&#038;show_faces=true&#038;width=450&#038;action=like&#038;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:65px;"></iframe></div>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Handling+External+SWF+Events+in+Flex+using+SWFLoader+http://bit.ly/99mEuv" title="Post to Twitter"><img class="nothumb" src="http://blog.unthinkmedia.com/wp-content/plugins/tweet-this/icons/tt-twitter-micro3.png" alt="Post to Twitter" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.unthinkmedia.com/2010/08/18/handeling-external-swf-events-in-flex-using-swfloader/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Lessons Learned: Designing Toys for Children 7months-2yrs</title>
		<link>http://blog.unthinkmedia.com/2010/06/05/lessons-learned-designing-toys-for-children-7months-2yrs/</link>
		<comments>http://blog.unthinkmedia.com/2010/06/05/lessons-learned-designing-toys-for-children-7months-2yrs/#comments</comments>
		<pubDate>Sat, 05 Jun 2010 15:04:43 +0000</pubDate>
		<dc:creator>Alex Britez</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Education]]></category>
		<category><![CDATA[toys]]></category>

		<guid isPermaLink="false">http://blog.unthinkmedia.com/?p=693</guid>
		<description><![CDATA[
I have spent the past few month deconstructing the cognitive, emotional and social attributes of children under the age of two.  I have been particularly interested in understanding why children are more responsive to some toys, then they are for others. What makes a successful toy, and why? What strategies could be used in the [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-medium wp-image-716" title="Hugging Elmo" src="http://blog.unthinkmedia.com/wp-content/uploads/IMG_0782-225x300.jpg" alt="" width="225" height="300" /></p>
<p>I have spent the past few month deconstructing the cognitive, emotional and social attributes of children under the age of two.  I have been particularly interested in understanding why children are more responsive to some toys, then they are for others. What makes a successful toy, and why? What strategies could be used in the development of a toy to foster learning opportunities, along with several other question regarding this ripe age and this medium.</p>
<p>This age is quite interesting since you are not only designing for the child, but also for the parent, who acts as the gatekeeper. This adds an additional level of complexity, and understanding that needs to be understood. So the first question I asked myself was, &#8220;What does a parent look for in a toy?&#8221;</p>
<p>According to the book, &#8220;The Blockbuster Toys&#8221;, parents look for toys that;</p>
<ul>
<li>Child&#8217;s Safety</li>
<li>Child&#8217;s Continued Enjoyment (play value)</li>
<li>Child&#8217;s Creativity</li>
<li>Child&#8217;s Mental &amp; Physical Development</li>
<li>Child&#8217;s Success</li>
<li>Child&#8217;s Health</li>
<li>Child&#8217;s Love</li>
</ul>
<p>I added some additional bullets that I&#8217;ve noticed parents, including myself look into when purchasing a toy:<span id="more-693"></span></p>
<ul>
<li>Brand Loyalty: Parent could be very loyal to brand names.  There is a strong element of trust when a parent purchases a toy for their child.  Parent trust that Fisher-Price would not put a toy on the shelf that would be dangerous. Others may trust that Leap Frog toys will help their children become smarter.  Your options here are either try to license your toy with a company that has the brand recognition that could help proppel your toy, or make sure to market your company in a way that best reflects the goals of your merchandise.</li>
<li>Cleaning: How easy is it to clean this toy? At this age kids put toys in their mouths, and parents are sometimes extra cautious constantly cleaning their toys.</li>
<li>Durability: Will this toy sustain all the punishment that a young child puts on the toy?</li>
<li>Cost: This one really depends, but is a factor.  I some condition where other bullets such as &#8220;Child&#8217;s Continued Enjoyment&#8221; are high, parent&#8217;s may make addition investment. Your goal as a designer, should be to keep the cost as low as possible. I&#8217;ve hear that you should imagine all the parts of a toy in a bag and then multiply the cost by 4. That should give you an idea of what the on the shelf cost would be.</li>
</ul>
<p><strong>What is going on in their little heads?</strong><br />
Although each child is unique, there are some common developmental characteristics that we could use to help and identify common attributes. Through these attribute I&#8217;ve been hopping to uncover some rough guidelines to follow when creating toys for this age group.</p>
<p>Albeit, many toys on the market rely on gimmicks or piggy back on the shoulders of licensed characters to attract a child&#8217;s curiosity. However, all children have emotional needs that they expect to get fulfilled during play. According to the book <em>The Blockbuster Toy</em>, &#8220;The fulfillment of these  deep emotional needs is the fun that creates a smile&#8221; , and this results in a child&#8217;s consistent play interactions with the toy.</p>
<p>So what are some child&#8217;s emotional needs that anyone designing interaction for children in this age group should look into?</p>
<ul>
<li>Pride</li>
<li>Self-Esteem</li>
<li>Appreciation/Attention</li>
<li>Accomplishment/Mastery</li>
<li>Power/Empowerment</li>
<li>Control</li>
<li>Silliness</li>
<li>Independence/Freedom (harmless rebellion)</li>
<li>Belonging</li>
<li>Love Nurturing</li>
<li>Security</li>
<li>Fear Reduction/Bravery</li>
<li>Sensory Gratification</li>
<li>Mental and Physical Development</li>
</ul>
<p>I narrowed down this list of bullets that fall inline with the child&#8217;s development at this point. As they get older, things like fantasy and role playing also start to appear.</p>
<p><strong>What do children know at this age?</strong></p>
<p>The first place to look, is at the child&#8217;s stage of development. Jean Piaget, a Swiss epistemologist that focused his research around the development of children of this age to be in their Sensory Motor Stage of development:</p>
<blockquote><p>Sensorimotor stage: from birth to age 2. Children experience the world through movement and senses (use five senses to explore the world). During the sensorimotor stage children are extremely egocentric, meaning they cannot perceive the world from others&#8217; viewpoints. The sensorimotor stage is divided into six substages: &#8220;(1) simple reflexes; (2) first habits and primary circular reactions; (3) secondary circular reactions; (4) coordination of secondary circular reactions; (5) tertiary circular reactions, novelty, and curiosity; and (6) internalization of schemes.&#8221;</p></blockquote>
<p>Love and Security</p>
<p>Children at this stage of development need to feel safe and loved. Many of the children in the lower part of this demographic still rely solely on their mother for nourishment.  This bonding along with all the hugs and kisses they get from their parents, help a child feel the security they need to find their place in this world, and with their family. Children will sometimes show their love and nurturing to a toy doll by snuggling up with it.</p>
<p>Language</p>
<p>Children at this age <a href="http://www.npr.org/templates/transcript/transcript.php?storyId=125123354" target="_blank">recognize voices and the emotions that they convey</a>.  Although a child at this age is just beginning to create a vocabulary, they do understand much of what you are saying to them.  Like little sponges they start to develop a schema for spoken words and actions and objects. Eventually, towards the child starts to experiment with their own voice to mimic sounds.</p>
<p>Babies of this age could also identify familiar voices.  If you put mommy on speaker phone they may start looking around the room to see where mommy is.</p>
<p>This is a perfect time to give a child an opportunity to make connection and experiment with language to help with their development.  The more a toy allows a child to be vocal, the quicker they will learn how to control their vocal instrument.</p>
<p>People and Objects</p>
<p>Children at this age are good with faces. <a href="http://www.sciencedaily.com/releases/2005/01/050104114623.htm" target="_blank">Babies could recognize face structures</a> and they use physical characteristics,  characteristic expressions, postures and movements to identify specific individuals to create mental models of people. Many times, when a baby sees a photo of mommy, they could easily make the correlation between mommy and the photo, and results in a smile and excitement. This same process happens with objects that they discover and interact with, however these mental models are very generalized. Although they may know what a doggie is, they may also think a cow is doggie, or any other animal that has 4 legs.</p>
<p><strong>How do children play at this age?</strong><br />
Children at this preliminary stage of development are self-centered. They don&#8217;t do well in collaborative play since their social development has not ripened. Concepts like &#8220;sharing&#8221; do not come naturally till later in this stage, or possibly well into the following stage, depending on how quickly their socialization skills develop. Through these formative years, you will see more &#8220;parallel play&#8221;. Typically, children are in their own little world playing, even if there is another child playing right next to them. Creating a toy that requires collaboration or cooperation would probably be too advanced for this age group.</p>
<p>Structure is a &#8220;no go&#8221; with young children. They are more interested in &#8220;free play&#8221;. These children lack the cognitive ability to play a game with rules or activities that require advanced forms of interaction. Keeping it simple with clear feedback is the way to go. Simple switches with blinking lights and audio work well, but don&#8217;t feel as though that is all you could do. You could get creative and create some interesting simple interaction from a ball with an embedded tilt sensor.  As with any design limitation, it could usually be solved with creativity.</p>
<p>This age group is packed with little explorers, constantly scanning the room and objects for something to interact with.  They enjoy to the feeling of empowerment when their actions result in sort of feedback (lights, audio, parent&#8217;s laughter).  Once they discover a &#8220;cause and effect&#8221; interaction, they will sometimes continue testing their hypothesis over and over.  If you have ever seen a child that discovers how to open a kitchen cabinet, you will know what i mean. Open, close, open, close &#8230; parent buys a cabinet lock.<br />
<strong>Conclusion</strong><br />
After following all these guidelines the truth of the matter is that the toy industry is a tough to break into.  There are only a handful of successful toys that make it big each year, while thousands of others collect dust on shelves, if they get on the shelves at all.  The one piece of advice that I read though my research which really made sense is, &#8220;Do it for the smiles, not the money&#8221;.  That is the essence of toy building, before companies like Mattel and Hasbro came along, parent would create toys simply for getting the satisfaction of watching the smiles on their children&#8217;s faces. The other piece of advice is don&#8217;t get married to any idea. If you get too emotionally invested in an idea, it will not allow you to see it&#8217;s flaws. Unless you are making the toy for yourself, then you need to step back and see what of your audience&#8217;s goals you have accomplished.</p>
<p><strong>References</strong><br />
<a href="http://www.amazon.com/gp/product/0684834480?ie=UTF8&#038;tag=unthinkmedia-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=0684834480">What Kids Buy and Why: The Psychology of Marketing to Kids</a><img src="http://www.assoc-amazon.com/e/ir?t=unthinkmedia-20&#038;l=as2&#038;o=1&#038;a=0684834480" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /><br />
<a href="http://www.amazon.com/gp/product/1589801229?ie=UTF8&#038;tag=unthinkmedia-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=1589801229">Blockbuster Toy!, The: How to Invent the Next BIG Thing</a><img src="http://www.assoc-amazon.com/e/ir?t=unthinkmedia-20&#038;l=as2&#038;o=1&#038;a=1589801229" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /><br />
<a href="http://www.amazon.com/gp/product/0976697327?ie=UTF8&#038;tag=unthinkmedia-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=0976697327">Marketing to the New Super Consumer: Mom &#038; Kid</a><img src="http://www.assoc-amazon.com/e/ir?t=unthinkmedia-20&#038;l=as2&#038;o=1&#038;a=0976697327" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /></p>
<div class='fb_like_button' style='padding-top:5px;padding-bottom:5px'><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fblog.unthinkmedia.com%2F2010%2F06%2F05%2Flessons-learned-designing-toys-for-children-7months-2yrs%2F&#038;layout=standart&#038;show_faces=true&#038;width=450&#038;action=like&#038;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:65px;"></iframe></div>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Lessons+Learned%3A+Designing+Toys+for+Children+7months-2yrs+http://bit.ly/caecbt" title="Post to Twitter"><img class="nothumb" src="http://blog.unthinkmedia.com/wp-content/plugins/tweet-this/icons/tt-twitter-micro3.png" alt="Post to Twitter" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.unthinkmedia.com/2010/06/05/lessons-learned-designing-toys-for-children-7months-2yrs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Multi-Master Arduino Setup using i2c</title>
		<link>http://blog.unthinkmedia.com/2010/05/05/multi-master-arduino-setup-using-i2c/</link>
		<comments>http://blog.unthinkmedia.com/2010/05/05/multi-master-arduino-setup-using-i2c/#comments</comments>
		<pubDate>Wed, 05 May 2010 17:22:34 +0000</pubDate>
		<dc:creator>Alex Britez</dc:creator>
				<category><![CDATA[Examples]]></category>
		<category><![CDATA[Physical Computing]]></category>
		<category><![CDATA[programing]]></category>
		<category><![CDATA[arduino]]></category>
		<category><![CDATA[electronics]]></category>
		<category><![CDATA[i2c]]></category>
		<category><![CDATA[physical computing]]></category>

		<guid isPermaLink="false">http://blog.unthinkmedia.com/?p=678</guid>
		<description><![CDATA[I working on a project, I was faced with a challenge of creating a serial bus via multiple Arduino which could communicate with each other.  My first intuition, after a little push in the right direction by Tom Igoe, was to create a Master/Slave setup where a Master micro-controller polls all the slave micro-controllers, [...]]]></description>
			<content:encoded><![CDATA[<p>I working on a project, I was faced with a challenge of creating a serial bus via multiple Arduino which could communicate with each other.  My first intuition, after a little push in the right direction by <a href="http://www.tigoe.net/">Tom Igoe</a>, was to create a Master/Slave setup where a Master micro-controller polls all the slave micro-controllers, and dispatches an action. Although this answered one of my question, polling didn&#8217;t allow for complete 2-way communication.  It tuned out that the answer was mainly an oversight of my interpretation of the <a href="http://arduino.cc/en/Reference/Wire">Wire documentation</a>.</p>
<p>From Arduino Site:</p>
<blockquote><p>
Wire.begin()<br />
Wire.begin(address)<br />
====<br />
Description<br />
Initiate the Wire library and join the I2C bus as a master or slave.<br />
====<br />
Parameters<br />
address: the 7-bit slave address (optional); <strong>if not specified, join the bus as a master</strong>.<br />
====<br />
Returns<br />
none</p></blockquote>
<p>I interpreted this explanation as Wire.begin(<em>SomeAddress</em>) would default as a slave, and <strong>not</strong> be allowed to be a Master.  Being as curious, and stubborn as I typically am, i decided to forget what I thought I was being told, and instead try to break the library, so I could then see where it broke, and attempt to adjust it in a way that better suited my need. Surprise, surprise, it worked, and not need to change anything at all!  The address parameter is <em>optional</em> and defaults as a master role if no address is set. However if you do plan on sending messages to the master, you could switch speaker and listener roles via a slaves Wire.onReceive(handler) rather then polling using onRequest(handler).<span id="more-678"></span></p>
<p>I then decided to do a search on google for just &#8220;i2c&#8221;. When I clicked on the <a href="http://en.wikipedia.org/wiki/I%C2%B2C">Wikipedia entry</a> it all made sense in the first sentence of the entry summary:</p>
<blockquote><p>
I²C (Inter-Integrated Circuit) (pronounced /ˈaɪ skwɛərd ˈsiː/ or /ˈaɪ tuː ˈsiː/) is a <em>multi-master</em> serial single-ended computer bus&#8230;</p></blockquote>
<p>This basically states that no one microcontroller (unless you do not specify an address) could claim being a master at all time.  They could be bumped off their soupbox by another microcontrol and assume the role of listener/slave at anytime.
<div class='fb_like_button' style='padding-top:5px;padding-bottom:5px'><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fblog.unthinkmedia.com%2F2010%2F05%2F05%2Fmulti-master-arduino-setup-using-i2c%2F&#038;layout=standart&#038;show_faces=true&#038;width=450&#038;action=like&#038;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:65px;"></iframe></div>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Multi-Master+Arduino+Setup+using+i2c+http://blog.unthinkmedia.com/?p=678" title="Post to Twitter"><img class="nothumb" src="http://blog.unthinkmedia.com/wp-content/plugins/tweet-this/icons/tt-twitter-micro3.png" alt="Post to Twitter" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.unthinkmedia.com/2010/05/05/multi-master-arduino-setup-using-i2c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Why I make &#8220;Native Mobile Apps&#8221; not &#8220;Native iPhone Apps&#8221;</title>
		<link>http://blog.unthinkmedia.com/2010/04/12/i-make-mobile-apps-not-iphone-apps/</link>
		<comments>http://blog.unthinkmedia.com/2010/04/12/i-make-mobile-apps-not-iphone-apps/#comments</comments>
		<pubDate>Mon, 12 Apr 2010 22:46:44 +0000</pubDate>
		<dc:creator>Alex Britez</dc:creator>
				<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.unthinkmedia.com/?p=645</guid>
		<description><![CDATA[A little over a year ago, I was drawn to this marvelous device, named the iPhone.  All the possibilities that it could bring opening up another outlet for me to develop applications for.  Seeing the possibilities, like many developers, I ran out to the nearest Barnes &#38; Noble and bought an &#8220;Introduction to [...]]]></description>
			<content:encoded><![CDATA[<p>A little over a year ago, I was drawn to this marvelous device, named the iPhone.  All the possibilities that it could bring opening up another outlet for me to develop applications for.  Seeing the possibilities, like many developers, I ran out to the nearest Barnes &amp; Noble and bought an &#8220;Introduction to iPhone Development&#8221; book.  I diligently went though each and every chapter, getting acquainted to Objective-C and the iPhone development environment. Then it hit me!  Do I want to be an iPhone Developer or a Mobile Developer? What happens when <a href="http://www.h-online.com/open/news/item/Report-Android-gaining-market-share-971744.html">Android gains market share</a>? What about Windows and BlackBerry? iPhone&#8217;s reign could only last for so long, and the pack is slowly creeping up.</p>
<p>The iPhone revolution placed blinders on us all, and many of us forgot the obvious. Remember years ago, when you would go to a site only to be greeted with a &#8220;Sorry we do not support your current browser, this site is optimized for IE 6&#8243;, you would be forced to close you current session on the non-IE browser and open up IE to view the site.  What a pain! Eventually, javascript libraries like JQuery, and the adoption of CSS standards have made that less of an issue, although you still see this once in a while.  The main difference however between the browser wars, and mobile wars is that browser all interpreted HTML and CSS, with only slight differences. Mobile phone native coding language on the other hand are extremely different. iPhone coding looks very different then Android, which look different the Windows Mobile.  That means more resources need to be allocate on a project, costing the perspective client more money. Not exactly a smart investment, and unfortunately there is no &#8220;Export to Android&#8221; option in Apple&#8217;s XCode software.<br />
<span id="more-645"></span><br />
To help put this in perspective, just imagine a client coming in, and being irate because a site you built for them only works in Firefox. I am guessing the conversation would go a little something like:</p>
<blockquote><p>Client: Hey, I just checked out the site in Safari and it didn&#8217;t work<br />
You: &#8220;Sorry, Safari is extra&#8221;.<br />
Client: Extra? But i paid you to make me a website!<br />
You: &#8220;No, you paid us to make a Firefox website&#8221;.<br />
Client: &#8220;Isn&#8217;t that the same thing?&#8221;<br />
You: &#8220;No that will require substantial more work, but we could give you an estimate on that&#8221;<br />
Client: What about IE?<br />
You: &#8220;Yep that will cost you too!&#8221;<br />
Client: And Chrome?<br />
You: Sorry we don&#8217;t have an in-house Chrome developer. We won&#8217;t be able to support that</p></blockquote>
<p>Luckily I was not the only one to get this &#8220;ah-ha&#8221; moment, and I ran into multiple projects such as <a href="http://www.phonegap.com">PhoneGap</a> (@PhoneGap), <a href="http://www.appcelerator.com/">Titanium</a> (@jhaynie), and <a href="http://rhomobile.com/">Rhodes Mobile</a> (@rhomobile).  Adobe eventually joined the party (disclaimer: I haven&#8217;t actually tried this yet) with the addition of the &#8220;Export to iPhone&#8221; option, which promises to include the rest of the mobile devices soon.  I decided on PhoneGap, simply for the fact that it supported the most hardware (iPhone, Android,  Windows 7 Phone, Windows Mobile, Blackberry, Symbian, Palm Pre, a few others), was written all in JavaScript/HTML5/CSS. PhoneGap creates a bridge between Objective-C and Javascript through WebKit so I could call native functions like the Camera, Vibrate, etc. on all the aforementioned devices. Being able to to use the same codebase for &#8220;ALL&#8221; devices is something that not only applies to my needs, but makes it easier to pursue a client, and pitch them an app that will work on as many mobile platforms as possible, giving them the highest return on investment.</p>
<p>There are scenarios where using a fully native solution would probably make sense, however even in those scenarios creating a fully iPhone solution doesn&#8217;t make sense. If you use something like Unity3D for high end game development you get iPhone, Android, and even Playstation exports. This holds true for other game development environments like Torque2D &amp; 3D, and even Flash CS5.</p>
<p>Unforunitly all these options have entered a state of limbo, due to Apple&#8217;s new adjustment of it&#8217;s terms of service:</p>
<blockquote><p>Applications must be originally written in Objective-C, C, C++, or JavaScript as executed by the iPhone OS WebKit engine, and only code written in C, C++, and Objective-C may compile and directly link against the Documented APIs (e.g., Applications that link to Documented APIs through an intermediary translation or compatibility layer or tool are prohibited).</p></blockquote>
<p>No official word, but I highly doubt that PhoneGap will be affected by this, since it runs out of XCode and uses Objective-C to speak with JavaScript inside of Webkit, which seems to fall in line. I am pretty sure that Unity3D is also safe since you could open up a Unity3D project in XCode and see all the Objective-C. My problem is that there are other programs, specifically Flex/AIR and Mono that are very suited to do mobile development.</p>
<p>This by no means is this a gripe about Flash or any other program being left out, I&#8217;ve prided myself in using ANY technology that works and makes the most business sense for each specific project. Even if it means learning an entirely new development environment which is what I initially did by learning Objective-C. However, Objective-C made no sense for me nor my clients needs, if a project came up where Objective-C was needed then by all means I would code it in Objective-C.  For now I am happy with PhoneGap.  It does the job, and does it well, my only issue is that JavaScript isn&#8217;t naturally Object Oriented, which forces me to come up with solution to mimic an Object Oriented environment. This is what enables me to keep my sanity.  It also allows me to make any adjustment, or enhancements to the PhoneGap code if the need arises, since i could easily fork the <a href="http://github.com/sintaxi/phonegap">PhoneGap Objective-C code from their repository</a>.</p>
<blockquote><p><strong><span style="color: #ff0000;">UPDATE</span></strong> (5/15/2010): Engadget reports that P<a href="http://www.engadget.com/2010/04/15/phonegap-framework-fine-for-app-store-development-sez-apple/">honeGap framework fine for App Store development</a></p></blockquote>
<div class='fb_like_button' style='padding-top:5px;padding-bottom:5px'><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fblog.unthinkmedia.com%2F2010%2F04%2F12%2Fi-make-mobile-apps-not-iphone-apps%2F&#038;layout=standart&#038;show_faces=true&#038;width=450&#038;action=like&#038;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:65px;"></iframe></div>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Why+I+make+%E2%80%9CNative+Mobile+Apps%E2%80%9D+not+%E2%80%9CNative+iPhone+Apps%E2%80%9D+http://bit.ly/aukpXA" title="Post to Twitter"><img class="nothumb" src="http://blog.unthinkmedia.com/wp-content/plugins/tweet-this/icons/tt-twitter-micro3.png" alt="Post to Twitter" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.unthinkmedia.com/2010/04/12/i-make-mobile-apps-not-iphone-apps/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Sensing Child&#8217;s Play: Examining 7 toys from the toybox</title>
		<link>http://blog.unthinkmedia.com/2010/03/27/sensing-childs-play-examining-7-toys-from-the-toybox/</link>
		<comments>http://blog.unthinkmedia.com/2010/03/27/sensing-childs-play-examining-7-toys-from-the-toybox/#comments</comments>
		<pubDate>Sat, 27 Mar 2010 16:14:09 +0000</pubDate>
		<dc:creator>Alex Britez</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Physical Computing]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[children]]></category>
		<category><![CDATA[electronics]]></category>
		<category><![CDATA[sensors]]></category>
		<category><![CDATA[toys]]></category>

		<guid isPermaLink="false">http://blog.unthinkmedia.com/?p=579</guid>
		<description><![CDATA[I have always had a fascination with trying to understand how the things around me work. It just so happens that after having a child, most of the thing around me are toys. Large toys, small toy, blinking lights, sounds, singing, haptics, interactivity, it is all pretty darn amazing when you sit back and really [...]]]></description>
			<content:encoded><![CDATA[<p>I have always had a fascination with trying to understand how the things around me work. It just so happens that after having a child, most of the thing around me are toys. Large toys, small toy, blinking lights, sounds, singing, haptics, interactivity, it is all pretty darn amazing when you sit back and really look at how much technology my little one year old daughter navigates and interacts with during play.  Many time when we think of children and technology we automatically think of desktop computers and video game consoles. Although all of these are examples of technology the only interaction my daughter has with them is me telling her, &#8220;don&#8217;t touch&#8221;, and handing her a toy to distract her attention.</p>
<p>I decided to take a trip to my daughter&#8217;s toy collection to examine some of the sensing capabilities that her electronic toys offer.  I will specifically focus on the toys input capabilities:</p>
<p>(At the end of the post there is a video of me trying to figure out how the LeapFrog Tag Jr works. Let me know your thoughts.)</p>
<p><strong><a href="http://www.amazon.com/gp/product/B001W1R176?ie=UTF8&#038;tag=unthinkmedia-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=B001W1R176">Fisher-Price Elmo Live Encore</a><img src="http://www.assoc-amazon.com/e/ir?t=unthinkmedia-20&#038;l=as2&#038;o=1&#038;a=B001W1R176" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /><br />
</strong><br />
This is by far one my daughters favorite toys.  The toy is modeled after Elmo, a Sesame Street character, which most children a quickly drawn to by his bright red color, large eyes, and youthfully fun voice.<br />
<a href="http://www.amazon.com/gp/product/B001W1R176?ie=UTF8&#038;tag=unthinkmedia-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=B001W1R176"><img src="http://blog.unthinkmedia.com/wp-content/uploads/41MJQ2ttTwL._SL500_AA300_.jpg" alt="" title="41MJQ2ttTwL._SL500_AA300_" width="300" height="300" class="alignleft size-full wp-image-593" /></a></p>
<p>Inputs</p>
<ul>
<li>Push Buttons: Typically buttons on toys are visually obvious, however Fisher Price decided to create an exploratory interaction by spreading out four button throughout the plush doll.  Three of the buttons are hidden under the fabric, on the toe, chest, and back, and the final button switch is closed by squeezing his nose.</li>
<li>Tilt Sensor: One of the nice additions that the creators added to the toy was integration of a Tilt Sensor. When Elmo falls on his side, he politely ask for help to stand backup, which is sometime accompanied with a joke.</li>
</ul>
<p><br style="clear:both;" /><br />
<span id="more-579"></span></p>
<p><strong><a href="http://www.amazon.com/gp/product/B002PHLU4G?ie=UTF8&#038;tag=unthinkmedia-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=B002PHLU4G">LeapFrog Learn &#038; Groove™ Musical Table</a><img src="http://www.assoc-amazon.com/e/ir?t=unthinkmedia-20&#038;l=as2&#038;o=1&#038;a=B002PHLU4G" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /><br />
</strong><br />
We originally got this toy when our daughter was showing signs of wanting to stand on her own.  The toy itself is stuffed with several auditory and visual feedback that really grabs her attention.<br />
<a href="http://www.amazon.com/gp/product/B002PHLU4G?ie=UTF8&#038;tag=unthinkmedia-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=B002PHLU4G"><img src="http://blog.unthinkmedia.com/wp-content/uploads/51NJ3M2DARL._AA300_.jpg" alt="" title="51NJ3M2DARL._AA300_" width="300" height="300" class="alignleft size-full wp-image-591" /></a></p>
<p>Inputs</p>
<ul>
<li>Push Buttons: Typically buttons on toys are visually obvious, however Fisher Price decided to create an exploratory interaction by spreading out four button throughout the plush doll.  Three of the buttons are hidden under the fabric, on the toe, chest, and back, and the final button switch is closed by squeezing his nose.</li>
<li>Toggling Buttons: From watching my daughter play with this section of the table, I noticed that the design decision was probably based around learning not only shapes, but also cause and effect.  When she presses one, the previously pressed button switch pops up to an open state.</li>
<li>Flipping : This might be one of my daughter favorite interactions.  It may be partly due to the fact that we read a lot of books to her, or it might just be an intrinsic curiosity that makes her want to flip things over.  Feedback is dispatched when the child flips the pages of the book on the center of the toy, and also when they open the small compartment on one of the sides.  I would imagine that the switch is hidden on the hinge of the book. Each page has individual hinges that are associate with it. Once the page is flipped and crosses the angular threshold an embedded audio file is dispatched, along with some dancing LEDs. </li>
<li>Slider: The slider, is a &#8220;slider&#8221; in the physical interaction sense of the word. However the slider does not send an analog signal, or at least is doesn&#8217;t technically need too.  I believe that the reason for the design decision was mainly an educational one to create opportunity to exercise multiple sensory motor functions (sliding, twisting, pushing, flipping, etc.) </li>
</ul>
<p><br style="clear:both;" /></p>
<p><strong><a href="http://www.amazon.com/gp/product/B001W35I8I?ie=UTF8&#038;tag=unthinkmedia-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=B001W35I8I">LeapFrog My Pal Violet</a><img src="http://www.assoc-amazon.com/e/ir?t=unthinkmedia-20&#038;l=as2&#038;o=1&#038;a=B001W35I8I" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /><br />
</strong><br />
This product is actually one of my favorites. In the exterior it seems like a pretty straight forward digitally enhanced plush toy, but it add another layer of interaction for the parent, which evolves connecting the toy to the computer via USB and downloading audio files onto the toy. There is also some slight visual feedback from the LED that is housed in the plastic bone around the toy&#8217;s neck.<br />
<a href="http://www.amazon.com/gp/product/B001W35I8I?ie=UTF8&#038;tag=unthinkmedia-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=B001W35I8I"><img src="http://blog.unthinkmedia.com/wp-content/uploads/51Ff8bs7pwL._SL500_AA300_.jpg" alt="" title="51Ff8bs7pwL._SL500_AA300_" width="300" height="300" class="alignleft size-full wp-image-592" /></a></p>
<p>Inputs</p>
<p>Push Buttons: There are 4 normally open push buttons, each living on one of the plush dog&#8217;s paws. All the buttons, have iconic representations of the type of audio that it will dispatch once the switch is closed: Music, Action, Lullaby , and Power Off. </p>
<p>Parental Interaction<br />
Keyboard/Mouse: The toy comes with a desktop application that syncs with the toy via USB. The parent could then select which audio files to have the available to the toy. They are also able to personalizing some the interaction, by selecting from a list of names.<br />
<br style="clear:both;" /></p>
<p><strong><a href="http://www.amazon.com/gp/product/B000NRX5XE?ie=UTF8&#038;tag=unthinkmedia-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=B000NRX5XE">LeapFrog Spin and Sing Alphabet Zoo</a><img src="http://www.assoc-amazon.com/e/ir?t=unthinkmedia-20&#038;l=as2&#038;o=1&#038;a=B000NRX5XE" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /><br />
</strong><br />
This was probably the first toy that my daughter mastered at a couple months old. She almost looked like a boxer spinning the all the letters round and round, and enjoy the audio that is dispatched on the toys active state. Once the action stops, and the spinning section comes to a stop, the audio dispatches which animal or letter is in between the arrows, sort of like the large wheel from Wheel of fortune.</p>
<p><a href="http://www.amazon.com/gp/product/B000NRX5XE?ie=UTF8&#038;tag=unthinkmedia-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=B000NRX5XE"><img src="http://blog.unthinkmedia.com/wp-content/uploads/pTRU1-3387830reg.jpg" alt="" title="pTRU1-3387830reg" width="220" height="220" class="alignleft size-full wp-image-588" /></a></p>
<p>Inputs</p>
<p>Without gutting this toy (my wife would kill me) I&#8217;m not too sure how they made this work, however my best guess is:</p>
<p>Metal roller/ball bearing &#038; Metal Plate contact:  each of the 25 selections have individual plates that are connected to some sort of Shift register or multiplexer. As the the spinning action occurs the fixed conductive roller stays in contact with each of the plates that passes by. Once an individual contact is closed for about a second, the spin cycle is assumed to have finished, and the appropriate audio file is dispatched. Not sure if this is accurate since this may add friction. I can&#8217;t be sure unless i open it up.<br />
<br style="clear:both;" /></p>
<p>Here is a video of my daughter playing with this toy:<br />
<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/erkl1VqG114&#038;hl=en&#038;fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/erkl1VqG114&#038;hl=en&#038;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object></p>
<p><strong><a href="http://www.amazon.com/gp/product/B000ETREN8?ie=UTF8&#038;tag=unthinkmedia-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=B000ETREN8">LeapFrog Learn &#038; Groove Counting Maracas</a><img src="http://www.assoc-amazon.com/e/ir?t=unthinkmedia-20&#038;l=as2&#038;o=1&#038;a=B000ETREN8" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /><br />
</strong><br />
These are bionic baby rattles/maraca that sense when they are being shaken. Once they are shaken an array of lights and melodies start to play. These are lots of fun, and has an added affordance of making adults act like complete fools.</p>
<p><a href="http://www.amazon.com/gp/product/B000ETREN8?ie=UTF8&#038;tag=unthinkmedia-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=B000ETREN8"><img src="http://blog.unthinkmedia.com/wp-content/uploads/pTRU1-2878179reg.jpg" alt="" title="pTRU1-2878179reg" width="220" height="220" class="alignleft size-full wp-image-586" /></a><br />
Input</p>
<ul>
<li>Slide Switch: This is just a simple multi state switch to adjust various mode settings</li>
<li>Accelerometer or Tilt Switch: Not sure exactly how they are sensing movement, but typically you would use either a tilt switch, or accelerometer. I would put money on the tilt switch mainly for cost, and being that the accelerometer may be overkill.</li>
</ul>
<p><br style="clear:both;" /></p>
<p><strong><a href="http://www.amazon.com/gp/product/B000W3TD44?ie=UTF8&#038;tag=unthinkmedia-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=B000W3TD44">Fisher-Price Go Baby Go! Crawl-Along Musical Ball</a><img src="http://www.assoc-amazon.com/e/ir?t=unthinkmedia-20&#038;l=as2&#038;o=1&#038;a=B000W3TD44" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /><br />
</strong><br />
We bought this toy when the baby was in the brink of starting of crawling.  The interaction involves rolling the ball and watch the illusion of the monkey keeping it&#8217;s balance, while letting out some humorous squeals.<br />
<a href="http://www.amazon.com/gp/product/B000W3TD44?ie=UTF8&#038;tag=unthinkmedia-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=B000W3TD44"><img src="http://blog.unthinkmedia.com/wp-content/uploads/pG01-4243725reg.jpg" alt="" title="pG01-4243725reg" width="220" height="220" class="alignleft size-full wp-image-595" /></a><br />
Input<br />
The only input for this toy is sensing that the ball is in movement. Since the ball roll only in one direction, I would imagine a spinning tilt switch is all that was needed to sense when the ball was in motion.<br />
<br style="clear:both;" /></p>
<p><strong><a href="http://www.amazon.com/gp/product/B001U5R200?ie=UTF8&#038;tag=unthinkmedia-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=B001U5R200">LeapFrog Tag Junior Book Pal &#8211; Purple</a><img src="http://www.assoc-amazon.com/e/ir?t=unthinkmedia-20&#038;l=as2&#038;o=1&#038;a=B001U5R200" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /><br />
</strong><br />
One of my friends bought this toy for my daughter, which is a bit advanced for her, however extremely impressive.  This toy serves a scaffold for children that are learning to read. By simply touching the pen on the area of the word, it dispatches an audio files that speaks the word that they child selected.<br />
<a href="http://www.amazon.com/gp/product/B001U5R200?ie=UTF8&#038;tag=unthinkmedia-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=B001U5R200"><img src="http://blog.unthinkmedia.com/wp-content/uploads/pTRU1-5751447reg.jpg" alt="" title="pTRU1-5751447reg" width="220" height="220" class="alignleft size-full wp-image-615" /></a><br />
Input</p>
<p>It is totally beyond me how this technology works, but I will post up a video of me trying to guess. No idea if will actually be right, and unfortunately I need to wait till my daughter could read before I could take it apart, so a guess will do for now.<br />
<br style="clear:both;" /><br />
My guess on how the LeapFrog Tag Junior works:<br />
<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/9XvYnvjyzps&#038;hl=en&#038;fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/9XvYnvjyzps&#038;hl=en&#038;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object></p>
<p><em><strong>Update</strong>:  So it turns out I was correct&#8230;woohoo!  I did a few searches and ran into the LeapFrog FlyPaper Pen. I didn&#8217;t event know LeapFrog made this. Anyhow, I downloaded the manual and this is what it says under &#8220;How it works&#8221;. (would have been a lot easier if they added that section in the Tag manual). </p>
<blockquote><p>The FLY Fusion Pentop Computer has a built-in camera next to the writing tip. When you write, the camera sees tiny dots on the FLY™ Paper, which are printed with reflective ink in a very subtle pattern. The camera takes a series of fast snapshots of the dots, reads the pattern, and finds the action assigned to those dots.</p></blockquote>
<p>I think it is safe to assume that they leveraged the same technology.</p>
<p>I also found another guy who made a video about the same exact topic, and had the same answer. <a href="http://www.youtube.com/watch?v=A6yKZ1wjUgg">http://www.youtube.com/watch?v=A6yKZ1wjUgg</a></em></p>
<div class='fb_like_button' style='padding-top:5px;padding-bottom:5px'><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fblog.unthinkmedia.com%2F2010%2F03%2F27%2Fsensing-childs-play-examining-7-toys-from-the-toybox%2F&#038;layout=standart&#038;show_faces=true&#038;width=450&#038;action=like&#038;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:65px;"></iframe></div>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Sensing+Child%E2%80%99s+Play%3A+Examining+7+toys+from+the+toybox+http://bit.ly/dh9rbH" title="Post to Twitter"><img class="nothumb" src="http://blog.unthinkmedia.com/wp-content/plugins/tweet-this/icons/tt-twitter-micro3.png" alt="Post to Twitter" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.unthinkmedia.com/2010/03/27/sensing-childs-play-examining-7-toys-from-the-toybox/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Initial Test of my Expandable/Interchangeable Circuit</title>
		<link>http://blog.unthinkmedia.com/2010/03/20/initial-test-of-my-expandable-circuit/</link>
		<comments>http://blog.unthinkmedia.com/2010/03/20/initial-test-of-my-expandable-circuit/#comments</comments>
		<pubDate>Sun, 21 Mar 2010 06:05:10 +0000</pubDate>
		<dc:creator>Alex Britez</dc:creator>
				<category><![CDATA[Education]]></category>
		<category><![CDATA[Examples]]></category>
		<category><![CDATA[Physical Computing]]></category>
		<category><![CDATA[programing]]></category>
		<category><![CDATA[arduino]]></category>
		<category><![CDATA[digital manipulative]]></category>
		<category><![CDATA[EEPROM]]></category>
		<category><![CDATA[manipulative]]></category>

		<guid isPermaLink="false">http://blog.unthinkmedia.com/?p=562</guid>
		<description><![CDATA[So what do i mean by expandable? Basically the idea is that I would like the cheapest possible way to be able to create a circuit that I could chain sub circuits too (those are the 2 sub circuits in the video).  After lots of trial and error, I was able to put on [...]]]></description>
			<content:encoded><![CDATA[<p><img alt="" src="http://static.sparkfun.com/images/products/EEPROM_i_ma.jpg" class="alignright" width="188" height="188" />So what do i mean by expandable? Basically the idea is that I would like the cheapest possible way to be able to create a circuit that I could chain sub circuits too (those are the 2 sub circuits in the video).  After lots of trial and error, I was able to put on my crafty hat to make these darn electrons work the way I wanted them too.</p>
<p>In the accompanying video, I give a quick run through of how the circuit works.  Essentially, the main goal that I was able to achieve was that I would be able to clone one the inner circuits and add it right in the middle. All I would need to do is connect them to the 2 digital pins, 2 analog pins, one ground, and one 5V series, and it should work without any additional rewiring (although the idea is to make the sub circuits slightly different in their interaction, yet the same in their communication), asides from programing the EEPROM (<a href="http://www.sparkfun.com/commerce/product_info.php?products_id=525">I used the 24LC256 from SparkFun for $1.95</a>) to contain a unique identifier.  The secret to success&#8230;diodes..lots of them.</p>
<p>I based my code on a <a href="http://www.arduino.cc/playground/Code/I2CEEPROM">great snippet of code</a> to help me get the I2C communication working on my EEPROMs. I also checked out a <a href="http://www.ghettohax.com/2009/02/i2c-eeprom-for-arduino.html">helpful tutorial </a>which also helped me out substantially.</p>
<p>One quick tip: Keep in mind that Arduino has an EEPROM mounted on the chip.  I intially made the silly mistake of using the <a href="http://arduino.cc/en/Tutorial/HomePage">EEPROM code that is found on the Arduino tutorial page</a>. This code was reading and writing data on my Arduino&#8217;s board mounted EEPROM, which i quickly realized once I realized that the unique data I was writing on each external EEPROM chip did not seem to be working properly.</p>
<p>So why go through all this extra effort?<span id="more-562"></span> Basically there are two reasons.</p>
<p>1) allowing a person to customize and interchange their toy gives them an added sense of ownership, and taps into an emotional type of attachment.<br />
2) it is pretty easy to come up with a ways of taking the ideas behind this circuit, and give very young children the ability to construct abstract concepts such as flow. This in turn makes this simple interaction material a digital manipulative with extraordinary educational benefit.</p>
<p>One of my points of inspiration was <a href="http://llk.media.mit.edu/projects.php?id=136">MIT&#8217;s Mitchel Resnic&#8217;s Programmable Beads </a>, and other work with digital manipulative that I&#8217;ve spoken about <a href="http://blog.unthinkmedia.com/?p=228">on other posts</a>.</p>
<p>Onto phase 2&#8230;</p>
<p><object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/82UoO6F9wdM&#038;hl=en_US&#038;fs=1&#038;"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/82UoO6F9wdM&#038;hl=en_US&#038;fs=1&#038;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object></p>
<p>Here is a video of Mitch Resnick speaking about his Lifelong Kindergarten group at the MIT Media Lab</p>
<p><object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/pyvpz2aRH4o&#038;hl=en_US&#038;fs=1&#038;"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/pyvpz2aRH4o&#038;hl=en_US&#038;fs=1&#038;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object>
<div class='fb_like_button' style='padding-top:5px;padding-bottom:5px'><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fblog.unthinkmedia.com%2F2010%2F03%2F20%2Finitial-test-of-my-expandable-circuit%2F&#038;layout=standart&#038;show_faces=true&#038;width=450&#038;action=like&#038;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:65px;"></iframe></div>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Initial+Test+of+my+Expandable%2FInterchangeable+Circuit+http://bit.ly/aHgojj" title="Post to Twitter"><img class="nothumb" src="http://blog.unthinkmedia.com/wp-content/plugins/tweet-this/icons/tt-twitter-micro3.png" alt="Post to Twitter" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.unthinkmedia.com/2010/03/20/initial-test-of-my-expandable-circuit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Post TEDxNYED Thoughts</title>
		<link>http://blog.unthinkmedia.com/2010/03/07/post-tedxnyed-thoughts/</link>
		<comments>http://blog.unthinkmedia.com/2010/03/07/post-tedxnyed-thoughts/#comments</comments>
		<pubDate>Mon, 08 Mar 2010 04:11:44 +0000</pubDate>
		<dc:creator>Alex Britez</dc:creator>
				<category><![CDATA[Education]]></category>
		<category><![CDATA[conference]]></category>
		<category><![CDATA[TED]]></category>
		<category><![CDATA[TEDxNYED]]></category>

		<guid isPermaLink="false">http://blog.unthinkmedia.com/?p=538</guid>
		<description><![CDATA[This past Saturday, March 6th, I was given the opportunity to attend my first TEDx event.  I didn&#8217;t really know what to expect, I typically only  attend technical conferences filled with pocket protector wearing programmers. Okay we don&#8217;t wear pocket protectors, but that doesn&#8217;t make it any less of a complete geek fest, [...]]]></description>
			<content:encoded><![CDATA[<p><img alt="" src="http://creativecommons.org/wp-content/uploads/2009/12/tedxnyed.jpg" title="TEDxNYED" class="alignleft" width="282" height="61" />This past Saturday, March 6th, I was given the opportunity to attend my first TEDx event.  I didn&#8217;t really know what to expect, I typically only  attend technical conferences filled with pocket protector wearing programmers. Okay we don&#8217;t wear pocket protectors, but that doesn&#8217;t make it any less of a complete geek fest, me included.  Anyhow, to start, I must applaud the group of educators that ran the event.  The location was great, the line up of speakers was very good, and overall I had an amazing time.  However, there where a couple of suggestions, or maybe some preconceive expectations that I may have had prior to attending.</p>
<p>Although I believe that many of the speakers where amazing, at points I felt like i was at an educators pep rally.  Don&#8217;t get me wrong, it is always great to get other educators excited about certain topics, however much of what was being talked about is nothing new of innovative.  For instance, I think just about everyone knows that standardized testing is probably not the best way to assess students, but how could you successfully implement portfolio based assessments?  One speaker touched on it, however I really wanted more examples, more case studies. I basically wanted the speakers ideas, so I could tweak them start putting them into practice.  Most of the talks were powerful in there own way, I unfortunately didn&#8217;t quite get that &#8220;Ah ha!&#8221; moment that i was hoping for.<br />
<span id="more-538"></span><br />
The other critique that I had about the event was networking opportunities. Although, I am sure it is mostly my own fault for not pursuing enough conversation during the break, I feel like there must be a better way of creating connections of like minded or curious attendees.  Since i never like to give a critique without at least attempting to give some suggestions, I&#8217;ll take my best stab at the problem.</p>
<p>You asked each attendee to give you 3 topics that we where interested in.  Having them on our badge was a great idea, however the type was way too small, and it was nearly impossible to try and read those without looking like a complete weirdo. Maybe creating some sort of physical area in the space where we could gather and talk and network.  For example, take the top 4 topics of each session and plot them on 4 separate sides of the room. It is easy enough to print them out so why not have the topics be crowd sourced, and then quickly polled at the end of the session? &#8220;People interested in talking about educational reform for to the far left corner&#8221;. This sort of setting would have given me the opportunity not to walk in circles and go to the first person I saw in that area and say &#8220;SATs suck, any ideas on how to make assessment better?&#8221;</p>
<p>I would have also liked access to individuals twitter handles, along with their three topics posted on a board, or possibly even in the program itself. This way I could have just picked up my phone and tweet &#8220;@person I see you have X as your topic,  would you like to talk about Y at the next break?&#8221;</p>
<p>Just a couple of suggestion, from an attendee. Thanks again for an otherwise great event, I hope to attend many others in the future!<br />
<em><br />
<strong>Update:</strong> The people of TEDxNYED have released a public listing of all the attendees, along with interests and twitter information (<a href="http://tedxnyed.wikispaces.com/participants">http://tedxnyed.wikispaces.com/participants</a>)</p>
<p>This was great, I was able to communicate with some people post event via twitter. Would be great to offer this pre-event so I could have set up some networking time at the event with certain individuals that are working on similar projects that I am working on.</em>
<div class='fb_like_button' style='padding-top:5px;padding-bottom:5px'><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fblog.unthinkmedia.com%2F2010%2F03%2F07%2Fpost-tedxnyed-thoughts%2F&#038;layout=standart&#038;show_faces=true&#038;width=450&#038;action=like&#038;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:65px;"></iframe></div>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Post+TEDxNYED+Thoughts+http://bit.ly/97KFpF" title="Post to Twitter"><img class="nothumb" src="http://blog.unthinkmedia.com/wp-content/plugins/tweet-this/icons/tt-twitter-micro3.png" alt="Post to Twitter" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.unthinkmedia.com/2010/03/07/post-tedxnyed-thoughts/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Update Twitter Status w/ Arduino &amp; Processing</title>
		<link>http://blog.unthinkmedia.com/2010/02/26/update-twitter-status-w-arduino-processing/</link>
		<comments>http://blog.unthinkmedia.com/2010/02/26/update-twitter-status-w-arduino-processing/#comments</comments>
		<pubDate>Fri, 26 Feb 2010 15:55:30 +0000</pubDate>
		<dc:creator>Alex Britez</dc:creator>
				<category><![CDATA[Examples]]></category>
		<category><![CDATA[Physical Computing]]></category>
		<category><![CDATA[programing]]></category>
		<category><![CDATA[arduino]]></category>
		<category><![CDATA[physical computing]]></category>
		<category><![CDATA[source]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://blog.unthinkmedia.com/?p=520</guid>
		<description><![CDATA[The next phase of my project was to send the serial communication from my Arduino, over to Processing, which then would formulate a status update based on the button you pressed and send it over to Twitter.  I&#8217;ve worked with several Twitter API&#8217;s in the past, so I decided to go with Twitter4J, the [...]]]></description>
			<content:encoded><![CDATA[<p>The next phase of my project was to send the serial communication from my Arduino, over to Processing, which then would formulate a status update based on the button you pressed and send it over to Twitter.  I&#8217;ve worked with several Twitter API&#8217;s in the past, so I decided to go with <a href="http://twitter4j.org/en/index.html">Twitter4J</a>, the &#8220;J&#8221; in this case stands for Java, which works perfectly with Processing.</p>
<p><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/BY9ZiiQxXWU&#038;hl=en_US&#038;fs=1&#038;"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/BY9ZiiQxXWU&#038;hl=en_US&#038;fs=1&#038;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object></p>
<p>Bellow is an updated version of my previous Arduino coding. I plan on switching the status updating to the Processing side, instead of the Arduino side. If this where to be a real product, it would be easier to download a software update, then to have to reprogram the toy itself.  I will add that to my todo list, once i get all the major <span id="more-520"></span>functionality working.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// BUTTONS</span>
<span style="color: #993333;">const</span> <span style="color: #993333;">int</span> buttonGreen <span style="color: #339933;">=</span> <span style="color: #0000dd;">8</span><span style="color: #339933;">;</span>
<span style="color: #993333;">const</span> <span style="color: #993333;">int</span> buttonRed <span style="color: #339933;">=</span> <span style="color: #0000dd;">9</span><span style="color: #339933;">;</span>
<span style="color: #993333;">const</span> <span style="color: #993333;">int</span> buttonYellow <span style="color: #339933;">=</span> <span style="color: #0000dd;">10</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//LEDS</span>
<span style="color: #993333;">const</span> <span style="color: #993333;">int</span> ledGreen <span style="color: #339933;">=</span>  <span style="color: #0000dd;">2</span><span style="color: #339933;">;</span>
<span style="color: #993333;">const</span> <span style="color: #993333;">int</span> ledRed <span style="color: #339933;">=</span>  <span style="color: #0000dd;">3</span><span style="color: #339933;">;</span>
<span style="color: #993333;">const</span> <span style="color: #993333;">int</span> ledYellow <span style="color: #339933;">=</span>  <span style="color: #0000dd;">4</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//STORE BUTTON STATES</span>
<span style="color: #993333;">int</span> greenState <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #993333;">int</span> redState <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #993333;">int</span> yellowState <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">int</span> lastActiveLED <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Keep track of the activeLED</span>
&nbsp;
<span style="color: #993333;">void</span> setup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  Serial.<span style="color: #202020;">begin</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">9600</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  pinMode<span style="color: #009900;">&#40;</span>ledGreen<span style="color: #339933;">,</span> OUTPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  pinMode<span style="color: #009900;">&#40;</span>ledRed<span style="color: #339933;">,</span> OUTPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  pinMode<span style="color: #009900;">&#40;</span>ledYellow<span style="color: #339933;">,</span> OUTPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  pinMode<span style="color: #009900;">&#40;</span>buttonGreen<span style="color: #339933;">,</span> INPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
  pinMode<span style="color: #009900;">&#40;</span>buttonRed<span style="color: #339933;">,</span> INPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
  pinMode<span style="color: #009900;">&#40;</span>buttonYellow<span style="color: #339933;">,</span> INPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> loop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// CHECK BTN STATES</span>
  greenState <span style="color: #339933;">=</span> digitalRead<span style="color: #009900;">&#40;</span>buttonGreen<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  redState <span style="color: #339933;">=</span> digitalRead<span style="color: #009900;">&#40;</span>buttonRed<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  yellowState <span style="color: #339933;">=</span> digitalRead<span style="color: #009900;">&#40;</span>buttonYellow<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #808080; font-style: italic;">/**********
   *  Each of the following conditionals only sends one Serial message
   *  per button press
   **********/</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">//GREEN</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>greenState <span style="color: #339933;">==</span> HIGH<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #666666; font-style: italic;">//check if last active LED was not Green </span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>lastActiveLED <span style="color: #339933;">!=</span> ledGreen<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      <span style="color: #666666; font-style: italic;">//print the respective message for each button only once per mouse press. End message transmission with '10' which is linefeed.</span>
      Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;green&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">10</span><span style="color: #339933;">,</span> BYTE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>   
    <span style="color: #666666; font-style: italic;">//store green as last active press</span>
    lastActiveLED <span style="color: #339933;">=</span> ledGreen<span style="color: #339933;">;</span>
    digitalWrite<span style="color: #009900;">&#40;</span>ledGreen<span style="color: #339933;">,</span> HIGH<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span> 
  <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">//clear out last active so you could reclick it</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>lastActiveLED <span style="color: #339933;">==</span> ledGreen<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      lastActiveLED <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    digitalWrite<span style="color: #009900;">&#40;</span>ledGreen<span style="color: #339933;">,</span> LOW<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    delay<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">100</span><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;">//RED</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>redState <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>lastActiveLED <span style="color: #339933;">!=</span> ledRed<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;red&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">10</span><span style="color: #339933;">,</span> BYTE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>   
    lastActiveLED <span style="color: #339933;">=</span> ledRed<span style="color: #339933;">;</span>
    digitalWrite<span style="color: #009900;">&#40;</span>ledRed<span style="color: #339933;">,</span> HIGH<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    delay<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">100</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span> 
  <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>lastActiveLED <span style="color: #339933;">==</span> ledRed<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      lastActiveLED <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    digitalWrite<span style="color: #009900;">&#40;</span>ledRed<span style="color: #339933;">,</span> LOW<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;">//YELLOW</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>yellowState <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>lastActiveLED <span style="color: #339933;">!=</span> ledYellow<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;yellow&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">10</span><span style="color: #339933;">,</span> BYTE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>   
    lastActiveLED <span style="color: #339933;">=</span> ledYellow<span style="color: #339933;">;</span>
    digitalWrite<span style="color: #009900;">&#40;</span>ledYellow<span style="color: #339933;">,</span> HIGH<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    delay<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">100</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span> 
  <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>lastActiveLED <span style="color: #339933;">==</span> ledYellow<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      lastActiveLED <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    digitalWrite<span style="color: #009900;">&#40;</span>ledYellow<span style="color: #339933;">,</span> LOW<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Now that we are sending message, we need to listen.  I decided to go with Processing since I&#8217;ve always been curious about it, and it is about as seamless of a coding experience as you could possibly get with Arduino.</p>
<p>In order to get the Twitter4J Java Library working you first needed to drag the .jar file directly onto your Processing sketch, and that is pretty much it. Bellow is the Processing code that simply listens for a Serial Event (Arduino button press), and then sends the status message over to Twitter.</p>
<p>Being a total N00bie to Processing, one additional tip that confused me was Fonts. Processing doesn&#8217;t allow True Type Fonts, so if you want to add text to your project you need to go to:</p>
<p>Tools > Create Fonts&#8230;  </p>
<p>and then select the font you would like to use. The Processing IDE then converts the font to a .vlw file. You could find the file in a folder named &#8216;data&#8217; that gets created within your projected folder.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/*************
*    based on:  http://processing.org/reference/libraries/serial/serialEvent_.html
*************/</span>
&nbsp;
import processing.<span style="color: #202020;">serial</span>.<span style="color: #339933;">*;</span> 
&nbsp;
Serial myPort<span style="color: #339933;">;</span>    <span style="color: #666666; font-style: italic;">// The serial port </span>
PFont myFont<span style="color: #339933;">;</span>     <span style="color: #666666; font-style: italic;">// The display font </span>
String inString<span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">// Input string from serial port </span>
<span style="color: #993333;">int</span> lf <span style="color: #339933;">=</span> <span style="color: #0000dd;">10</span><span style="color: #339933;">;</span>      <span style="color: #666666; font-style: italic;">// ASCII linefeed </span>
&nbsp;
Twitter twitter<span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">// Twitter</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//Going to get oAuth working instead of this, but this will do for now</span>
String username <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;YOUR-TWITTER-USERNAME&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// you Twitter Username Here</span>
String password <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;YOUR-TWITTER-PASSWORD&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// your Twitter Password Here</span>
&nbsp;
<span style="color: #993333;">void</span> setup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
  size<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">400</span><span style="color: #339933;">,</span><span style="color: #0000dd;">200</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  twitter <span style="color: #339933;">=</span> new Twitter<span style="color: #009900;">&#40;</span>username<span style="color: #339933;">,</span>password<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  myFont <span style="color: #339933;">=</span> loadFont<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;AppleGothic-48.vlw&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
  textFont<span style="color: #009900;">&#40;</span>myFont<span style="color: #339933;">,</span> <span style="color: #0000dd;">18</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
  println<span style="color: #009900;">&#40;</span>Serial.<span style="color: #202020;">list</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
  myPort <span style="color: #339933;">=</span> new Serial<span style="color: #009900;">&#40;</span>this<span style="color: #339933;">,</span> Serial.<span style="color: #202020;">list</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">9600</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
  myPort.<span style="color: #202020;">bufferUntil</span><span style="color: #009900;">&#40;</span>lf<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//wiat for line feed to specify end of serial buffer</span>
<span style="color: #009900;">&#125;</span> 
&nbsp;
<span style="color: #993333;">void</span> draw<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
  background<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">100</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
  text<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;color selected: &quot;</span> <span style="color: #339933;">+</span> inString<span style="color: #339933;">,</span> <span style="color: #0000dd;">10</span><span style="color: #339933;">,</span><span style="color: #0000dd;">50</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #009900;">&#125;</span> 
&nbsp;
<span style="color: #993333;">void</span> serialEvent<span style="color: #009900;">&#40;</span>Serial p<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  inString <span style="color: #339933;">=</span> p.<span style="color: #202020;">readString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//read serial string</span>
  <span style="color: #666666; font-style: italic;">//For some reason this only wanted to work in a try catch</span>
  try
  <span style="color: #009900;">&#123;</span>
    Status status1 <span style="color: #339933;">=</span> twitter.<span style="color: #202020;">updateStatus</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Arduino's favorite color is &quot;</span><span style="color: #339933;">+</span>inString<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//update twitter status</span>
  <span style="color: #009900;">&#125;</span>
  catch<span style="color: #009900;">&#40;</span> TwitterException e<span style="color: #009900;">&#41;</span>  <span style="color: #009900;">&#123;</span>
    println<span style="color: #009900;">&#40;</span>e.<span style="color: #202020;">getStatusCode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<div class='fb_like_button' style='padding-top:5px;padding-bottom:5px'><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fblog.unthinkmedia.com%2F2010%2F02%2F26%2Fupdate-twitter-status-w-arduino-processing%2F&#038;layout=standart&#038;show_faces=true&#038;width=450&#038;action=like&#038;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:65px;"></iframe></div>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Update+Twitter+Status+w%2F+Arduino+%26+Processing+http://bit.ly/9RgNkb" title="Post to Twitter"><img class="nothumb" src="http://blog.unthinkmedia.com/wp-content/plugins/tweet-this/icons/tt-twitter-micro3.png" alt="Post to Twitter" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.unthinkmedia.com/2010/02/26/update-twitter-status-w-arduino-processing/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Arduino: Print a Single Serial Message per Button Press</title>
		<link>http://blog.unthinkmedia.com/2010/02/24/arduino-print-a-single-serial-message-per-button-press/</link>
		<comments>http://blog.unthinkmedia.com/2010/02/24/arduino-print-a-single-serial-message-per-button-press/#comments</comments>
		<pubDate>Thu, 25 Feb 2010 06:16:37 +0000</pubDate>
		<dc:creator>Alex Britez</dc:creator>
				<category><![CDATA[Examples]]></category>
		<category><![CDATA[Physical Computing]]></category>
		<category><![CDATA[programing]]></category>
		<category><![CDATA[arduino]]></category>
		<category><![CDATA[source]]></category>

		<guid isPermaLink="false">http://blog.unthinkmedia.com/?p=512</guid>
		<description><![CDATA[So I&#8217;ve been working on a new project and have run into a bit of an issue.  I plan to send a serial message over to Processing, however it very important that I don&#8217;t send multiple values stating the same button press.  Since Arduino is in a constant loop state, when i press [...]]]></description>
			<content:encoded><![CDATA[<p>So I&#8217;ve been working on a new project and have run into a bit of an issue.  I plan to send a serial message over to Processing, however it very important that I don&#8217;t send multiple values stating the same button press.  Since Arduino is in a constant loop state, when i press a button using something like:<br />
<span id="more-512"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// BUTTONS</span>
<span style="color: #993333;">const</span> <span style="color: #993333;">int</span> buttonGreen <span style="color: #339933;">=</span> <span style="color: #0000dd;">8</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//LEDS</span>
<span style="color: #993333;">const</span> <span style="color: #993333;">int</span> ledGreen <span style="color: #339933;">=</span>  <span style="color: #0000dd;">2</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//STORE BUTTON STATES</span>
<span style="color: #993333;">int</span> greenState <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #993333;">void</span> setup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  Serial.<span style="color: #202020;">begin</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">9600</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  pinMode<span style="color: #009900;">&#40;</span>ledGreen<span style="color: #339933;">,</span> OUTPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  pinMode<span style="color: #009900;">&#40;</span>buttonGreen<span style="color: #339933;">,</span> INPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> loop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// CHECK BTN STATES</span>
  greenState <span style="color: #339933;">=</span> digitalRead<span style="color: #009900;">&#40;</span>buttonGreen<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">//GREEN</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>greenState <span style="color: #339933;">==</span> HIGH<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span>ledGreen<span style="color: #339933;">,</span> DEC<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    digitalWrite<span style="color: #009900;">&#40;</span>ledGreen<span style="color: #339933;">,</span> HIGH<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>
    digitalWrite<span style="color: #009900;">&#40;</span>ledGreen<span style="color: #339933;">,</span> LOW<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
  <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>When i check my serial monitor I receive something like:<br />
22222222222222222222222222&#8230;..</p>
<p>That won&#8217;t work, since I plan for each of the Serial events to make an API call to Twitter. This activity would wipe out my allotted request in a matter of a couple of clicks, and probably would result in getting my account suspended due to unusual activity. So bellow is a quick fix which store individual button clicks, and prints out the Serial output once. I also decided against using any delays, since that may have potentially ended up in ignoring a button press.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// BUTTONS</span>
<span style="color: #993333;">const</span> <span style="color: #993333;">int</span> buttonGreen <span style="color: #339933;">=</span> <span style="color: #0000dd;">8</span><span style="color: #339933;">;</span>
<span style="color: #993333;">const</span> <span style="color: #993333;">int</span> buttonRed <span style="color: #339933;">=</span> <span style="color: #0000dd;">9</span><span style="color: #339933;">;</span>
<span style="color: #993333;">const</span> <span style="color: #993333;">int</span> buttonYellow <span style="color: #339933;">=</span> <span style="color: #0000dd;">10</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//LEDS</span>
<span style="color: #993333;">const</span> <span style="color: #993333;">int</span> ledGreen <span style="color: #339933;">=</span>  <span style="color: #0000dd;">2</span><span style="color: #339933;">;</span>
<span style="color: #993333;">const</span> <span style="color: #993333;">int</span> ledRed <span style="color: #339933;">=</span>  <span style="color: #0000dd;">3</span><span style="color: #339933;">;</span>
<span style="color: #993333;">const</span> <span style="color: #993333;">int</span> ledYellow <span style="color: #339933;">=</span>  <span style="color: #0000dd;">4</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//STORE BUTTON STATES</span>
<span style="color: #993333;">int</span> greenState <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #993333;">int</span> redState <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #993333;">int</span> yellowState <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #993333;">int</span> lastActiveLED <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Keep track of the activeLED</span>
&nbsp;
<span style="color: #993333;">void</span> setup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  Serial.<span style="color: #202020;">begin</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">9600</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  pinMode<span style="color: #009900;">&#40;</span>ledGreen<span style="color: #339933;">,</span> OUTPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  pinMode<span style="color: #009900;">&#40;</span>ledRed<span style="color: #339933;">,</span> OUTPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  pinMode<span style="color: #009900;">&#40;</span>ledYellow<span style="color: #339933;">,</span> OUTPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  pinMode<span style="color: #009900;">&#40;</span>buttonGreen<span style="color: #339933;">,</span> INPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
  pinMode<span style="color: #009900;">&#40;</span>buttonRed<span style="color: #339933;">,</span> INPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
  pinMode<span style="color: #009900;">&#40;</span>buttonYellow<span style="color: #339933;">,</span> INPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> loop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// CHECK BTN STATES</span>
  greenState <span style="color: #339933;">=</span> digitalRead<span style="color: #009900;">&#40;</span>buttonGreen<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  redState <span style="color: #339933;">=</span> digitalRead<span style="color: #009900;">&#40;</span>buttonRed<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  yellowState <span style="color: #339933;">=</span> digitalRead<span style="color: #009900;">&#40;</span>buttonYellow<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #808080; font-style: italic;">/**********
   *  Each of the following conditionals only sends one Serial message
   *  per button press
   **********/</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">//GREEN</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>greenState <span style="color: #339933;">==</span> HIGH<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #666666; font-style: italic;">//check if last active LED was not Green </span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>lastActiveLED <span style="color: #339933;">!=</span> ledGreen<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      <span style="color: #666666; font-style: italic;">//print Green since it is a new press</span>
      Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span>ledGreen<span style="color: #339933;">,</span> DEC<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>   
    <span style="color: #666666; font-style: italic;">//store green as last active press</span>
    lastActiveLED <span style="color: #339933;">=</span> ledGreen<span style="color: #339933;">;</span>
    digitalWrite<span style="color: #009900;">&#40;</span>ledGreen<span style="color: #339933;">,</span> HIGH<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span> 
  <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">//clear out last active so you could reclick it</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>lastActiveLED <span style="color: #339933;">==</span> ledGreen<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      lastActiveLED <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    digitalWrite<span style="color: #009900;">&#40;</span>ledGreen<span style="color: #339933;">,</span> LOW<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;">//RED</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>redState <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>lastActiveLED <span style="color: #339933;">!=</span> ledRed<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span>ledRed<span style="color: #339933;">,</span> DEC<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>   
    lastActiveLED <span style="color: #339933;">=</span> ledRed<span style="color: #339933;">;</span>
    digitalWrite<span style="color: #009900;">&#40;</span>ledRed<span style="color: #339933;">,</span> HIGH<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    delay<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">100</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span> 
  <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>lastActiveLED <span style="color: #339933;">==</span> ledRed<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      lastActiveLED <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    digitalWrite<span style="color: #009900;">&#40;</span>ledRed<span style="color: #339933;">,</span> LOW<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;">//YELLOW</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>yellowState <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>lastActiveLED <span style="color: #339933;">!=</span> ledYellow<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span>ledYellow<span style="color: #339933;">,</span> DEC<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>   
    lastActiveLED <span style="color: #339933;">=</span> ledYellow<span style="color: #339933;">;</span>
    digitalWrite<span style="color: #009900;">&#40;</span>ledYellow<span style="color: #339933;">,</span> HIGH<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    delay<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">100</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span> 
  <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>lastActiveLED <span style="color: #339933;">==</span> ledYellow<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      lastActiveLED <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    digitalWrite<span style="color: #009900;">&#40;</span>ledYellow<span style="color: #339933;">,</span> LOW<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>If anyone knows of any other methods of doing this, let me know!
<div class='fb_like_button' style='padding-top:5px;padding-bottom:5px'><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fblog.unthinkmedia.com%2F2010%2F02%2F24%2Farduino-print-a-single-serial-message-per-button-press%2F&#038;layout=standart&#038;show_faces=true&#038;width=450&#038;action=like&#038;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:65px;"></iframe></div>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Arduino%3A+Print+a+Single+Serial+Message+per+Button+Press+http://bit.ly/cdpNGr" title="Post to Twitter"><img class="nothumb" src="http://blog.unthinkmedia.com/wp-content/plugins/tweet-this/icons/tt-twitter-micro3.png" alt="Post to Twitter" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.unthinkmedia.com/2010/02/24/arduino-print-a-single-serial-message-per-button-press/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
