<?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 &#187; Examples</title>
	<atom:link href="http://blog.unthinkmedia.com/category/examples/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.unthinkmedia.com</link>
	<description>creativity + technology</description>
	<lastBuildDate>Wed, 11 Jan 2012 22:20:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Playing with &#8220;Game Feel&#8221;</title>
		<link>http://blog.unthinkmedia.com/2011/09/13/playing-with-game-feel/</link>
		<comments>http://blog.unthinkmedia.com/2011/09/13/playing-with-game-feel/#comments</comments>
		<pubDate>Tue, 13 Sep 2011 16:42:41 +0000</pubDate>
		<dc:creator>Alex Britez</dc:creator>
				<category><![CDATA[Examples]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[Research]]></category>
		<category><![CDATA[Unity3d]]></category>

		<guid isPermaLink="false">http://blog.unthinkmedia.com/?p=1166</guid>
		<description><![CDATA[I am currently taking on the dual task of researching &#8220;game feel&#8221; for a Game Modding class at NYU&#8217;s Game Center, and teaching myself Unity3d. As part of my course work, we have been asked to read &#8220;Game Feel: A Game Designer&#8217;s Guide to Virtual Sensation&#8221;. In this book, the author talks about 3 specific [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.amazon.com/gp/product/0123743281/ref=as_li_ss_il?ie=UTF8&#038;tag=unthinkmedia-20&#038;linkCode=as2&#038;camp=217145&#038;creative=399369&#038;creativeASIN=0123743281"><img border="0" src="http://ws.assoc-amazon.com/widgets/q?_encoding=UTF8&#038;Format=_SL160_&#038;ASIN=0123743281&#038;MarketPlace=US&#038;ID=AsinImage&#038;WS=1&#038;tag=unthinkmedia-20&#038;ServiceVersion=20070822" style="float:right;padding:10px;"></a> I am currently taking on the dual task of researching &#8220;game feel&#8221; for a Game Modding class at NYU&#8217;s Game Center,  and teaching myself <a href="http://www.unity3d.com">Unity3d</a>. As part of my course work, we have been asked to read &#8220;Game Feel: A Game Designer&#8217;s Guide to Virtual Sensation&#8221;. </p>
<p>In this book, the author talks about 3 specific areas that effect the &#8220;feel&#8221; of a game. He describes feel as being, &#8220;Real-time control of virtual objects in a simulated space, with interactions emphasized by polish&#8221;.</p>
<p><strong>Real-Time Control</strong><br />
This is comprised of a interactivity between at least tow participants.  Each participant actively communicates with each other though a combination of input and output feedback.  Bellow, Swink describes this process as it pertains to computer games and their participants.</p>
<blockquote><p>The user has some intent, which is expressed to the computer in the form of the user’s input. The computer reconciles this input with its own internal model and outputs the results. The user then perceives the changes, thinks about how they compare to the original intent, and formulates a new action, which is expressed to the computer through another input.</p></blockquote>
<p><strong>Simulated Spaces</strong><br />
These are are comprised of physical interaction that take place in a virtual space.  Through the use of level design, collision detection, and physics, the game designer is able to give meaning to the games movement.  The surrounding visuals offer a frame of reference for the player to  get the impression of speed. &#8220;Using the avatar as a channel for expression and perception, we experience game worlds at the tactile, physical level of the world around us.&#8221;</p>
<p><strong>Polish</strong><br />
Polish is comprised of all this tiny details that &#8220;artificially enhance&#8221; a players interaction without changing any of the games core functionality. Examples of these could be dust particles on ground, sound effects, camera shakes.  These effects, add the games overall appeal and allow for the game to seem more &#8220;real&#8221;.<br />
<span id="more-1166"></span><br />
Bellow is a quick exercise that I coded taking some of the concepts that Steve Swink speaks about in his first chapter.  There is no goal in this simulation, just wanted to see if I could evoke a feeling while i walked around.</p>
<p><strong>First Person Shooter using Unity 3d</strong><br />
The controls are:</p>
<ul>
<li>move: A,S,W,D keys</li>
<li>jump: Space</li>
<li>head movement : Mouse</li>
<li>shoot: Right Mouse Click</li>
<li>fullscreen: Left Mouse Click > Go Fullscreen</li>
</ul>
<p><em>Please view the full post to see the Unity content.</em></p>
<p>In this exercise I spent most of my time on the &#8220;polish&#8221;, mainly because it allowed me to learn how to code small details that help in adding to a user&#8217;s immersion.  Some of these include a far from refined particle effect when you shoot the terrain, slight head bobbing motion when your avatar runs, and some ambiant noise and background music to further capture a &#8220;feeling&#8221;. Obviously there are loads of other effects that  I could add to this experiment, but I think it helped me get a better understanding of what Steve Swink was getting at in his chapter.</p>
<p>In a Gamastra article called &#8220;<a href="http://www.gamasutra.com/view/news/31072/QA_Kaos_On_Homefront_Imp">Q&#038;A: Kaos On Homefront, Importance Of &#8216;Authenticity&#8217; In Online Shooters</a>&#8220;, when asked about the story element of <a href="http://www.homefront-game.com/">Homefront</a>, they noted that there aren&#8217;t traditional cut scenes, just some backstory, and in game narrative:</p>
<blockquote><p>We&#8217;re not doing any kind of cut scenes or anything like that; it&#8217;s really about the atmosphere and the ambiance&#8230; I think it&#8217;s just up to us to really accentuate the atmospheric elements that really help create that fun experience for the player that feels different and feels unique.</p></blockquote>
<p><strong> Reference:</strong><br />
Swink, Steve (2008-10-13). Game Feel: A Game Designer&#8217;s Guide to Virtual Sensation (Morgan Kaufmann Game Design Books). Morgan Kaufmann. Kindle Edition.
<div class='kouguu_fb_like_button'><iframe src="http://www.facebook.com/plugins/like.php?href=http://blog.unthinkmedia.com/2011/09/13/playing-with-game-feel/&#038;layout=standart&#038;show_faces=true&#038;width=450&#038;height=65&#038;action=like&#038;colorscheme=light&#038;" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:65px;"></iframe></div>
<img src="http://blog.unthinkmedia.com/?ak_action=api_record_view&id=1166&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blog.unthinkmedia.com/2011/09/13/playing-with-game-feel/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Prototyping a Networked Family</title>
		<link>http://blog.unthinkmedia.com/2010/09/27/prototyping-a-networked-family/</link>
		<comments>http://blog.unthinkmedia.com/2010/09/27/prototyping-a-networked-family/#comments</comments>
		<pubDate>Mon, 27 Sep 2010 16:40:50 +0000</pubDate>
		<dc:creator>Alex Britez</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Education]]></category>
		<category><![CDATA[Examples]]></category>
		<category><![CDATA[Physical Computing]]></category>
		<category><![CDATA[project]]></category>
		<category><![CDATA[Social Media]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[arduino]]></category>
		<category><![CDATA[electronics]]></category>
		<category><![CDATA[learning]]></category>
		<category><![CDATA[product design]]></category>
		<category><![CDATA[toy]]></category>

		<guid isPermaLink="false">http://blog.unthinkmedia.com/?p=762</guid>
		<description><![CDATA[Being a first time dad has been the most amazing experience of my life. Watching my daughter grow, and witnessing her constant exploration of the world around her has been extraordinary. Unfortunately when Mondays roll around, it is time for me and many other parents to drop off our kids at the babysitter.  The amount [...]]]></description>
			<content:encoded><![CDATA[<p>Being a first time dad has been the most amazing experience of my life. Watching my daughter grow, and witnessing her constant exploration of the world around her has been extraordinary. Unfortunately when Mondays roll around, it is time for me and many other parents to drop off our kids at the babysitter.  The amount of time we get to interact with each other is very minimal, and pretty sad.</p>
<p>In a world where we all feel so &#8220;connected&#8221;, the people that matter most have no method of remotely interacting with us.  My 1 1/2 year has no twitter, or Facebook account to update.  She doesn&#8217;t check into fourSquare every time we go to grandma&#8217;s house. Even with mobile phones and Skype video conferencing, there is no direct method of me interacting with her without the assistance and supervision of an adult.  So basically, we could only interact with each other when another adult has both the time and is willing to put in the effort to set up an environment for us to communicate.</p>
<p>This got me thinking &#8220;how can my daughter and I interact during my work hours?&#8221;  The first thing I did was identify the main characteristics of my daughter, back when I first started working on this project:</p>
<ul>
<li>My daughter was one year old.</li>
<li>Her vocal communication ability was in the preliminary stages of development</li>
<li>Her motor skills where still not fully developed, so complex tasks like using a keyboard or mouse where not possible.</li>
<li>She needs adult assistance to use our everyday communication tools that available to us (moble and land-line phones, computers, etc).</li>
</ul>
<p>At this young age, children are extremely dependent on their parents and other adults for just about everything.  However, there are also several activities that come as naturally as breathing and eating to a child. Two of those activities that i observed where exploration and play, many times triggered by a common catalyst of curiosity.</p>
<p>Children gradually explore their environment and toys and interacted with them, mastering the new skills that they learn along the way.  Quickly they are able to identify all sorts of toy input locations which triggered various types of output, such as audio and visual feedback.<br />
<span id="more-762"></span><br />
Many people are quick to suggest that we need to expose children to computers at an early age, I don&#8217;t disagree.  However, there is no reason that we need to take a child to a some cold desk, when where they are already in-front of their toy box. Why not instead bring the computer to them, in their own natural environment, and make them available on their own terms.  Computers come in various shapes and sizes, and are all around us. In washing machines, toasters, and most of the objects we interact with on a daily basis have them.  Just look around you right now, I&#8217;m sure you would be surprised on the amount of digital technology that is surrounding you at this moment.</p>
<p>Digital toys, and interactive plush dolls are nothing new. Companies suck as Leap Frog have thrived on making toys which have been getting smarter and smarter. With the introduction of micro-controllers embedded deep inside their soft cuddly exterior, there are endless possibilities.  So that was my answer, I would prototype a interactive based toy solution, that both an adult and child could easily use to communicate with each other.  It is too easy to go into fantasy land with a project like this, so here were my self-imposed rules:</p>
<ol>
<li>The toy must not cost more then $39 retail, since that is my personal breaking point for interactive toys.</li>
<li>It must work anywhere, and not be totally dependent on a network connection.</li>
<li>The child must need zero guidance to interact with the toy.</li>
<li>The toy must promote exploration</li>
<li>There must be some learning activities.</li>
<li>I must be able to interact with the toy from my office</li>
</ol>
<h3>Putting it all Together</h3>
<p>I knew that I would like a toy that enabled &#8220;me&#8221; to interact with my child via audio or video, however I started seeing that as an obvious solution and not very cost of effective.  Why should parents be forced to buy individual toys for each person that would like to interact with the child?  My daughter has a mother, aunts, grandparents, etc. Would it be feasible of me buying one for each person?  More importantly, would the child be able to interact with such a fragmented family of toys at such an early age? What would be the total cost, $39 a piece? That is pretty steep, and won&#8217;t work as a solution in my opinion.  Taking all these questions into account gave me my &#8220;ah-ha&#8221; moment.  My family and I are part of my daughter&#8217;s social network, as exclusive as it may be. Looking at the toy as a social network would mean incorporating several functions that a typical social network would have.  I decided that the most important social network functions that my toy should support where:</p>
<ul>
<li>Avatars</li>
<li>Buddy List</li>
<li>Messaging</li>
</ul>
<h3>The Birth of my ChatterPillar</h3>
<p>I decided to go with a completely modular design, so I could play off the metaphor of a family unit.  One unit, one toy, multiple facets. Each facet containing unique actions associated to that family member.  The modular design would also allow me to add and remove modules as I please.  This allows my toy to take a very literal approach to a buddy list.  If you wanted to add a buddy you would have to physically add your buddy to the toy and vice-versa.  It also allowed for an interesting business model, add all the costly circuitry in the head (the brain) and allow for less expensive body modules to take advantage of the brains powersupply, and various other components like speakers, memory, etc.  This along with some inner circuit  communication was all i needed to create the beginnings of what turned out to be myChatterPillar.  Bellow is a video showing my initial alpha prototype of myChatterPillar in action.</p>
<p><object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/B1j7UKRttgg?fs=1&amp;hl=en_US"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/B1j7UKRttgg?fs=1&amp;hl=en_US" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object></p>
<h3>Main Features</h3>
<p>My ChatterPillar has several features that have been incorporated into the design.  </p>
<ol>
<li>There is a photo sleeve on each of the detachable modules which serve as an avatar.</li>
<li>There are 3 audio switches. The one beneath the photo is to identify the family member, and the two on the legs is for adding any other audio, like messages, song, etc.  These audio buckets are created online by the adult via a accompanying web site, and the files are later synced to the toy via a tethered USB connection.</li>
<li>Adults could remotely communicate with the toy and send messages to it via familiar technology such as email, twitter and SMS</li>
<li>Embeded assessments to test the child&#8217;s familiarity with their family and colors.</li>
</ol>
<h3>Where to go from here</h3>
<p>My next steps are to take this toy out of it&#8217;s bread board stage, and into a more complete embodiment.  I initially looked at this project as a method of communicating with my daughter, but would be great to get it out there some day so other families could also enjoy interacting with their young children.  To be continued&#8230;.
<div class='kouguu_fb_like_button'><iframe src="http://www.facebook.com/plugins/like.php?href=http://blog.unthinkmedia.com/2010/09/27/prototyping-a-networked-family/&#038;layout=standart&#038;show_faces=true&#038;width=450&#038;height=65&#038;action=like&#038;colorscheme=light&#038;" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:65px;"></iframe></div>
<img src="http://blog.unthinkmedia.com/?ak_action=api_record_view&id=762&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blog.unthinkmedia.com/2010/09/27/prototyping-a-networked-family/feed/</wfw:commentRss>
		<slash:comments>4</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[Examples]]></category>
		<category><![CDATA[Flex/Flash]]></category>
		<category><![CDATA[programing]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[Flex]]></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 issue i [...]]]></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='kouguu_fb_like_button'><iframe src="http://www.facebook.com/plugins/like.php?href=http://blog.unthinkmedia.com/2010/08/18/handeling-external-swf-events-in-flex-using-swfloader/&#038;layout=standart&#038;show_faces=true&#038;width=450&#038;height=65&#038;action=like&#038;colorscheme=light&#038;" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:65px;"></iframe></div>
