<?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>Bruno Soares &#187; Projects</title>
	<atom:link href="http://blog.bsoares.com.br/category/projects/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.bsoares.com.br</link>
	<description></description>
	<lastBuildDate>Sun, 11 Jul 2010 02:16:23 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Twitter Hardware</title>
		<link>http://blog.bsoares.com.br/arduino/twitter-hardware</link>
		<comments>http://blog.bsoares.com.br/arduino/twitter-hardware#comments</comments>
		<pubDate>Sat, 18 Apr 2009 22:08:13 +0000</pubDate>
		<dc:creator>Bruno Soares</dc:creator>
				<category><![CDATA[Adobe AIR]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Electronics]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[ActionScript 3.0]]></category>
		<category><![CDATA[Display LCD]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Open Hardware]]></category>
		<category><![CDATA[Serialproxy]]></category>
		<category><![CDATA[Techology]]></category>
		<category><![CDATA[Twitter]]></category>

		<guid isPermaLink="false">http://blog.bsoares.com.br/?p=193</guid>
		<description><![CDATA[Twitter Hardware é um projeto que utiliza a placa Arduino e um Display LCD para exibir as mensagens do Twitter. Para que a Arduino tenha as mensagens escrevi um software em Adobe AIR / Flex, que se conecta ao Serial Proxy enviando o conteúdo para a Arduino.

 Arduino:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347/**
&#160;* Twitter Hardware
&#160;* 
&#160;* @author &#160; Bruno Soares
&#160;* [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.bsoares.com.br/arduino/twitter-hardware" target="_self">Twitter Hardware</a> é um projeto que utiliza a placa <a href="http://www.arduino.cc/" target="_self">Arduino</a> e um Display LCD para exibir as mensagens do <a href="http://twitter.com/" target="_self">Twitter</a>. Para que a Arduino tenha as mensagens escrevi um software em <a href="http://www.adobe.com/products/air/" target="_self">Adobe AIR</a> / <a href="http://www.adobe.com/products/flex/" target="_self">Flex</a>, que se conecta ao Serial Proxy enviando o conteúdo para a Arduino.</p>
<p style="text-align: center;"><object width="320" height="265" data="http://www.youtube.com/v/W-oXkI7pKZA&amp;hl=pt-br&amp;fs=1" type="application/x-shockwave-flash"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/W-oXkI7pKZA&amp;hl=pt-br&amp;fs=1" /><param name="allowfullscreen" value="true" /></object></p>
<p><strong> Arduino:</strong></p>
<div class="codecolorer-container cpp mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;height:500px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br />115<br />116<br />117<br />118<br />119<br />120<br />121<br />122<br />123<br />124<br />125<br />126<br />127<br />128<br />129<br />130<br />131<br />132<br />133<br />134<br />135<br />136<br />137<br />138<br />139<br />140<br />141<br />142<br />143<br />144<br />145<br />146<br />147<br />148<br />149<br />150<br />151<br />152<br />153<br />154<br />155<br />156<br />157<br />158<br />159<br />160<br />161<br />162<br />163<br />164<br />165<br />166<br />167<br />168<br />169<br />170<br />171<br />172<br />173<br />174<br />175<br />176<br />177<br />178<br />179<br />180<br />181<br />182<br />183<br />184<br />185<br />186<br />187<br />188<br />189<br />190<br />191<br />192<br />193<br />194<br />195<br />196<br />197<br />198<br />199<br />200<br />201<br />202<br />203<br />204<br />205<br />206<br />207<br />208<br />209<br />210<br />211<br />212<br />213<br />214<br />215<br />216<br />217<br />218<br />219<br />220<br />221<br />222<br />223<br />224<br />225<br />226<br />227<br />228<br />229<br />230<br />231<br />232<br />233<br />234<br />235<br />236<br />237<br />238<br />239<br />240<br />241<br />242<br />243<br />244<br />245<br />246<br />247<br />248<br />249<br />250<br />251<br />252<br />253<br />254<br />255<br />256<br />257<br />258<br />259<br />260<br />261<br />262<br />263<br />264<br />265<br />266<br />267<br />268<br />269<br />270<br />271<br />272<br />273<br />274<br />275<br />276<br />277<br />278<br />279<br />280<br />281<br />282<br />283<br />284<br />285<br />286<br />287<br />288<br />289<br />290<br />291<br />292<br />293<br />294<br />295<br />296<br />297<br />298<br />299<br />300<br />301<br />302<br />303<br />304<br />305<br />306<br />307<br />308<br />309<br />310<br />311<br />312<br />313<br />314<br />315<br />316<br />317<br />318<br />319<br />320<br />321<br />322<br />323<br />324<br />325<br />326<br />327<br />328<br />329<br />330<br />331<br />332<br />333<br />334<br />335<br />336<br />337<br />338<br />339<br />340<br />341<br />342<br />343<br />344<br />345<br />346<br />347<br /></div></td><td><div class="cpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff0000; font-style: italic;">/**<br />
&nbsp;* Twitter Hardware<br />
&nbsp;* <br />
&nbsp;* @author &nbsp; Bruno Soares<br />
&nbsp;* @link &nbsp; &nbsp; http://www.bsoares.com.br<br />
&nbsp;* @language Arduino / C++<br />
&nbsp;*/</span><br />
<br />
<span style="color: #666666;">// Includes</span><br />
<span style="color: #339900;">#include &lt;LiquidCrystal.h&gt;</span><br />
<br />
<span style="color: #666666;">// Defines</span><br />
<span style="color: #339900;">#define DEBUG_PIN &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 13</span><br />
<br />
<span style="color: #339900;">#define COMMAND_RIGHT &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0</span><br />
<span style="color: #339900;">#define COMMAND_LEFT &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1</span><br />
<span style="color: #339900;">#define QUANTITY_COMMANDS &nbsp; &nbsp; &nbsp; &nbsp; 2</span><br />
<br />
<span style="color: #339900;">#define ANALOG_PIN_COMMAND_RIGHT &nbsp;0</span><br />
<span style="color: #339900;">#define ANALOG_PIN_COMMAND_LEFT &nbsp; 1</span><br />
<span style="color: #339900;">#define ANALOG_PIN_SPEED &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;2</span><br />
<br />
<span style="color: #339900;">#define MESSAGE_START &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 94 &nbsp;// &nbsp;94 = ^</span><br />
<span style="color: #339900;">#define MESSAGE_END &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 126 // 126 = ~</span><br />
<br />
<span style="color: #339900;">#define SERIAL_BOUND &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;9600</span><br />
<br />
<span style="color: #339900;">#define LCD_LINES &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2</span><br />
<span style="color: #339900;">#define LCD_COLUMNS &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 16</span><br />
<br />
<span style="color: #339900;">#define ANIMATE_CMD_WIDTH &nbsp; &nbsp; &nbsp; &nbsp; 4</span><br />
<br />
<span style="color: #666666;">// Global variables</span><br />
<span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">long</span> <span style="color: #0000dd;">time</span><span style="color: #008080;">;</span><br />
<br />
<span style="color: #666666;">// LiquidCrystal display with:</span><br />
<span style="color: #666666;">// rs on pin 12</span><br />
<span style="color: #666666;">// rw on pin 11</span><br />
<span style="color: #666666;">// enable on pin 2</span><br />
<span style="color: #666666;">// dbs 3, 4, 5, 6, 7, 8, 9, 10</span><br />
LiquidCrystal lcd<span style="color: #008000;">&#40;</span>12, 11, 2, 3, 4, 5, 6, 7, 8, 9, 10<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
<br />
<span style="color: #666666;">// Analog configuration</span><br />
<span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">int</span> analogCmd<span style="color: #008000;">&#91;</span>QUANTITY_COMMANDS<span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span><br />
<span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">int</span> analogSpeed <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span><br />
<br />
<span style="color: #666666;">// Control commands</span><br />
boolean changingSpeed <span style="color: #000080;">=</span> <span style="color: #0000ff;">true</span><span style="color: #008080;">;</span><br />
boolean readingSerial <span style="color: #000080;">=</span> <span style="color: #0000ff;">false</span><span style="color: #008080;">;</span><br />
boolean pressedCmd<span style="color: #008000;">&#91;</span>QUANTITY_COMMANDS<span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span><br />
<span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">int</span> lastSpeed <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span><br />
<br />
<span style="color: #666666;">// Massages</span><br />
<span style="color: #0000ff;">char</span> currentMessage<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">400</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> <span style="color: #FF0000;">&quot;No messages.&quot;</span><span style="color: #008080;">;</span><br />
<span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">int</span> currentMessageLenght<span style="color: #008080;">;</span><br />
<br />
<span style="color: #666666;">// ------------------------------------------------------------------------ \\</span><br />
<span style="color: #666666;">// Program</span><br />
<span style="color: #0000ff;">void</span> setup<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; Serial.<span style="color: #007788;">begin</span><span style="color: #008000;">&#40;</span>SERIAL_BOUND<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; pinMode<span style="color: #008000;">&#40;</span>DEBUG_PIN, OUTPUT<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; <br />
&nbsp; smartDelay<span style="color: #008000;">&#40;</span>10<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; lastSpeed <span style="color: #000080;">=</span> analogSpeed<span style="color: #008080;">;</span><br />
&nbsp; <br />
&nbsp; presentation<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; changingSpeed <span style="color: #000080;">=</span> <span style="color: #0000ff;">false</span><span style="color: #008080;">;</span><br />
<span style="color: #008000;">&#125;</span><br />
<br />
<span style="color: #0000ff;">void</span> loop<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; <br />
&nbsp; <span style="color: #666666;">// Show current message</span><br />
&nbsp; clearLcd<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; writeLongTextInLcd<span style="color: #008000;">&#40;</span>currentMessage<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; smartDelay<span style="color: #008000;">&#40;</span>applySpeed<span style="color: #008000;">&#40;</span>7000<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; <br />
<span style="color: #008000;">&#125;</span><br />
<br />
<span style="color: #0000ff;">void</span> presentation<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; lcd.<span style="color: #007788;">clear</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; writeLongTextInLcd<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;Twitter Hardwareby Bruno Soares&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; smartDelay<span style="color: #008000;">&#40;</span>3000<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
<span style="color: #008000;">&#125;</span><br />
<br />
<span style="color: #0000ff;">void</span> refreshAnalogVars<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; analogCmd<span style="color: #008000;">&#91;</span>COMMAND_RIGHT<span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> analogRead<span style="color: #008000;">&#40;</span>ANALOG_PIN_COMMAND_RIGHT<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; analogCmd<span style="color: #008000;">&#91;</span>COMMAND_LEFT<span style="color: #008000;">&#93;</span> &nbsp;<span style="color: #000080;">=</span> analogRead<span style="color: #008000;">&#40;</span>ANALOG_PIN_COMMAND_LEFT<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; analogSpeed &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000080;">=</span> analogRead<span style="color: #008000;">&#40;</span>ANALOG_PIN_SPEED<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
<span style="color: #008000;">&#125;</span><br />
<br />
<span style="color: #666666;">// ------------------------------------------------------------------------ \\</span><br />
<span style="color: #666666;">// [INI] Commands</span><br />
<span style="color: #0000ff;">void</span> detectCommand<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; <span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">int</span> i <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span><br />
&nbsp; <span style="color: #0000ff;">while</span> <span style="color: #008000;">&#40;</span>i <span style="color: #000080;">&lt;</span> QUANTITY_COMMANDS<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>analogCmd<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #000080;">&gt;</span> 500 <span style="color: #000040;">&amp;&amp;</span> <span style="color: #000040;">!</span>pressedCmd<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; executeCommand<span style="color: #008000;">&#40;</span>i<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; i<span style="color: #000040;">++</span><span style="color: #008080;">;</span><br />
&nbsp; <span style="color: #008000;">&#125;</span><br />
<span style="color: #008000;">&#125;</span><br />
<br />
<span style="color: #0000ff;">void</span> executeCommand<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> command<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; pressedCmd<span style="color: #008000;">&#91;</span>command<span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> <span style="color: #0000ff;">true</span><span style="color: #008080;">;</span><br />
&nbsp; digitalWrite<span style="color: #008000;">&#40;</span>DEBUG_PIN, 1<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; <br />
&nbsp; <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>command <span style="color: #000080;">==</span> 0<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; animateNext<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; <span style="color: #008000;">&#125;</span> <span style="color: #0000ff;">else</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; animatePrevious<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; <br />
&nbsp; currentMessage<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> <span style="color: #FF0000;">'L'</span><span style="color: #008080;">;</span><br />
&nbsp; currentMessage<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> <span style="color: #FF0000;">'o'</span><span style="color: #008080;">;</span><br />
&nbsp; currentMessage<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">2</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> <span style="color: #FF0000;">'a'</span><span style="color: #008080;">;</span><br />
&nbsp; currentMessage<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">3</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> <span style="color: #FF0000;">'d'</span><span style="color: #008080;">;</span><br />
&nbsp; currentMessage<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">4</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> <span style="color: #FF0000;">'i'</span><span style="color: #008080;">;</span><br />
&nbsp; currentMessage<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">5</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> <span style="color: #FF0000;">'n'</span><span style="color: #008080;">;</span><br />
&nbsp; currentMessage<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">6</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> <span style="color: #FF0000;">'g'</span><span style="color: #008080;">;</span><br />
&nbsp; currentMessage<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">7</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> <span style="color: #FF0000;">'<span style="color: #006699; font-weight: bold;">\0</span>'</span><span style="color: #008080;">;</span><br />
&nbsp; currentMessageLenght <span style="color: #000080;">=</span> <span style="color: #0000dd;">7</span><span style="color: #008080;">;</span><br />
&nbsp; <br />
&nbsp; Serial.<span style="color: #007788;">print</span><span style="color: #008000;">&#40;</span>command<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; <br />
&nbsp; <span style="color: #0000ff;">while</span> <span style="color: #008000;">&#40;</span>analogCmd<span style="color: #008000;">&#91;</span>command<span style="color: #008000;">&#93;</span> <span style="color: #000080;">&gt;</span> 500<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; smartDelay<span style="color: #008000;">&#40;</span>4<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; <br />
&nbsp; pressedCmd<span style="color: #008000;">&#91;</span>command<span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> <span style="color: #0000ff;">false</span><span style="color: #008080;">;</span><br />
&nbsp; digitalWrite<span style="color: #008000;">&#40;</span>DEBUG_PIN, 0<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
<span style="color: #008000;">&#125;</span><br />
<br />
<span style="color: #0000ff;">void</span> animateNext<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> &nbsp;<span style="color: #008000;">&#123;</span><br />
&nbsp; <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">int</span> i <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> i <span style="color: #000080;">&lt;</span> LCD_COLUMNS <span style="color: #000040;">+</span> ANIMATE_CMD_WIDTH<span style="color: #008080;">;</span> i<span style="color: #000040;">++</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>i <span style="color: #000080;">&lt;</span> LCD_COLUMNS<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; lcd.<span style="color: #007788;">setCursor</span><span style="color: #008000;">&#40;</span>i, 0<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; lcd.<span style="color: #007788;">print</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;&gt;&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; lcd.<span style="color: #007788;">setCursor</span><span style="color: #008000;">&#40;</span>i, 1<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; lcd.<span style="color: #007788;">print</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;&gt;&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; delay<span style="color: #008000;">&#40;</span>5<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>i <span style="color: #000040;">-</span> ANIMATE_CMD_WIDTH <span style="color: #000080;">&gt;=</span> 0<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; lcd.<span style="color: #007788;">setCursor</span><span style="color: #008000;">&#40;</span>i <span style="color: #000040;">-</span> ANIMATE_CMD_WIDTH, 0<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; lcd.<span style="color: #007788;">print</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot; &quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; lcd.<span style="color: #007788;">setCursor</span><span style="color: #008000;">&#40;</span>i <span style="color: #000040;">-</span> ANIMATE_CMD_WIDTH, 1<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; lcd.<span style="color: #007788;">print</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot; &quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; delay<span style="color: #008000;">&#40;</span>30<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; <span style="color: #008000;">&#125;</span><br />
<span style="color: #008000;">&#125;</span><br />
<br />
<span style="color: #0000ff;">void</span> animatePrevious<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> i <span style="color: #000080;">=</span> LCD_COLUMNS<span style="color: #008080;">;</span> i <span style="color: #000080;">&gt;=</span> <span style="color: #000040;">-</span>ANIMATE_CMD_WIDTH<span style="color: #008080;">;</span> i<span style="color: #000040;">--</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>i <span style="color: #000080;">&gt;=</span> 0 <span style="color: #000040;">&amp;&amp;</span> i <span style="color: #000080;">&lt;</span> LCD_COLUMNS<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; lcd.<span style="color: #007788;">setCursor</span><span style="color: #008000;">&#40;</span>i, 0<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; lcd.<span style="color: #007788;">print</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;&lt;&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; lcd.<span style="color: #007788;">setCursor</span><span style="color: #008000;">&#40;</span>i, 1<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; lcd.<span style="color: #007788;">print</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;&lt;&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; delay<span style="color: #008000;">&#40;</span>5<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>i <span style="color: #000040;">+</span> ANIMATE_CMD_WIDTH <span style="color: #000080;">&lt;</span> LCD_COLUMNS <span style="color: #000040;">&amp;&amp;</span> i <span style="color: #000040;">+</span> ANIMATE_CMD_WIDTH <span style="color: #000080;">&gt;=</span> 0<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; lcd.<span style="color: #007788;">setCursor</span><span style="color: #008000;">&#40;</span>i <span style="color: #000040;">+</span> ANIMATE_CMD_WIDTH, 0<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; lcd.<span style="color: #007788;">print</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot; &quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; lcd.<span style="color: #007788;">setCursor</span><span style="color: #008000;">&#40;</span>i <span style="color: #000040;">+</span> ANIMATE_CMD_WIDTH, 1<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; lcd.<span style="color: #007788;">print</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot; &quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; delay<span style="color: #008000;">&#40;</span>30<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; <span style="color: #008000;">&#125;</span><br />
<span style="color: #008000;">&#125;</span><br />
<span style="color: #666666;">// [END] Commands</span><br />
<br />
<span style="color: #666666;">// ------------------------------------------------------------------------ \\</span><br />
<span style="color: #666666;">// [INI] Messages</span><br />
<span style="color: #0000ff;">void</span> detectSerialMessage<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>Serial.<span style="color: #007788;">available</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">&gt;</span> 0 <span style="color: #000040;">&amp;&amp;</span> <span style="color: #000040;">!</span>readingSerial<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>Serial.<span style="color: #007788;">read</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">==</span> MESSAGE_START<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; serialReadMessage<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; <span style="color: #008000;">&#125;</span><br />
<span style="color: #008000;">&#125;</span><br />
<br />
<span style="color: #0000ff;">void</span> serialReadMessage<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; digitalWrite<span style="color: #008000;">&#40;</span>DEBUG_PIN, 1<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; readingSerial <span style="color: #000080;">=</span> <span style="color: #0000ff;">true</span><span style="color: #008080;">;</span><br />
&nbsp; currentMessageLenght <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span><br />
&nbsp; <br />
&nbsp; iniReading<span style="color: #008080;">:</span><br />
&nbsp; <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>Serial.<span style="color: #007788;">available</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">&gt;</span> 0<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">int</span> _char <span style="color: #000080;">=</span> Serial.<span style="color: #007788;">read</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>_char <span style="color: #000080;">==</span> MESSAGE_END<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">goto</span> endReading<span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span> <span style="color: #0000ff;">else</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; currentMessage<span style="color: #008000;">&#91;</span>currentMessageLenght<span style="color: #000040;">++</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> _char<span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; delay<span style="color: #008000;">&#40;</span>2<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">goto</span> iniReading<span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; <span style="color: #0000ff;">goto</span> iniReading<span style="color: #008080;">;</span><br />
&nbsp; <br />
&nbsp; endReading<span style="color: #008080;">:</span><br />
&nbsp; currentMessage<span style="color: #008000;">&#91;</span>currentMessageLenght<span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> <span style="color: #FF0000;">'<span style="color: #006699; font-weight: bold;">\0</span>'</span><span style="color: #008080;">;</span><br />
&nbsp; digitalWrite<span style="color: #008000;">&#40;</span>DEBUG_PIN, 0<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; readingSerial <span style="color: #000080;">=</span> <span style="color: #0000ff;">false</span><span style="color: #008080;">;</span><br />
<span style="color: #008000;">&#125;</span><br />
<span style="color: #666666;">// [END] Messages</span><br />
<br />
<span style="color: #666666;">// ------------------------------------------------------------------------ \\</span><br />
<span style="color: #666666;">// [INI] LCD manipulation</span><br />
<span style="color: #0000ff;">void</span> writeLongTextInLcd<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">char</span> text<span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; writeInit<span style="color: #008080;">:</span><br />
&nbsp; clearLcd<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; <span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">int</span> cml <span style="color: #000080;">=</span> currentMessageLenght<span style="color: #008080;">;</span><br />
&nbsp; <span style="color: #0000ff;">int</span> loops <span style="color: #000080;">=</span> <span style="color: #000040;">-</span><span style="color: #0000dd;">1</span><span style="color: #008080;">;</span><br />
&nbsp; <span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">int</span> chars <span style="color: #000080;">=</span> <span style="color: #0000dd;">1</span><span style="color: #008080;">;</span><br />
&nbsp; <span style="color: #0000ff;">while</span> <span style="color: #008000;">&#40;</span>text<span style="color: #008000;">&#91;</span>loops<span style="color: #000040;">++</span> <span style="color: #000040;">+</span> 1<span style="color: #008000;">&#93;</span> <span style="color: #000040;">!</span><span style="color: #000080;">=</span> 0<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>chars <span style="color: #000080;">==</span> 17<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; lcd.<span style="color: #007788;">setCursor</span><span style="color: #008000;">&#40;</span>0, 1<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; smartDelay<span style="color: #008000;">&#40;</span>applySpeed<span style="color: #008000;">&#40;</span>600<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>cml <span style="color: #000040;">!</span><span style="color: #000080;">=</span> currentMessageLenght<span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">goto</span> writeInit<span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span> <span style="color: #0000ff;">else</span> <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>chars <span style="color: #000080;">==</span> 33<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; smartDelay<span style="color: #008000;">&#40;</span>applySpeed<span style="color: #008000;">&#40;</span>3000<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; clearLcd<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>cml <span style="color: #000040;">!</span><span style="color: #000080;">=</span> currentMessageLenght<span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">goto</span> writeInit<span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; chars <span style="color: #000080;">=</span> <span style="color: #0000dd;">1</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; lcd.<span style="color: #007788;">print</span><span style="color: #008000;">&#40;</span>text<span style="color: #008000;">&#91;</span>loops<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; smartDelay<span style="color: #008000;">&#40;</span>applySpeed<span style="color: #008000;">&#40;</span>60<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>cml <span style="color: #000040;">!</span><span style="color: #000080;">=</span> currentMessageLenght<span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">goto</span> writeInit<span style="color: #008080;">;</span><br />
&nbsp; &nbsp; chars<span style="color: #000040;">++</span><span style="color: #008080;">;</span><br />
&nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; Serial.<span style="color: #007788;">print</span><span style="color: #008000;">&#40;</span>2<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
<span style="color: #008000;">&#125;</span><br />
<br />
<span style="color: #0000ff;">void</span> writeInLcd<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">char</span> text<span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span>, <span style="color: #0000ff;">int</span> quantity<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">int</span> i <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> i <span style="color: #000080;">&lt;</span> quantity<span style="color: #008080;">;</span> i<span style="color: #000040;">++</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>text<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #000080;">==</span> 0<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">do</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; lcd.<span style="color: #007788;">print</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot; &quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span> <span style="color: #0000ff;">while</span> <span style="color: #008000;">&#40;</span>i<span style="color: #000040;">++</span> <span style="color: #000080;">&lt;</span> quantity<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">break</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span> <span style="color: #0000ff;">else</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; lcd.<span style="color: #007788;">print</span><span style="color: #008000;">&#40;</span>text<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; delay<span style="color: #008000;">&#40;</span>2<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; <span style="color: #666666;">//smartDelay(5);</span><br />
<span style="color: #008000;">&#125;</span><br />
<br />
<span style="color: #0000ff;">void</span> clearLcd<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; lcd.<span style="color: #007788;">setCursor</span><span style="color: #008000;">&#40;</span>0, 0<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; smartDelay<span style="color: #008000;">&#40;</span>5<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; lcd.<span style="color: #007788;">print</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; smartDelay<span style="color: #008000;">&#40;</span>applySpeed<span style="color: #008000;">&#40;</span>400<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; lcd.<span style="color: #007788;">setCursor</span><span style="color: #008000;">&#40;</span>0, 1<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; smartDelay<span style="color: #008000;">&#40;</span>5<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; lcd.<span style="color: #007788;">print</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; lcd.<span style="color: #007788;">setCursor</span><span style="color: #008000;">&#40;</span>0, 0<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; smartDelay<span style="color: #008000;">&#40;</span>applySpeed<span style="color: #008000;">&#40;</span>0<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
<span style="color: #008000;">&#125;</span><br />
<span style="color: #666666;">// [END] LCD manipulation</span><br />
<br />
<span style="color: #666666;">// ------------------------------------------------------------------------ \\</span><br />
<span style="color: #666666;">// [INI] Speed</span><br />
<span style="color: #0000ff;">void</span> detectChangeSpeed<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>changingSpeed<span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">return</span><span style="color: #008080;">;</span><br />
&nbsp; <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #000040;">!</span><span style="color: #008000;">&#40;</span>lastSpeed <span style="color: #000080;">&lt;</span> analogSpeed <span style="color: #000040;">+</span> 6 <span style="color: #000040;">&amp;&amp;</span> lastSpeed <span style="color: #000080;">&gt;</span> analogSpeed <span style="color: #000040;">-</span> 6<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; showGraderSpeed<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; <span style="color: #008000;">&#125;</span><br />
<span style="color: #008000;">&#125;</span><br />
<br />
<span style="color: #0000ff;">void</span> showGraderSpeed<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; changingSpeed <span style="color: #000080;">=</span> <span style="color: #0000ff;">true</span><span style="color: #008080;">;</span><br />
&nbsp; digitalWrite<span style="color: #008000;">&#40;</span>DEBUG_PIN, 1<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; lcd.<span style="color: #007788;">clear</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; writeInLcd<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;Speed:&quot;</span>, LCD_COLUMNS<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; <br />
&nbsp; <span style="color: #666666;">// Create display velocity</span><br />
&nbsp; showSpeed<span style="color: #008080;">:</span><br />
&nbsp; <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">int</span> i <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> i <span style="color: #000080;">&lt;</span> <span style="color: #0000dd;">10</span><span style="color: #008080;">;</span> i<span style="color: #000040;">++</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">int</span> charsSpeed <span style="color: #000080;">=</span> map<span style="color: #008000;">&#40;</span>analogSpeed, 0, 1023, 0, LCD_COLUMNS<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">int</span> percentSpeed <span style="color: #000080;">=</span> map<span style="color: #008000;">&#40;</span>analogSpeed, 0, 1023, 0, 100<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">char</span><span style="color: #000040;">*</span> percentString<span style="color: #008080;">;</span><br />
&nbsp; &nbsp; itoa<span style="color: #008000;">&#40;</span>100 <span style="color: #000040;">-</span> percentSpeed, percentString, 10<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; percentString <span style="color: #000080;">=</span> <span style="color: #0000dd;">strcat</span><span style="color: #008000;">&#40;</span>percentString, <span style="color: #FF0000;">&quot;%&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; lcd.<span style="color: #007788;">setCursor</span><span style="color: #008000;">&#40;</span>7, 0<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; writeInLcd<span style="color: #008000;">&#40;</span>percentString, 4<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; charsSpeed <span style="color: #000080;">=</span> LCD_COLUMNS <span style="color: #000040;">-</span> charsSpeed<span style="color: #008080;">;</span><br />
&nbsp; &nbsp; lcd.<span style="color: #007788;">setCursor</span><span style="color: #008000;">&#40;</span>0, 1<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">int</span> x <span style="color: #000080;">=</span> <span style="color: #0000dd;">1</span><span style="color: #008080;">;</span> x <span style="color: #000080;">&lt;</span> LCD_COLUMNS <span style="color: #000040;">+</span> <span style="color: #0000dd;">1</span><span style="color: #008080;">;</span> x<span style="color: #000040;">++</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>x <span style="color: #000080;">&lt;=</span> charsSpeed<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; lcd.<span style="color: #007788;">print</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;&gt;&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span> <span style="color: #0000ff;">else</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; lcd.<span style="color: #007788;">print</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot; &quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; lastSpeed <span style="color: #000080;">=</span> analogSpeed<span style="color: #008080;">;</span><br />
&nbsp; &nbsp; smartDelay<span style="color: #008000;">&#40;</span>40<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; <br />
&nbsp; <span style="color: #666666;">// Verify</span><br />
&nbsp; <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">int</span> i <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> i <span style="color: #000080;">&lt;</span> <span style="color: #0000dd;">10</span><span style="color: #008080;">;</span> i<span style="color: #000040;">++</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #000040;">!</span><span style="color: #008000;">&#40;</span>lastSpeed <span style="color: #000080;">&lt;</span> analogSpeed <span style="color: #000040;">+</span> 6 <span style="color: #000040;">&amp;&amp;</span> lastSpeed <span style="color: #000080;">&gt;</span> analogSpeed <span style="color: #000040;">-</span> 6<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">goto</span> showSpeed<span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; smartDelay<span style="color: #008000;">&#40;</span>40<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; <br />
&nbsp; <span style="color: #666666;">// Finalize</span><br />
&nbsp; lcd.<span style="color: #007788;">clear</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; changingSpeed <span style="color: #000080;">=</span> <span style="color: #0000ff;">false</span><span style="color: #008080;">;</span><br />
&nbsp; digitalWrite<span style="color: #008000;">&#40;</span>DEBUG_PIN, 0<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
<span style="color: #008000;">&#125;</span><br />
<br />
<span style="color: #0000ff;">long</span> applySpeed <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">int</span> value<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; <span style="color: #0000ff;">return</span> map<span style="color: #008000;">&#40;</span>analogSpeed, 0, 1023, 0, value<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
<span style="color: #008000;">&#125;</span><br />
<br />
<span style="color: #666666;">// [END] Speed</span><br />
<br />
<span style="color: #666666;">// ------------------------------------------------------------------------ \\</span><br />
<span style="color: #666666;">// [INI] Milliseconds controller</span><br />
<span style="color: #0000ff;">void</span> smartDelay<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> milliseconds<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>milliseconds <span style="color: #000080;">&lt;</span> 2<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; noDelayFunctions<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; delay<span style="color: #008000;">&#40;</span>milliseconds<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">return</span><span style="color: #008080;">;</span><br />
&nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; <span style="color: #0000ff;">do</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; delay<span style="color: #008000;">&#40;</span>1<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; milliseconds <span style="color: #000040;">-</span><span style="color: #000080;">=</span> noDelayFunctions<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; milliseconds <span style="color: #000040;">-</span><span style="color: #000080;">=</span> <span style="color: #0000dd;">1</span><span style="color: #008080;">;</span><br />
&nbsp; <span style="color: #008000;">&#125;</span> <span style="color: #0000ff;">while</span> <span style="color: #008000;">&#40;</span>milliseconds <span style="color: #000080;">&gt;</span> 0<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
<span style="color: #008000;">&#125;</span><br />
<br />
<span style="color: #0000ff;">int</span> noDelayFunctions<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; <span style="color: #0000dd;">time</span> <span style="color: #000080;">=</span> millis<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; <br />
&nbsp; <span style="color: #666666;">// [INI] No delay functions here</span><br />
&nbsp; refreshAnalogVars<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; detectChangeSpeed<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; detectCommand<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; detectSerialMessage<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; <span style="color: #666666;">// [END] No delay functions here</span><br />
&nbsp; <br />
&nbsp; <span style="color: #0000ff;">return</span> millis<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">-</span> <span style="color: #0000dd;">time</span><span style="color: #008080;">;</span><br />
<span style="color: #008000;">&#125;</span><br />
<span style="color: #666666;">// [END] Milliseconds controller</span></div></td></tr></tbody></table></div>
<p><strong>ActionScript (usando Serialproxy):</strong></p>
<div class="codecolorer-container actionscript3 mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;height:500px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br />115<br />116<br />117<br />118<br />119<br />120<br />121<br />122<br />123<br />124<br />125<br />126<br />127<br />128<br />129<br />130<br />131<br />132<br />133<br />134<br />135<br />136<br />137<br />138<br />139<br />140<br />141<br />142<br />143<br />144<br />145<br />146<br />147<br />148<br />149<br />150<br />151<br />152<br />153<br />154<br />155<br />156<br />157<br />158<br />159<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #9900cc; font-weight: bold;">package</span> br<span style="color: #000066; font-weight: bold;">.</span>com<span style="color: #000066; font-weight: bold;">.</span>bsoares<span style="color: #000066; font-weight: bold;">.</span>air<span style="color: #000066; font-weight: bold;">.</span>airtwitterhardware<br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><a href="http://www.google.com/search?q=event%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:event.html"><span style="color: #004993;">Event</span></a><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><a href="http://www.google.com/search?q=eventdispatcher%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:eventdispatcher.html"><span style="color: #004993;">EventDispatcher</span></a><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><a href="http://www.google.com/search?q=ioerrorevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:ioerrorevent.html"><span style="color: #004993;">IOErrorEvent</span></a><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><a href="http://www.google.com/search?q=progressevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:progressevent.html"><span style="color: #004993;">ProgressEvent</span></a><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.net</span><span style="color: #000066; font-weight: bold;">.</span><a href="http://www.google.com/search?q=socket%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:socket.html"><span style="color: #004993;">Socket</span></a><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #3f5fbf;">/**<br />
&nbsp; &nbsp; &nbsp;* Message Control<br />
&nbsp; &nbsp; &nbsp;* Control messages between the Arduino and in AIR<br />
&nbsp; &nbsp; &nbsp;* Application using Serial Proxy.<br />
&nbsp; &nbsp; &nbsp;* <br />
&nbsp; &nbsp; &nbsp;* @author Bruno Soares<br />
&nbsp; &nbsp; &nbsp;* @link &nbsp; http://www.bsoares.com.br<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> MessageControl <span style="color: #0033ff; font-weight: bold;">extends</span> <a href="http://www.google.com/search?q=eventdispatcher%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:eventdispatcher.html"><span style="color: #004993;">EventDispatcher</span></a><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// Properties</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _host<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _port<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=uint%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:uint.html"><span style="color: #004993;">uint</span></a><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _socket<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=socket%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:socket.html"><span style="color: #004993;">Socket</span></a><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _messages<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=array%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:array.html"><span style="color: #004993;">Array</span></a><span style="color: #000066; font-weight: bold;">;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _currentMessage<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=uint%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:uint.html"><span style="color: #004993;">uint</span></a><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> static <span style="color: #6699cc; font-weight: bold;">var</span> _instance<span style="color: #000066; font-weight: bold;">:</span>MessageControl<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> static <span style="color: #6699cc; font-weight: bold;">var</span> _allowInstantiation<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=boolean%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:boolean.html"><span style="color: #004993;">Boolean</span></a> = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// Constructor</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> MessageControl<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">!</span>_allowInstantiation<span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">throw</span> <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=error%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:error.html"><span style="color: #004993;">Error</span></a><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Use instance property (this is a Singleton Class).&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">init</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// Logic</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">init</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _host = <span style="color: #990000;">&quot;127.0.0.1&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// COM2</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _port = <span style="color: #000000; font-weight:bold;">5332</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _messages = <span style="color: #000000;">&#91;</span> <span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _currentMessage = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; socketConnect<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> socketConnect<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _socket = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=socket%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:socket.html"><span style="color: #004993;">Socket</span></a><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _socket<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=progressevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:progressevent.html"><span style="color: #004993;">ProgressEvent</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">SOCKET_DATA</span><span style="color: #000066; font-weight: bold;">,</span> onSocketData<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _socket<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=event%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:event.html"><span style="color: #004993;">Event</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">CLOSE</span><span style="color: #000066; font-weight: bold;">,</span> onSocketClose<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _socket<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=ioerrorevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:ioerrorevent.html"><span style="color: #004993;">IOErrorEvent</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">IO_ERROR</span><span style="color: #000066; font-weight: bold;">,</span> onSocketIoError<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _socket<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">connect</span><span style="color: #000000;">&#40;</span>_host<span style="color: #000066; font-weight: bold;">,</span> _port<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> processData<span style="color: #000000;">&#40;</span><span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Arduino command:&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">data</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">switch</span> <span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// Send next message</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #004993;">data</span> == <span style="color: #990000;">&quot;2&quot;</span> <span style="color: #000066; font-weight: bold;">||</span> <span style="color: #004993;">data</span> == <span style="color: #990000;">&quot;0&quot;</span><span style="color: #000066; font-weight: bold;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendNextMessage<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// Send previous message</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #004993;">data</span> == <span style="color: #990000;">&quot;1&quot;</span><span style="color: #000066; font-weight: bold;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendPreviousMessage<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> sendMessage<span style="color: #000000;">&#40;</span><span style="color: #004993;">message</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">message</span> == <span style="color: #0033ff; font-weight: bold;">null</span> <span style="color: #000066; font-weight: bold;">||</span> <span style="color: #004993;">message</span> == <span style="color: #990000;">&quot;&quot;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">return</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Message:&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">message</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// MESSAGE_START</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _socket<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">writeUTFBytes</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;^&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _socket<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">flush</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// MESSAGE</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=uint%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:uint.html"><span style="color: #004993;">uint</span></a> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> i <span style="color: #000066; font-weight: bold;">&lt;</span> <span style="color: #004993;">message</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span><span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _socket<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">writeUTFBytes</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">message</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">charAt</span><span style="color: #000000;">&#40;</span>i<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _socket<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">flush</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// MESSAGE_END</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _socket<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">writeUTFBytes</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;~&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _socket<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">flush</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">dispatchEvent</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=event%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:event.html"><span style="color: #004993;">Event</span></a><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=event%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:event.html"><span style="color: #004993;">Event</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">CHANGE</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> sendNextMessage<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _currentMessage = _currentMessage == _messages<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span> <span style="color: #000066; font-weight: bold;">-</span> 1 <span style="color: #000066; font-weight: bold;">?</span> 0 <span style="color: #000066; font-weight: bold;">:</span> _currentMessage <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendMessage<span style="color: #000000;">&#40;</span>_messages<span style="color: #000000;">&#91;</span>_currentMessage<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> sendPreviousMessage<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _currentMessage = _currentMessage == 0 <span style="color: #000066; font-weight: bold;">?</span> _messages<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span> <span style="color: #000066; font-weight: bold;">-</span> 1 <span style="color: #000066; font-weight: bold;">:</span> _currentMessage <span style="color: #000066; font-weight: bold;">-</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendMessage<span style="color: #000000;">&#40;</span>_messages<span style="color: #000000;">&#91;</span>_currentMessage<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// Events</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> onSocketData<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=progressevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:progressevent.html"><span style="color: #004993;">ProgressEvent</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">while</span> <span style="color: #000000;">&#40;</span>_socket<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">bytesAvailable</span> <span style="color: #000066; font-weight: bold;">&gt;</span> 0<span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; processData<span style="color: #000000;">&#40;</span>_socket<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">readUTFBytes</span><span style="color: #000000;">&#40;</span>1<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> onSocketClose<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=event%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:event.html"><span style="color: #004993;">Event</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; socketConnect<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> onSocketIoError<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=ioerrorevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:ioerrorevent.html"><span style="color: #004993;">IOErrorEvent</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// Getters and Setters</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> static <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">get</span> instance<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span>MessageControl<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>_instance == <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _allowInstantiation = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _instance = <span style="color: #0033ff; font-weight: bold;">new</span> MessageControl<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _allowInstantiation = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">return</span> _instance<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">set</span> messages<span style="color: #000000;">&#40;</span><span style="color: #004993;">value</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=array%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:array.html"><span style="color: #004993;">Array</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _currentMessage = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _messages = <span style="color: #004993;">value</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>_messages<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span> <span style="color: #000066; font-weight: bold;">&gt;</span> 0<span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendMessage<span style="color: #000000;">&#40;</span>_messages<span style="color: #000000;">&#91;</span>0<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">get</span> messages<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=array%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:array.html"><span style="color: #004993;">Array</span></a><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">return</span> _messages<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">get</span> currentMessage<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=uint%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:uint.html"><span style="color: #004993;">uint</span></a><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">return</span> _currentMessage<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<p><strong>Esquemático:</strong><br />
<a rel="attachment wp-att-207" href="http://blog.bsoares.com.br/arduino/twitter-hardware/attachment/twitterhardware-schematic"><img title="twitterhardware-schematic" src="http://blog.bsoares.com.br/wp-content/uploads/2009/04/twitterhardware-schematic-300x300.png" alt="twitterhardware-schematic" width="300" height="300" /></a></p>

<div class="ngg-galleryoverview" id="ngg-gallery-1-193">


	
	<!-- Thumbnails -->
		
	<div id="ngg-image-1" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://blog.bsoares.com.br/wp-content/gallery/twitter-hardware/twitterhardware.jpg" rel="shadowbox[post-193];player=img;" title=" "  >
								<img title="twitterhardware.jpg" alt="twitterhardware.jpg" src="http://blog.bsoares.com.br/wp-content/gallery/twitter-hardware/thumbs/thumbs_twitterhardware.jpg" width="100" height="75" />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-2" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://blog.bsoares.com.br/wp-content/gallery/twitter-hardware/Twitter-Hardware-1.jpg" rel="shadowbox[post-193];player=img;" title=" "  >
								<img title="Twitter-Hardware-1.jpg" alt="Twitter-Hardware-1.jpg" src="http://blog.bsoares.com.br/wp-content/gallery/twitter-hardware/thumbs/thumbs_Twitter-Hardware-1.jpg" width="100" height="75" />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-3" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://blog.bsoares.com.br/wp-content/gallery/twitter-hardware/Twitter-Hardware-2.jpg" rel="shadowbox[post-193];player=img;" title=" "  >
								<img title="Twitter-Hardware-2.jpg" alt="Twitter-Hardware-2.jpg" src="http://blog.bsoares.com.br/wp-content/gallery/twitter-hardware/thumbs/thumbs_Twitter-Hardware-2.jpg" width="100" height="75" />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-4" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://blog.bsoares.com.br/wp-content/gallery/twitter-hardware/Twitter-Hardware-3.jpg" rel="shadowbox[post-193];player=img;" title=" "  >
								<img title="Twitter-Hardware-3.jpg" alt="Twitter-Hardware-3.jpg" src="http://blog.bsoares.com.br/wp-content/gallery/twitter-hardware/thumbs/thumbs_Twitter-Hardware-3.jpg" width="100" height="75" />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-5" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://blog.bsoares.com.br/wp-content/gallery/twitter-hardware/Twitter-Hardware-4.jpg" rel="shadowbox[post-193];player=img;" title=" "  >
								<img title="Twitter-Hardware-4.jpg" alt="Twitter-Hardware-4.jpg" src="http://blog.bsoares.com.br/wp-content/gallery/twitter-hardware/thumbs/thumbs_Twitter-Hardware-4.jpg" width="100" height="75" />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-6" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://blog.bsoares.com.br/wp-content/gallery/twitter-hardware/Twitter-Hardware-5.jpg" rel="shadowbox[post-193];player=img;" title=" "  >
								<img title="Twitter-Hardware-5.jpg" alt="Twitter-Hardware-5.jpg" src="http://blog.bsoares.com.br/wp-content/gallery/twitter-hardware/thumbs/thumbs_Twitter-Hardware-5.jpg" width="100" height="75" />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-7" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://blog.bsoares.com.br/wp-content/gallery/twitter-hardware/Twitter-Hardware-6.jpg" rel="shadowbox[post-193];player=img;" title=" "  >
								<img title="Twitter-Hardware-6.jpg" alt="Twitter-Hardware-6.jpg" src="http://blog.bsoares.com.br/wp-content/gallery/twitter-hardware/thumbs/thumbs_Twitter-Hardware-6.jpg" width="100" height="75" />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-8" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://blog.bsoares.com.br/wp-content/gallery/twitter-hardware/Twitter-Hardware-7.jpg" rel="shadowbox[post-193];player=img;" title=" "  >
								<img title="Twitter-Hardware-7.jpg" alt="Twitter-Hardware-7.jpg" src="http://blog.bsoares.com.br/wp-content/gallery/twitter-hardware/thumbs/thumbs_Twitter-Hardware-7.jpg" width="100" height="75" />
							</a>
		</div>
	</div>
	
		
 	 	
	<!-- Pagination -->
 	<div class='ngg-clear'></div>
 	
</div>


<p>Baixe o <a href="http://blog.bsoares.com.br/wp-content/uploads/2009/04/twitterhardware.zip">código fonte aqui</a>.</p>
<p><strong>Conteúdo relacionado:</strong><br />
Mais fotos: <a href="http://www.flickr.com/photos/bsoares/sets/72157616923436133/" target="_self">http://www.flickr.com/photos/bsoares/sets/72157616923436133/</a><br />
Fritzing: <a href="http://fritzing.org/">http://fritzing.org/</a><br />
Arduino: <a href="http://arduino.cc/" target="_self">http://arduino.cc/</a><br />
Adobe AIR: <a href="http://www.adobe.com/products/air/" target="_self">http://www.adobe.com/products/air/</a><br />
Adobe Flex: <a href="http://www.adobe.com/products/flex/" target="_self">http://www.adobe.com/products/flex/</a><br />
LiquidCrystal Library: <a href="http://arduino.cc/en/Reference/LiquidCrystal?from=Tutorial.LCDLibrary" target="_self">http://arduino.cc/en/Reference/LiquidCrystal?from=Tutorial.LCDLibrary</a><br />
Twitter: <a href="http://twitter.com/" target="_self">http://twitter.com/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bsoares.com.br/arduino/twitter-hardware/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