<img src="http://blog.unthinkmedia.com/?ak_action=api_record_view&id=729&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blog.unthinkmedia.com/2010/08/18/handeling-external-swf-events-in-flex-using-swfloader/feed/</wfw:commentRss>
		<slash:comments>6</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, and [...]]]></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='kouguu_fb_like_button'><iframe src="http://www.facebook.com/plugins/like.php?href=http://blog.unthinkmedia.com/2010/05/05/multi-master-arduino-setup-using-i2c/&#038;layout=standart&#038;show_faces=true&#038;width=450&#038;height=65&#038;action=like&#038;colorscheme=light&#038;" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:65px;"></iframe></div>
<img src="http://blog.unthinkmedia.com/?ak_action=api_record_view&id=678&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blog.unthinkmedia.com/2010/05/05/multi-master-arduino-setup-using-i2c/feed/</wfw:commentRss>
		<slash:comments>1</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[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 my [...]]]></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='kouguu_fb_like_button'><iframe src="http://www.facebook.com/plugins/like.php?href=http://blog.unthinkmedia.com/2010/03/20/initial-test-of-my-expandable-circuit/&#038;layout=standart&#038;show_faces=true&#038;width=450&#038;height=65&#038;action=like&#038;colorscheme=light&#038;" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:65px;"></iframe></div>
<img src="http://blog.unthinkmedia.com/?ak_action=api_record_view&id=562&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blog.unthinkmedia.com/2010/03/20/initial-test-of-my-expandable-circuit/feed/</wfw:commentRss>
		<slash:comments>1</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 &#8220;J&#8221; [...]]]></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='kouguu_fb_like_button'><iframe src="http://www.facebook.com/plugins/like.php?href=http://blog.unthinkmedia.com/2010/02/26/update-twitter-status-w-arduino-processing/&#038;layout=standart&#038;show_faces=true&#038;width=450&#038;height=65&#038;action=like&#038;colorscheme=light&#038;" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:65px;"></iframe></div>
<img src="http://blog.unthinkmedia.com/?ak_action=api_record_view&id=520&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blog.unthinkmedia.com/2010/02/26/update-twitter-status-w-arduino-processing/feed/</wfw:commentRss>
		<slash:comments>8</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 a button [...]]]></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='kouguu_fb_like_button'><iframe src="http://www.facebook.com/plugins/like.php?href=http://blog.unthinkmedia.com/2010/02/24/arduino-print-a-single-serial-message-per-button-press/&#038;layout=standart&#038;show_faces=true&#038;width=450&#038;height=65&#038;action=like&#038;colorscheme=light&#038;" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:65px;"></iframe></div>
<img src="http://blog.unthinkmedia.com/?ak_action=api_record_view&id=512&type=feed" alt="" />]]></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>
		<item>
		<title>DIY Simon with Arduino w/ Source and Diagram</title>
		<link>http://blog.unthinkmedia.com/2010/02/09/diy-simon-with-arduino-w-source-and-diagram/</link>
		<comments>http://blog.unthinkmedia.com/2010/02/09/diy-simon-with-arduino-w-source-and-diagram/#comments</comments>
		<pubDate>Wed, 10 Feb 2010 06:03:14 +0000</pubDate>
		<dc:creator>Alex Britez</dc:creator>
				<category><![CDATA[Examples]]></category>
		<category><![CDATA[Physical Computing]]></category>
		<category><![CDATA[project]]></category>
		<category><![CDATA[arduino]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[electronics]]></category>
		<category><![CDATA[source]]></category>

		<guid isPermaLink="false">http://blog.unthinkmedia.com/?p=475</guid>
		<description><![CDATA[So i finally had time to tinker around with this Simon Sez project again. Turns out there wasn&#8217;t an issue after all with my circuits, it was an issue in my code. I also did some house keeping on the code, and created a nice little diagram using Fritzing, an awesome app that was recommend [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.unthinkmedia.com/wp-content/uploads/Simon_bb.jpg"><img src="http://blog.unthinkmedia.com/wp-content/uploads/Simon_bb-300x121.jpg" alt="" title="Simon_bb" width="300" height="121" class="alignright size-medium wp-image-476" /></a><br />
So i finally had time to tinker around with this Simon Sez project again. Turns out there wasn&#8217;t an issue after all with my circuits, it was an issue in my code.  I also did some house keeping on the code, and created a nice little diagram using <a href="http://fritzing.org/">Fritzing</a>, an awesome app that was recommend to our class <span id="more-475"></span> by <a href="http://www.tigoe.net/">Tom Igoe</a>.</p>
<p>I tried to keep both programming and circuitry as slim as I could, and I think that worked out pretty well.  Not sure if i will add anything else to this, but if anyone has any ideas, asides from my <a href="http://twitter.com/orian/status/8828061476">coworker&#8217;s recent tweet</a>, then Iet me know.</p>
<p><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/9IbpiVJKoPU&#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/9IbpiVJKoPU&#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>This source 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
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"> <span style="color: #808080; font-style: italic;">/*
   Simon Sez
&nbsp;
&nbsp;
  created Feb 10 2010
  by Alex Britez
&nbsp;
  http://blog.unthinkmedia.com/?p=475
&nbsp;
  */</span>
&nbsp;
<span style="color: #339933;">#include &lt;Tone.h&gt;</span>
&nbsp;
Tone audioFeedback<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//DEFINE MOTOR</span>
<span style="color: #993333;">int</span> transistorPin <span style="color: #339933;">=</span> <span style="color: #0000dd;">12</span><span style="color: #339933;">;</span> 
&nbsp;
<span style="color: #993333;">int</span> speakerPin <span style="color: #339933;">=</span> <span style="color: #0000dd;">6</span><span style="color: #339933;">;</span> 
&nbsp;
<span style="color: #666666; font-style: italic;">//DEFINE LEDS</span>
<span style="color: #993333;">int</span> ledWhite <span style="color: #339933;">=</span> <span style="color: #0000dd;">11</span><span style="color: #339933;">;</span>
<span style="color: #993333;">int</span> ledGreen <span style="color: #339933;">=</span> <span style="color: #0000dd;">10</span><span style="color: #339933;">;</span>
<span style="color: #993333;">int</span> ledRed <span style="color: #339933;">=</span> <span style="color: #0000dd;">9</span><span style="color: #339933;">;</span>
<span style="color: #993333;">int</span> ledYellow <span style="color: #339933;">=</span> <span style="color: #0000dd;">8</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">char</span> leds<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
  ledWhite<span style="color: #339933;">,</span>ledGreen<span style="color: #339933;">,</span>ledRed<span style="color: #339933;">,</span>ledYellow<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//DEFINE SWITCHES </span>
<span style="color: #993333;">int</span> switchWhite <span style="color: #339933;">=</span> <span style="color: #0000dd;">5</span><span style="color: #339933;">;</span>
<span style="color: #993333;">int</span> switchGreen <span style="color: #339933;">=</span> <span style="color: #0000dd;">4</span><span style="color: #339933;">;</span>
<span style="color: #993333;">int</span> switchRed <span style="color: #339933;">=</span> <span style="color: #0000dd;">3</span><span style="color: #339933;">;</span>
<span style="color: #993333;">int</span> switchYellow <span style="color: #339933;">=</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//AUDIO</span>
<span style="color: #993333;">int</span> notes<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
  NOTE_D4<span style="color: #339933;">,</span>NOTE_E4<span style="color: #339933;">,</span>NOTE_F4<span style="color: #339933;">,</span>NOTE_G4<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//this plays if you win</span>
<span style="color: #993333;">int</span> winNotes<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
  NOTE_D4<span style="color: #339933;">,</span> NOTE_E4<span style="color: #339933;">,</span>NOTE_C4<span style="color: #339933;">,</span>NOTE_C3<span style="color: #339933;">,</span>NOTE_G3 <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #993333;">int</span> durations<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #0000dd;">500</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">500</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">500</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">500</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">1000</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">//</span>
<span style="color: #993333;">int</span> playbackCount <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//autoplay selection count</span>
<span style="color: #993333;">int</span> selectionCount<span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//player selection count</span>
&nbsp;
<span style="color: #993333;">int</span> currentLevel <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//current game level</span>
&nbsp;
boolean watchMode <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">true</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Simon's turn, false means it is the players turn </span>
&nbsp;
<span style="color: #666666; font-style: italic;">//store which switch is currently active?</span>
<span style="color: #993333;">int</span> pressAry<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span><span style="color: #0000dd;">0</span><span style="color: #339933;">,</span><span style="color: #0000dd;">0</span><span style="color: #339933;">,</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//Storing the squence that gets randomly generated, Num in brackets states how long sequence is [#]</span>
<span style="color: #993333;">int</span> sequenceAry<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">7</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #993333;">int</span> sequenceAryLegnth <span style="color: #339933;">=</span> <span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span>sequenceAry<span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</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>
  pinMode<span style="color: #009900;">&#40;</span>ledWhite<span style="color: #339933;">,</span> OUTPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  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>
  pinMode<span style="color: #009900;">&#40;</span>switchWhite<span style="color: #339933;">,</span> INPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  pinMode<span style="color: #009900;">&#40;</span>switchGreen<span style="color: #339933;">,</span> INPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  pinMode<span style="color: #009900;">&#40;</span>switchRed<span style="color: #339933;">,</span> INPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>     
  pinMode<span style="color: #009900;">&#40;</span>switchYellow<span style="color: #339933;">,</span> INPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  pinMode<span style="color: #009900;">&#40;</span>transistorPin<span style="color: #339933;">,</span> OUTPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  randomSeed<span style="color: #009900;">&#40;</span>analogRead<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//Add this so sequence is truely random</span>
  audioFeedback.<span style="color: #202020;">begin</span><span style="color: #009900;">&#40;</span>speakerPin<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  createRandomSequence<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> loop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #808080; font-style: italic;">/************
   *  Check to see if simon/player mode
   *************/</span>
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>watchMode <span style="color: #339933;">==</span> <span style="color: #000000; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
   <span style="color: #808080; font-style: italic;">/************
   *  SIMON SEZ: leds automatically blink in random sequence
   *************/</span>
    <span style="color: #666666; font-style: italic;">//have you won?</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>playbackCount <span style="color: #339933;">&lt;=</span> sequenceAryLegnth<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      <span style="color: #666666; font-style: italic;">//has simon finshed showing current sequence?</span>
      <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>playbackCount <span style="color: #339933;">&lt;</span> currentLevel<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">//Blink proper LED from leds array</span>
        <span style="color: #993333;">int</span> activeLED_index <span style="color: #339933;">=</span> sequenceAry<span style="color: #009900;">&#91;</span>playbackCount<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        digitalWrite<span style="color: #009900;">&#40;</span>leds<span style="color: #009900;">&#91;</span>activeLED_index<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> HIGH<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">//Play corrisponding note</span>
        audioFeedback.<span style="color: #202020;">play</span><span style="color: #009900;">&#40;</span>notes<span style="color: #009900;">&#91;</span>activeLED_index<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        delay<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">200</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        digitalWrite<span style="color: #009900;">&#40;</span>leds<span style="color: #009900;">&#91;</span>activeLED_index<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> LOW<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        audioFeedback.<span style="color: #202020;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        delay<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">200</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        playbackCount<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;">//simon is done, now it is players turn</span>
        watchMode <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">false</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
       <span style="color: #808080; font-style: italic;">/************
       *  PLAYER WINS!
       *************/</span>
      playerWins<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">//Read States of all Switches</span>
    <span style="color: #993333;">int</span> whiteState <span style="color: #339933;">=</span> digitalRead<span style="color: #009900;">&#40;</span>switchWhite<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #993333;">int</span> greenState <span style="color: #339933;">=</span> digitalRead<span style="color: #009900;">&#40;</span>switchGreen<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #993333;">int</span> redState <span style="color: #339933;">=</span> digitalRead<span style="color: #009900;">&#40;</span>switchRed<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #993333;">int</span> yellowState <span style="color: #339933;">=</span> digitalRead<span style="color: #009900;">&#40;</span>switchYellow<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #993333;">int</span> statesAry<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
      whiteState<span style="color: #339933;">,</span>greenState<span style="color: #339933;">,</span>redState<span style="color: #339933;">,</span>yellowState<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">//loop across all 4 switch states</span>
    <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> x<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> x<span style="color: #339933;">&lt;</span><span style="color: #0000dd;">4</span><span style="color: #339933;">;</span> x<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      <span style="color: #993333;">int</span> switchState <span style="color: #339933;">=</span> statesAry<span style="color: #009900;">&#91;</span>x<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>switchState <span style="color: #339933;">==</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        audioFeedback.<span style="color: #202020;">play</span><span style="color: #009900;">&#40;</span>notes<span style="color: #009900;">&#91;</span>x<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        digitalWrite<span style="color: #009900;">&#40;</span>leds<span style="color: #009900;">&#91;</span>x<span style="color: #009900;">&#93;</span><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;">200</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        audioFeedback.<span style="color: #202020;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        digitalWrite<span style="color: #009900;">&#40;</span>leds<span style="color: #009900;">&#91;</span>x<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> LOW<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>pressAry<span style="color: #009900;">&#91;</span>x<span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
          <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>sequenceAry<span style="color: #009900;">&#91;</span>selectionCount<span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span>x<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            selectionCount<span style="color: #339933;">++;</span>
            pressAry<span style="color: #009900;">&#91;</span>x<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
          <span style="color: #009900;">&#125;</span>
          <span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
            resetGame<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #009900;">&#125;</span>
&nbsp;
      <span style="color: #009900;">&#125;</span>
      <span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
        pressAry<span style="color: #009900;">&#91;</span>x<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">// turn LED off:</span>
        digitalWrite<span style="color: #009900;">&#40;</span>leds<span style="color: #009900;">&#91;</span>x<span style="color: #009900;">&#93;</span><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;">//Check to see if we could incrament level</span>
      <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>selectionCount <span style="color: #339933;">==</span> currentLevel<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        advanceLevel<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #993333;">void</span> createRandomSequence<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
   <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> x<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> x<span style="color: #339933;">&lt;</span>sequenceAryLegnth<span style="color: #339933;">;</span> x<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      sequenceAry<span style="color: #009900;">&#91;</span>x<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> random<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">4</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span> 
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/************
 *  Play winning melody
 *************/</span>
<span style="color: #993333;">void</span> playerWins<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> thisNote <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> thisNote <span style="color: #339933;">&lt;</span> <span style="color: #0000dd;">5</span><span style="color: #339933;">;</span> thisNote <span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// play the next note:</span>
    audioFeedback.<span style="color: #202020;">play</span><span style="color: #009900;">&#40;</span>winNotes<span style="color: #009900;">&#91;</span>thisNote<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// hold the note:</span>
    delay<span style="color: #009900;">&#40;</span>durations<span style="color: #009900;">&#91;</span>thisNote<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// stop for the next note:</span>
    audioFeedback.<span style="color: #202020;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #666666; font-style: italic;">// hold before repeating:</span>
  delay<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">3000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/************
 *  Incrament player one level
 *************/</span>
<span style="color: #993333;">void</span> advanceLevel<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  resetValues<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  currentLevel<span style="color: #339933;">++;</span>
  delay<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">200</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> 
&nbsp;
<span style="color: #808080; font-style: italic;">/************
 *  Player pressed wrong button
 *************/</span>
<span style="color: #993333;">void</span> resetGame<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;">//DISPATCH HAPTIC FEEDBACK </span>
  digitalWrite<span style="color: #009900;">&#40;</span>transistorPin<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;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  digitalWrite<span style="color: #009900;">&#40;</span>transistorPin<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;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  resetValues<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  currentLevel <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
  delay<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/************
 *  Reset all values so simon knows to start from the first LED in the sequenceAry
 *************/</span>
<span style="color: #993333;">void</span> resetValues<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  selectionCount <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
  playbackCount <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
  watchMode <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<div class='kouguu_fb_like_button'><iframe src="http://www.facebook.com/plugins/like.php?href=http://blog.unthinkmedia.com/2010/02/09/diy-simon-with-arduino-w-source-and-diagram/&#038;layout=standart&#038;show_faces=true&#038;width=450&#038;height=65&#038;action=like&#038;colorscheme=light&#038;" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:65px;"></iframe></div>
<img src="http://blog.unthinkmedia.com/?ak_action=api_record_view&id=475&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blog.unthinkmedia.com/2010/02/09/diy-simon-with-arduino-w-source-and-diagram/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DIY Simon with Arduino: Take 1</title>
		<link>http://blog.unthinkmedia.com/2010/02/07/diy-simon-with-arduino-take-1/</link>
		<comments>http://blog.unthinkmedia.com/2010/02/07/diy-simon-with-arduino-take-1/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 03:49:57 +0000</pubDate>
		<dc:creator>Alex Britez</dc:creator>
				<category><![CDATA[Examples]]></category>
		<category><![CDATA[Physical Computing]]></category>
		<category><![CDATA[programing]]></category>
		<category><![CDATA[project]]></category>

		<guid isPermaLink="false">http://blog.unthinkmedia.com/?p=462</guid>
		<description><![CDATA[This past week I was trying to figure out what i could work on for my Physical Computing class. My professor mentioned, Simon, so why not take on the challenge. Simon was one of my favorite game, I even have it on my iPhone. For those that may not remember the Simon game check out [...]]]></description>
			<content:encoded><![CDATA[<p>This past week I was trying to figure out what i could work on for my Physical Computing class.  My professor mentioned, Simon, so why not take on the challenge.  Simon was one of my favorite game, I even have it on my iPhone.  For those that may not remember the Simon game check out this commercial.</p>
<p><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/KVzZVYtt64I&#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/KVzZVYtt64I&#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>Anyhow, armed with some basic knowledge of electronics, and some programming knowledge, why not!  Bellow is my stab at Simon<span id="more-462"></span>, I even added some haptic feedback just because.  The audio is a bit low because it was 1am and I didn&#8217;t want to wake up my wife and daughter, but you get the idea.</p>
<p><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/9IbpiVJKoPU&#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/9IbpiVJKoPU&#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>Before I post up the code, I need to clean it up a little bit and get a bit more acquainted with C. The programing language that Ardiuno uses is pretty bare bones, so a lot of common functions that i have taken for granted don&#8217;t exist, go figure. Not a big deal, it will just take some research and tinkering to figure it out.</p>
<p>Another issue i had was regarding resistor setup, an 8 ohm speaker, and it&#8217;s affect to what i believe is the audio pitch.  The sound that plays during Simon&#8217;s turn and the sound of the same note that play during the button press is slightly different. May need to bring out the multi-meter and see how many ohms are being passed through, in both scenarios. I am using the <a href="http://code.google.com/p/arduino-tone/">Arduino Tone Library</a>. I&#8217;ll add my findings in my next post once i find some free time to get my debugging hat on. Other then that, my first real project went pretty smoothly.</p>
<p>As I mentioned, once I iron out these small bugs, I will post all the source and wiring, then take it apart and move onto my next project.  Homework has never been so much fun&#8230;ha!
<div class='kouguu_fb_like_button'><iframe src="http://www.facebook.com/plugins/like.php?href=http://blog.unthinkmedia.com/2010/02/07/diy-simon-with-arduino-take-1/&#038;layout=standart&#038;show_faces=true&#038;width=450&#038;height=65&#038;action=like&#038;colorscheme=light&#038;" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:65px;"></iframe></div>
<img src="http://blog.unthinkmedia.com/?ak_action=api_record_view&id=462&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blog.unthinkmedia.com/2010/02/07/diy-simon-with-arduino-take-1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>A* Pathfinding and Away3D game</title>
		<link>http://blog.unthinkmedia.com/2008/09/23/a-pathfinding-and-away3d-game/</link>
		<comments>http://blog.unthinkmedia.com/2008/09/23/a-pathfinding-and-away3d-game/#comments</comments>
		<pubDate>Tue, 23 Sep 2008 19:22:50 +0000</pubDate>
		<dc:creator>Alex Britez</dc:creator>
				<category><![CDATA[Examples]]></category>
		<category><![CDATA[Flex/Flash]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[source]]></category>

		<guid isPermaLink="false">http://blog.unthinkmedia.com/?p=86</guid>
		<description><![CDATA[I created a very simple game using Away3d and with a A* pathfinding class which is called Detour with some help from Peter Kapelyan, who helped me tweak some of my code to make it 3D friendly.  It&#8217;s only a prototype of a game which i probably won&#8217;t enhance anytime soon, so I included the [...]]]></description>
			<content:encoded><![CDATA[<p>I created a very simple game using <a href="http://www.away3d.com">Away3d</a> and with a A* pathfinding class which is called Detour with some help from Peter Kapelyan, who helped me tweak some of my code to make it 3D friendly.  It&#8217;s only a prototype of a game which i probably won&#8217;t enhance anytime soon, so I included the source code for anyone that is interested.  If you does anything with it drop me an email so I could check it out.</p>
<p>The game is pretty much a maze that gets created &#8220;on the fly&#8221; (I really hate that phrase) by intersections that close off on each turn. The goal of the game is to beat the computer to the your homebase which is the space that the computer starts on (sort of like Chinese Checkers, but with one marble and maze) The first person to get to their homebase wins.  Use your arrow keys to move around.</p>
<p>Source View is <a href="http://project.unthinkmedia.com/un/pathfinder/srcview/">here</a>, so go bananas (I like that phrase).</p>
<p><a href="http://project.unthinkmedia.com/un/pathfinder/Detour.html"><img class="alignnone" src="http://project.unthinkmedia.com/un/pathfinder/detour.png" alt="" width="516" height="344" /></a></p>
<div class='kouguu_fb_like_button'><iframe src="http://www.facebook.com/plugins/like.php?href=http://blog.unthinkmedia.com/2008/09/23/a-pathfinding-and-away3d-game/&#038;layout=standart&#038;show_faces=true&#038;width=450&#038;height=65&#038;action=like&#038;colorscheme=light&#038;" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:65px;"></iframe></div>
<img src="http://blog.unthinkmedia.com/?ak_action=api_record_view&id=86&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blog.unthinkmedia.com/2008/09/23/a-pathfinding-and-away3d-game/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

