<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>.Net Zone</title>
	<atom:link href="http://staceyw1.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://staceyw1.wordpress.com</link>
	<description>Just another WordPress.com site</description>
	<lastBuildDate>Sat, 08 Oct 2011 15:55:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='staceyw1.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>.Net Zone</title>
		<link>http://staceyw1.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://staceyw1.wordpress.com/osd.xml" title=".Net Zone" />
	<atom:link rel='hub' href='http://staceyw1.wordpress.com/?pushpress=hub'/>
		<item>
		<title>LightSwitch timeouts and SessionState service</title>
		<link>http://staceyw1.wordpress.com/2011/10/08/lightswitch-timeouts-and-sessionstate-service/</link>
		<comments>http://staceyw1.wordpress.com/2011/10/08/lightswitch-timeouts-and-sessionstate-service/#comments</comments>
		<pubDate>Sat, 08 Oct 2011 15:54:59 +0000</pubDate>
		<dc:creator>staceyw1</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[LightSwitch]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[SessionState]]></category>

		<guid isPermaLink="false">https://staceyw1.wordpress.com/2011/10/08/lightswitch-timeouts-and-sessionstate-service/</guid>
		<description><![CDATA[In terms of IIS, a LS app is just another web app, so all the same rules apply such as Forms Session cookies.&#160; I had taken care to set session timeouts, but still was having timeouts at random times which &#8230; <a href="http://staceyw1.wordpress.com/2011/10/08/lightswitch-timeouts-and-sessionstate-service/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=staceyw1.wordpress.com&amp;blog=16471264&amp;post=311&amp;subd=staceyw1&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In terms of IIS, a LS app is just another web app, so all the same rules apply such as Forms Session cookies.&nbsp; I had taken care to set session timeouts, but still was having timeouts at random times which left me confused; until I realized application pool restarts wipe out the session state on the server.&nbsp; So you need a way to persist session state across AppPool restarts (and server restarts).&nbsp; If you are using 3rd party Hoster, your app pool is normally shared across all sites on the server. So you should assume your app pool is restarting all the time for various reasons (configuration changes, memory pressure, maintence, etc)&nbsp; The easiest way to store session state is the use the ASP.NET State Service.&nbsp; Here is the process:</p>
<p>1) Start the ASP.NET State Service and change to automatic startup. Your hoster may already have it started.&nbsp; Arvixe does for example.</p>
<p>2) Update your LS web.config in the ServerGenerated folder. Add or change the authentiation element and sessionState element using below as a guide.</p>
<p>3) Deploy your app again and browse to your application or&nbsp; Hit F5 if already open to pull down new version and update session.<br /><strong><font size="2" face="Lucida Console"> &lt;system.web&gt;<br />&#8230;<br />&nbsp;&nbsp;&nbsp; &lt;authentication mode=&#8221;Forms&#8221;&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;forms name=&#8221;MyAppName&#8221; timeout=&#8221;1440&#8243; /&gt;<br />&nbsp;&nbsp;&nbsp; &lt;/authentication&gt;<br />&nbsp;&nbsp;&nbsp; &lt;sessionState mode=&#8221;StateServer&#8221; cookieless=&#8221;false&#8221; timeout=&#8221;1440&#8243; /&gt;<br />&#8230;<br /> &lt;system.web&gt;</font></strong></p>
<p>You can also view or change your application&#8217;s session state in IIS MMC in the Session State icon. It is best to add to your LS web.config as it will persist across deployments.</p>
<p><a href="http://staceyw1.files.wordpress.com/2011/10/image.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="image" border="0" alt="image" src="http://staceyw1.files.wordpress.com/2011/10/image_thumb.png?w=360&#038;h=456" width="360" height="456"></a></p>
<p>Hope that helps.<br />&#8211;William</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/staceyw1.wordpress.com/311/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/staceyw1.wordpress.com/311/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/staceyw1.wordpress.com/311/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/staceyw1.wordpress.com/311/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/staceyw1.wordpress.com/311/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/staceyw1.wordpress.com/311/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/staceyw1.wordpress.com/311/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/staceyw1.wordpress.com/311/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/staceyw1.wordpress.com/311/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/staceyw1.wordpress.com/311/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/staceyw1.wordpress.com/311/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/staceyw1.wordpress.com/311/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/staceyw1.wordpress.com/311/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/staceyw1.wordpress.com/311/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=staceyw1.wordpress.com&amp;blog=16471264&amp;post=311&amp;subd=staceyw1&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://staceyw1.wordpress.com/2011/10/08/lightswitch-timeouts-and-sessionstate-service/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4fa5b439a8f2b92717211098784f9867?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">staceyw1</media:title>
		</media:content>

		<media:content url="http://staceyw1.files.wordpress.com/2011/10/image_thumb.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>LightSwitch and Slot number order for Auditions Sample</title>
		<link>http://staceyw1.wordpress.com/2011/07/12/lightswitch-and-slot-number-order-for-auditions-sample/</link>
		<comments>http://staceyw1.wordpress.com/2011/07/12/lightswitch-and-slot-number-order-for-auditions-sample/#comments</comments>
		<pubDate>Tue, 12 Jul 2011 07:30:00 +0000</pubDate>
		<dc:creator>staceyw1</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[LightSwitch]]></category>
		<category><![CDATA[LightSwitch. c#]]></category>

		<guid isPermaLink="false">https://staceyw1.wordpress.com/2011/07/12/lightswitch-and-slot-number-order-for-auditions-sample/</guid>
		<description><![CDATA[Create a junction table to map Auditions to People. The AuditionSlots table will include the SlotNumber (make Unique) and the Person and Audition (make Unique). This way, slot numbers are unique per audition. Change the slot numbers to reorder acts &#8230; <a href="http://staceyw1.wordpress.com/2011/07/12/lightswitch-and-slot-number-order-for-auditions-sample/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=staceyw1.wordpress.com&amp;blog=16471264&amp;post=306&amp;subd=staceyw1&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Create a junction table to map Auditions to People. The AuditionSlots table will include the SlotNumber (make Unique) and the Person and Audition (make Unique). This way, slot numbers are unique per audition. Change the slot numbers to reorder acts and save.</p>
<p><a href="http://staceyw1.files.wordpress.com/2011/07/image.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="image" border="0" alt="image" src="http://staceyw1.files.wordpress.com/2011/07/image_thumb.png?w=611&#038;h=492" width="611" height="492"></a></p>
<p>AuditionSlots table</p>
<p><a href="http://staceyw1.files.wordpress.com/2011/07/image1.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="image" border="0" alt="image" src="http://staceyw1.files.wordpress.com/2011/07/image_thumb1.png?w=723&#038;h=516" width="723" height="516"></a></p>
<p>Auditions Table</p>
<p><a href="http://staceyw1.files.wordpress.com/2011/07/image2.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="image" border="0" alt="image" src="http://staceyw1.files.wordpress.com/2011/07/image_thumb2.png?w=686&#038;h=485" width="686" height="485"></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/staceyw1.wordpress.com/306/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/staceyw1.wordpress.com/306/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/staceyw1.wordpress.com/306/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/staceyw1.wordpress.com/306/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/staceyw1.wordpress.com/306/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/staceyw1.wordpress.com/306/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/staceyw1.wordpress.com/306/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/staceyw1.wordpress.com/306/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/staceyw1.wordpress.com/306/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/staceyw1.wordpress.com/306/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/staceyw1.wordpress.com/306/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/staceyw1.wordpress.com/306/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/staceyw1.wordpress.com/306/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/staceyw1.wordpress.com/306/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=staceyw1.wordpress.com&amp;blog=16471264&amp;post=306&amp;subd=staceyw1&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://staceyw1.wordpress.com/2011/07/12/lightswitch-and-slot-number-order-for-auditions-sample/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4fa5b439a8f2b92717211098784f9867?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">staceyw1</media:title>
		</media:content>

		<media:content url="http://staceyw1.files.wordpress.com/2011/07/image_thumb.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://staceyw1.files.wordpress.com/2011/07/image_thumb1.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://staceyw1.files.wordpress.com/2011/07/image_thumb2.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>Febco 765 Sprinkler Backflow Repair</title>
		<link>http://staceyw1.wordpress.com/2011/06/16/febco-765-sprinkler-backflow-repair/</link>
		<comments>http://staceyw1.wordpress.com/2011/06/16/febco-765-sprinkler-backflow-repair/#comments</comments>
		<pubDate>Thu, 16 Jun 2011 22:02:22 +0000</pubDate>
		<dc:creator>staceyw1</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">https://staceyw1.wordpress.com/2011/06/16/febco-765-sprinkler-backflow-repair/</guid>
		<description><![CDATA[Ok, first none technical post in a long time.&#160; It is rare when you find something that is cheaper, better, and designed better then the original repair part.&#160; This gave me some joy, so I felt it deserved a post &#8230; <a href="http://staceyw1.wordpress.com/2011/06/16/febco-765-sprinkler-backflow-repair/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=staceyw1.wordpress.com&amp;blog=16471264&amp;post=299&amp;subd=staceyw1&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Ok, first none technical post in a long time.&nbsp; It is rare when you find something that is cheaper, better, and designed better then the original repair part.&nbsp; This gave me some joy, so I felt it deserved a post for someone else.&nbsp; If you have a Febco 765 Backflow on your house for your sprinkler system (as many do), don’t buy the Febco replacement Bonnet and Poppet kit as it is junk (the rest of the unit is good).&nbsp; This Blue Heron replacement is 5 times better.&nbsp; Better plastic and better design. DIY for about $30 bucks from SpinklerWarehouse.&nbsp; A plumber or sprinkler guy will charge you $100-$200 for the repair and will probably not use this fine part.&nbsp; Even if you don’t need one yet, I would buy this, replace current and keep old one as emergency spare.</p>
<p><a href="http://staceyw1.files.wordpress.com/2011/06/febcopoppet.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="FebcoPoppet" border="0" alt="FebcoPoppet" src="http://staceyw1.files.wordpress.com/2011/06/febcopoppet_thumb.png?w=210&#038;h=244" width="210" height="244"></a></p>
<p><a title="http://www.sprinklerwarehouse.com/Blue-Heron-Replacement-Kit-Febco-p/abr091011.htm" href="http://www.sprinklerwarehouse.com/Blue-Heron-Replacement-Kit-Febco-p/abr091011.htm">http://www.sprinklerwarehouse.com/Blue-Heron-Replacement-Kit-Febco-p/abr091011.htm</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/staceyw1.wordpress.com/299/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/staceyw1.wordpress.com/299/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/staceyw1.wordpress.com/299/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/staceyw1.wordpress.com/299/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/staceyw1.wordpress.com/299/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/staceyw1.wordpress.com/299/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/staceyw1.wordpress.com/299/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/staceyw1.wordpress.com/299/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/staceyw1.wordpress.com/299/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/staceyw1.wordpress.com/299/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/staceyw1.wordpress.com/299/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/staceyw1.wordpress.com/299/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/staceyw1.wordpress.com/299/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/staceyw1.wordpress.com/299/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=staceyw1.wordpress.com&amp;blog=16471264&amp;post=299&amp;subd=staceyw1&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://staceyw1.wordpress.com/2011/06/16/febco-765-sprinkler-backflow-repair/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4fa5b439a8f2b92717211098784f9867?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">staceyw1</media:title>
		</media:content>

		<media:content url="http://staceyw1.files.wordpress.com/2011/06/febcopoppet_thumb.png" medium="image">
			<media:title type="html">FebcoPoppet</media:title>
		</media:content>
	</item>
		<item>
		<title>Switch your lights with LightSwitch</title>
		<link>http://staceyw1.wordpress.com/2011/06/13/switch-your-lights-with-lightswitch/</link>
		<comments>http://staceyw1.wordpress.com/2011/06/13/switch-your-lights-with-lightswitch/#comments</comments>
		<pubDate>Mon, 13 Jun 2011 18:37:00 +0000</pubDate>
		<dc:creator>staceyw1</dc:creator>
				<category><![CDATA[.Net Micro Framework]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[LightSwitch]]></category>
		<category><![CDATA[LED]]></category>
		<category><![CDATA[NETMF]]></category>

		<guid isPermaLink="false">https://staceyw1.wordpress.com/2011/06/13/switch-your-lights-with-lightswitch/</guid>
		<description><![CDATA[With a name like LightSwitch, you know someone had to do it eventually. Here is fun little project that combines Microsoft LightSwitch and a Microsoft Micro Framework controller to switch LEDs on and off.&#160; Here is the hardware: FEZ Panda &#8230; <a href="http://staceyw1.wordpress.com/2011/06/13/switch-your-lights-with-lightswitch/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=staceyw1.wordpress.com&amp;blog=16471264&amp;post=288&amp;subd=staceyw1&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://staceyw1.files.wordpress.com/2011/06/lighton.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="LightOn" border="0" alt="LightOn" src="http://staceyw1.files.wordpress.com/2011/06/lighton_thumb.png?w=148&#038;h=148" width="148" height="148"></a></p>
<p>With a name like LightSwitch, you know someone had to do it eventually. <img style="border-style:none;" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://staceyw1.files.wordpress.com/2011/06/wlemoticon-smile.png?w=640"></p>
<p>Here is fun little project that combines Microsoft LightSwitch and a Microsoft Micro Framework controller to switch LEDs on and off.&nbsp; Here is the hardware:</p>
<p><a href="http://staceyw1.files.wordpress.com/2011/06/lsfritzing.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="LSFritzing" border="0" alt="LSFritzing" src="http://staceyw1.files.wordpress.com/2011/06/lsfritzing_thumb.png?w=584&#038;h=282" width="584" height="282"></a></p>
<ul>
<li>FEZ Panda
<li>Breadboard small
<li>2 LEDs, one red, one green
<li>Jumper wire
<li>1 or 2 100 ohm resistors. Sharing a resistor here.</li>
</ul>
<p><a href="http://staceyw1.files.wordpress.com/2011/06/2011-06-13-14-08-17.jpg"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="2011-06-13 14.08.17" border="0" alt="2011-06-13 14.08.17" src="http://staceyw1.files.wordpress.com/2011/06/2011-06-13-14-08-17_thumb.jpg?w=375&#038;h=268" width="375" height="268"></a></p>
<p>And here is the LS screen to both control lights and see current light status:</p>
<p><a href="http://staceyw1.files.wordpress.com/2011/06/lslightscreen21.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="LSLightScreen2" border="0" alt="LSLightScreen2" src="http://staceyw1.files.wordpress.com/2011/06/lslightscreen2_thumb1.png?w=652&#038;h=498" width="652" height="498"></a></p>
<p>Below is the LS table that drives everything:</p>
<p><a href="http://staceyw1.files.wordpress.com/2011/06/lstable.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="LSTable" border="0" alt="LSTable" src="http://staceyw1.files.wordpress.com/2011/06/lstable_thumb.png?w=766&#038;h=487" width="766" height="487"></a></p>
<p>Basically, it works as follows:</p>
<ul>
<li>I hook into the tables Updating event.
<li>Inside the event, I send a single line command to the NETMF device via SerialPort.
<li>The NETMF device is listening on USB serial device in a loop reading lines and performs the on/off switching based on what light name is send in the command line.
<li>Before leaving Updating event, I update the light status to on or off to reflect its new state.
<li>After the Save, the screen reflects the new state information that was set inside the Updating event.</li>
</ul>
<pre class="csharpcode"><span class="kwrd">partial</span> <span class="kwrd">void</span> LightStatusSet_Updating(LightStatus entity)
{
    SendLightCommand(entity);

    <span class="kwrd">if</span> (!entity.LastTurnOnTime.HasValue &amp;&amp; entity.TurnOnNow)
    {
        <span class="rem">// Turn on stopwatch.</span>
        entity.LastTurnOnTime = DateTime.Now;
    }
    <span class="kwrd">else</span> <span class="kwrd">if</span> (entity.LastTurnOnTime.HasValue &amp;&amp; ! entity.TurnOnNow)
    {
        <span class="rem">// Turn off stopwatch.</span>
        TimeSpan ts = (DateTime.Now - entity.LastTurnOnTime.Value);
        entity.HoursOn += ts.TotalHours;
        entity.LastTurnOnTime = <span class="kwrd">null</span>;
    }
}</pre>
<pre class="csharpcode"><span class="kwrd">private</span> <span class="kwrd">static</span> <span class="kwrd">void</span> SendLightCommand(LightStatus entity)
{
    <span class="kwrd">if</span> (!entity.IsActive) <span class="kwrd">return</span>;
    <span class="kwrd">if</span> (port == <span class="kwrd">null</span>)
    {
        port = <span class="kwrd">new</span> SerialPort(<span class="str">"com3"</span>);
        port.Open();
        Debug.WriteLine(<span class="str">"Port opened. Send cmds."</span>);
    }

    <span class="kwrd">if</span> (entity.TurnOnNow)
    {
        port.WriteLine(entity.Name + <span class="str">",ON"</span>);
        entity.IsOn = <span class="kwrd">true</span>;
    }
    <span class="kwrd">else</span>
    {
        port.WriteLine(entity.Name + <span class="str">",OFF"</span>);
        entity.IsOn = <span class="kwrd">false</span>;
    }
}</pre>
<p>The device side is done same way. Just block reading lines from the SerialPort in a loop and handle the commands by name.&nbsp; Here is the device code:</p>
<pre class="csharpcode"><span class="kwrd">using</span> System.Threading;
<span class="kwrd">using</span> Microsoft.SPOT;
<span class="kwrd">using</span> Microsoft.SPOT.Hardware;
<span class="kwrd">using</span> GHIElectronics.NETMF.FEZ;
<span class="kwrd">using</span> GHIElectronics.NETMF.USBClient;
<span class="kwrd">using</span> System.Text;

<span class="kwrd">namespace</span> FezPandaApp1
{
    <span class="kwrd">public</span> <span class="kwrd">class</span> Program
    {
        <span class="kwrd">static</span> OutputPort sysLed;
        <span class="kwrd">static</span> OutputPort led1;
        <span class="kwrd">static</span> OutputPort led2;

        <span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">void</span> Main()
        {
            Debug.EnableGCMessages(<span class="kwrd">false</span>);
            sysLed = <span class="kwrd">new</span> OutputPort((Cpu.Pin)FEZ_Pin.Digital.LED, <span class="kwrd">false</span>);
            led1 = <span class="kwrd">new</span> OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di6, <span class="kwrd">false</span>);
            led2 = <span class="kwrd">new</span> OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di7, <span class="kwrd">false</span>);

            ReadComm();

            Debug.Print(<span class="str">"Done."</span>);
        }

        <span class="kwrd">public</span> <span class="kwrd">static</span> USBC_CDC StartCDC()
        {
            <span class="rem">// Check debug interface. We don't do this check with CDC debugging port</span>
            <span class="rem">//if (Configuration.DebugInterface.GetCurrent() == Configuration.DebugInterface.Port.USB1)</span>
            <span class="rem">//    throw new InvalidOperationException("Current debug interface is USB. It must be changed to something else before proceeding. Refer to your platform user manual to change the debug interface.");</span>

            <span class="rem">// Start CDC</span>
            Debug.Print(<span class="str">"Hit Break all. Then Continue to Init CDC."</span>);
            USBC_CDC cdc = USBClientController.StandardDevices.StartCDC_WithDebugging();

            <span class="rem">// Send "Hello world!" to PC every second. (Append a new line too)</span>
            <span class="kwrd">byte</span>[] bytes = System.Text.Encoding.UTF8.GetBytes(<span class="str">"Hello world!\r\n"</span>);

            <span class="kwrd">int</span> count = 10;
            <span class="kwrd">while</span> (count--&gt;0)
            {
                Debug.Print(<span class="str">"Sending on comm."</span>);
                <span class="rem">// Check if connected to PC</span>
                <span class="kwrd">if</span> (USBClientController.GetState() != USBClientController.State.Running)
                {
                    Debug.Print(<span class="str">"Waiting to connect to PC..."</span>);
                }
                <span class="kwrd">else</span>
                {
                    cdc.Write(bytes, 0, bytes.Length);
                }
                Thread.Sleep(500);
            }
            <span class="kwrd">return</span> cdc;
        }

        <span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">void</span> ReadComm()
        {
            USBC_CDC port = StartCDC();
            port.ReadTimeout = -1;
            <span class="kwrd">while</span> (<span class="kwrd">true</span>)
            {
                <span class="kwrd">string</span> line = CDCReadLineEx(port, 512);
                <span class="kwrd">bool</span> result = HandleCommand(line);
                <span class="kwrd">if</span> (!result) <span class="kwrd">break</span>; <span class="rem">// Exit cmd.</span>
                <span class="rem">//CDCWriteLine(port, line); // Write reply if needed.</span>
            }
        }

        <span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">bool</span> HandleCommand(<span class="kwrd">string</span> line)
        {
            <span class="kwrd">string</span>[] cmds = line.Split(<span class="str">','</span>);
            <span class="kwrd">if</span> (cmds.Length != 2) <span class="kwrd">return</span> <span class="kwrd">true</span>;
            <span class="kwrd">string</span> cmd = cmds[0].Trim().ToLower();
            <span class="kwrd">string</span> arg1 = cmds[1].Trim().ToLower();

            <span class="kwrd">switch</span> (cmd)
            {
                <span class="kwrd">case</span> <span class="str">"sys"</span>:
                    <span class="kwrd">if</span> (arg1 == <span class="str">"on"</span>)
                        sysLed.Write(<span class="kwrd">true</span>);
                    <span class="kwrd">else</span>
                        sysLed.Write(<span class="kwrd">false</span>);
                    <span class="kwrd">break</span>;
                <span class="kwrd">case</span> <span class="str">"led1"</span>:
                    <span class="kwrd">if</span> (arg1 == <span class="str">"on"</span>)
                        led1.Write(<span class="kwrd">true</span>);
                    <span class="kwrd">else</span>
                        led1.Write(<span class="kwrd">false</span>);
                    <span class="kwrd">break</span>;
                <span class="kwrd">case</span> <span class="str">"led2"</span>:
                    <span class="kwrd">if</span> (arg1 == <span class="str">"on"</span>)
                        led2.Write(<span class="kwrd">true</span>);
                    <span class="kwrd">else</span>
                        led2.Write(<span class="kwrd">false</span>);
                    <span class="kwrd">break</span>;
                <span class="kwrd">case</span> <span class="str">"exit"</span>:
                    <span class="kwrd">return</span> <span class="kwrd">false</span>;
                <span class="kwrd">default</span>: <span class="rem">// Ignore</span>
                    <span class="kwrd">break</span>;
            }
            <span class="kwrd">return</span> <span class="kwrd">true</span>;
        }

        <span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">int</span> CDCWriteLine(USBC_CDC port, <span class="kwrd">string</span> line)
        {
            <span class="kwrd">byte</span>[] bytes = Encoding.UTF8.GetBytes(line+<span class="str">"\n"</span>);
            <span class="kwrd">return</span> port.Write(bytes, 0, bytes.Length);
        }

        <span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">string</span> CDCReadLineEx(USBC_CDC sr, <span class="kwrd">int</span> bufLen)
        {
            <span class="kwrd">char</span>[] readLineBuff = <span class="kwrd">new</span> <span class="kwrd">char</span>[bufLen];
            <span class="kwrd">int</span> curPos = 0;
            <span class="kwrd">byte</span>[] ba = <span class="kwrd">new</span> <span class="kwrd">byte</span>[1];
            <span class="kwrd">while</span> (<span class="kwrd">true</span>)
            {
                <span class="kwrd">int</span> read = sr.Read(ba, 0, 1);
                <span class="kwrd">if</span> (read &lt;= 0) <span class="kwrd">break</span>;
                readLineBuff[curPos] = (<span class="kwrd">char</span>)ba[0];
                <span class="kwrd">if</span> (readLineBuff[curPos] == <span class="str">'\n'</span>)
                {
                    <span class="kwrd">return</span> <span class="kwrd">new</span> <span class="kwrd">string</span>(readLineBuff, 0, curPos);
                }
                curPos++;
            }

            <span class="kwrd">if</span> (curPos == 0) <span class="kwrd">return</span> <span class="kwrd">null</span>; <span class="rem">// Null fix.</span>
            <span class="kwrd">return</span> <span class="kwrd">new</span> <span class="kwrd">string</span>(readLineBuff, 0, curPos);
        }
    }
}</pre>
<p>For this sample, we are just switching LEDs. But you could easily switch actual lights and other high power devices by adding Relays and/or MOSFETs to the setup.</p>
<p>Cool thing about using LightSwitch for this is it is already internet-ready and multi-user ready.&nbsp; So deploy to the cloud and switch your lights over the internet.</p>
<p>So what if your LightSwitch server is hosted at a provider or not near your light sources?&nbsp; Good news. You are covered there also. Instead of using a serial port, you can hook your NETMF device to Ethernet or wireless instead.&nbsp; Do some port forwarding and/or open up your NAT at home and your LS server can send commands to your public facing NAT IP address which can forward to your FEZ.&nbsp; You could also create a WCF RIA service on some box at home (or work) and talk to it from the LS server side.&nbsp; You have many options with some imagination.&nbsp; Just don’t open up your screen to the public if you don’t want your lights blinking on and off! <img style="border-style:none;" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://staceyw1.files.wordpress.com/2011/06/wlemoticon-smile.png?w=640"></p>
<p>Have fun and post blogs of your project !</p>
<p>&#8211;William Stacey</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/staceyw1.wordpress.com/288/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/staceyw1.wordpress.com/288/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/staceyw1.wordpress.com/288/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/staceyw1.wordpress.com/288/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/staceyw1.wordpress.com/288/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/staceyw1.wordpress.com/288/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/staceyw1.wordpress.com/288/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/staceyw1.wordpress.com/288/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/staceyw1.wordpress.com/288/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/staceyw1.wordpress.com/288/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/staceyw1.wordpress.com/288/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/staceyw1.wordpress.com/288/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/staceyw1.wordpress.com/288/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/staceyw1.wordpress.com/288/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=staceyw1.wordpress.com&amp;blog=16471264&amp;post=288&amp;subd=staceyw1&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://staceyw1.wordpress.com/2011/06/13/switch-your-lights-with-lightswitch/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4fa5b439a8f2b92717211098784f9867?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">staceyw1</media:title>
		</media:content>

		<media:content url="http://staceyw1.files.wordpress.com/2011/06/lighton_thumb.png" medium="image">
			<media:title type="html">LightOn</media:title>
		</media:content>

		<media:content url="http://staceyw1.files.wordpress.com/2011/06/wlemoticon-smile.png" medium="image">
			<media:title type="html">Smile</media:title>
		</media:content>

		<media:content url="http://staceyw1.files.wordpress.com/2011/06/lsfritzing_thumb.png" medium="image">
			<media:title type="html">LSFritzing</media:title>
		</media:content>

		<media:content url="http://staceyw1.files.wordpress.com/2011/06/2011-06-13-14-08-17_thumb.jpg" medium="image">
			<media:title type="html">2011-06-13 14.08.17</media:title>
		</media:content>

		<media:content url="http://staceyw1.files.wordpress.com/2011/06/lslightscreen2_thumb1.png" medium="image">
			<media:title type="html">LSLightScreen2</media:title>
		</media:content>

		<media:content url="http://staceyw1.files.wordpress.com/2011/06/lstable_thumb.png" medium="image">
			<media:title type="html">LSTable</media:title>
		</media:content>

		<media:content url="http://staceyw1.files.wordpress.com/2011/06/wlemoticon-smile.png" medium="image">
			<media:title type="html">Smile</media:title>
		</media:content>
	</item>
		<item>
		<title>NETMF Get/Set Real Time Clock (RTC)</title>
		<link>http://staceyw1.wordpress.com/2011/04/22/netmf-getset-real-time-clock-rtc/</link>
		<comments>http://staceyw1.wordpress.com/2011/04/22/netmf-getset-real-time-clock-rtc/#comments</comments>
		<pubDate>Sat, 23 Apr 2011 02:18:00 +0000</pubDate>
		<dc:creator>staceyw1</dc:creator>
				<category><![CDATA[.Net Micro Framework]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[DateTime]]></category>
		<category><![CDATA[FEZ]]></category>
		<category><![CDATA[NETMF]]></category>
		<category><![CDATA[RTC]]></category>

		<guid isPermaLink="false">https://staceyw1.wordpress.com/2011/04/22/netmf-getset-real-time-clock-rtc/</guid>
		<description><![CDATA[Just a short reminder post on how to get and set RTC.&#160; The RTC is powered by VBatt pin and keeps the RTC ticking with the time after you set it once.&#160; After you set it, then just read the &#8230; <a href="http://staceyw1.wordpress.com/2011/04/22/netmf-getset-real-time-clock-rtc/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=staceyw1.wordpress.com&amp;blog=16471264&amp;post=278&amp;subd=staceyw1&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Just a short reminder post on how to get and set RTC.&nbsp; The RTC is powered by VBatt pin and keeps the RTC ticking with the time after you set it once.&nbsp; After you set it, then just read the time on boot and set the system clock.</p>
<pre class="csharpcode"><span class="kwrd">private</span> <span class="kwrd">static</span> DateTime SetDateTimeFromRTC()
{
    <span class="rem">// RealTimeClock.SetTime(new DateTime(2011, 4, 22, 1, 1, 1, 0)); // Set once to set the RTC.</span>
    DateTime dt = RealTimeClock.GetTime(); <span class="rem">// Get RTC time.</span>
    Utility.SetLocalTime(dt); <span class="rem">// Set system clock.</span>
    <span class="kwrd">return</span> dt;
}</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/staceyw1.wordpress.com/278/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/staceyw1.wordpress.com/278/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/staceyw1.wordpress.com/278/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/staceyw1.wordpress.com/278/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/staceyw1.wordpress.com/278/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/staceyw1.wordpress.com/278/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/staceyw1.wordpress.com/278/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/staceyw1.wordpress.com/278/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/staceyw1.wordpress.com/278/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/staceyw1.wordpress.com/278/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/staceyw1.wordpress.com/278/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/staceyw1.wordpress.com/278/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/staceyw1.wordpress.com/278/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/staceyw1.wordpress.com/278/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=staceyw1.wordpress.com&amp;blog=16471264&amp;post=278&amp;subd=staceyw1&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://staceyw1.wordpress.com/2011/04/22/netmf-getset-real-time-clock-rtc/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4fa5b439a8f2b92717211098784f9867?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">staceyw1</media:title>
		</media:content>
	</item>
		<item>
		<title>FEZ firmware update helper</title>
		<link>http://staceyw1.wordpress.com/2011/04/21/fez-firmware-update-helper/</link>
		<comments>http://staceyw1.wordpress.com/2011/04/21/fez-firmware-update-helper/#comments</comments>
		<pubDate>Fri, 22 Apr 2011 00:43:00 +0000</pubDate>
		<dc:creator>staceyw1</dc:creator>
				<category><![CDATA[.Net Micro Framework]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[FEZ]]></category>
		<category><![CDATA[Firmware]]></category>

		<guid isPermaLink="false">https://staceyw1.wordpress.com/2011/04/21/fez-firmware-update-helper/</guid>
		<description><![CDATA[Just wanted a reminder post when I have to update FEZ with new firmware. Update Fez Firmware1) Hold LDR button then plug in USB.&#160; New comm port should appear in devices (i.e. comm13)2) Open TeraTerm3) Erase current with E4) Load &#8230; <a href="http://staceyw1.wordpress.com/2011/04/21/fez-firmware-update-helper/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=staceyw1.wordpress.com&amp;blog=16471264&amp;post=277&amp;subd=staceyw1&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Just wanted a reminder post when I have to update FEZ with new firmware.</p>
<p>Update Fez Firmware<br />1) Hold LDR button then plug in USB.&nbsp; New comm port should appear in devices (i.e. comm13)<br />2) Open TeraTerm<br />3) Erase current with E<br />4) Load new firmware with X from location (e.g. C:\Program Files (x86)\GHI Electronics\GHI NETMF v4.1 SDK\USBizi\Firmware)<br />5) Use XModem and 1K transfer.<br />6) Update your GHI references in your project(s) by removing them and adding them back. Create a screen snip of references before removing them to help remember which to add back.</p>
<p>Can also use MFDeploy to verify version before and after or just to check what level.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/staceyw1.wordpress.com/277/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/staceyw1.wordpress.com/277/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/staceyw1.wordpress.com/277/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/staceyw1.wordpress.com/277/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/staceyw1.wordpress.com/277/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/staceyw1.wordpress.com/277/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/staceyw1.wordpress.com/277/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/staceyw1.wordpress.com/277/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/staceyw1.wordpress.com/277/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/staceyw1.wordpress.com/277/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/staceyw1.wordpress.com/277/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/staceyw1.wordpress.com/277/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/staceyw1.wordpress.com/277/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/staceyw1.wordpress.com/277/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=staceyw1.wordpress.com&amp;blog=16471264&amp;post=277&amp;subd=staceyw1&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://staceyw1.wordpress.com/2011/04/21/fez-firmware-update-helper/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4fa5b439a8f2b92717211098784f9867?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">staceyw1</media:title>
		</media:content>
	</item>
		<item>
		<title>NETMF Servo classes (PWM and Software versions)</title>
		<link>http://staceyw1.wordpress.com/2011/04/19/netmf-servo-classes-pwm-and-software-versions/</link>
		<comments>http://staceyw1.wordpress.com/2011/04/19/netmf-servo-classes-pwm-and-software-versions/#comments</comments>
		<pubDate>Tue, 19 Apr 2011 04:13:00 +0000</pubDate>
		<dc:creator>staceyw1</dc:creator>
				<category><![CDATA[.Net Micro Framework]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[FEZ]]></category>
		<category><![CDATA[Motors]]></category>
		<category><![CDATA[Servo]]></category>
		<category><![CDATA[NETMF]]></category>
		<category><![CDATA[PWM]]></category>

		<guid isPermaLink="false">https://staceyw1.wordpress.com/2011/04/19/netmf-servo-classes-pwm-and-software-versions/</guid>
		<description><![CDATA[Just posting some servo classes.&#160; One for hardware PWM control and one for software PWM using OutputCompare. Never know when you may need. using System; using GHIElectronics.NETMF.FEZ; using GHIElectronics.NETMF.Hardware; namespace MicroFezRobot { public class ServoHardPWM : IServo { readonly PWM &#8230; <a href="http://staceyw1.wordpress.com/2011/04/19/netmf-servo-classes-pwm-and-software-versions/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=staceyw1.wordpress.com&amp;blog=16471264&amp;post=276&amp;subd=staceyw1&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Just posting some servo classes.&nbsp; One for hardware PWM control and one for software PWM using OutputCompare. Never know when you may need.</p>
<pre class="csharpcode"><span class="kwrd">using</span> System;
<span class="kwrd">using</span> GHIElectronics.NETMF.FEZ;
<span class="kwrd">using</span> GHIElectronics.NETMF.Hardware;

<span class="kwrd">namespace</span> MicroFezRobot
{
    <span class="kwrd">public</span> <span class="kwrd">class</span> ServoHardPWM : IServo
    {
        <span class="kwrd">readonly</span> PWM pwm;
        <span class="kwrd">readonly</span> <span class="kwrd">uint</span> periodUs;     <span class="rem">// Number of us in period.</span>
        <span class="kwrd">readonly</span> <span class="kwrd">uint</span> periodNs;     <span class="rem">// Number of ns in period.</span>
        <span class="kwrd">readonly</span> <span class="kwrd">uint</span> lowDegree;    <span class="rem">// Low degree of servo; 0 default.</span>
        <span class="kwrd">readonly</span> <span class="kwrd">uint</span> highDegree;   <span class="rem">// High degree of servo; 180 default.</span>
        <span class="kwrd">uint</span> lowUs = 690;           <span class="rem">// microsecond (us) range. Find your specific values with servo range testing.</span>
        <span class="kwrd">uint</span> highUs = 2422;         <span class="rem">// microsecond (us) range.</span>
        <span class="kwrd">bool</span> invert;                <span class="rem">// Invert/reverse rotation.</span>
        DateTime lastChanged;

        <span class="kwrd">public</span> ServoHardPWM(FEZ_Pin.PWM pin, <span class="kwrd">uint</span> periodUs=20000, <span class="kwrd">uint</span> lowUs=1000, <span class="kwrd">uint</span> highUs=2000, <span class="kwrd">uint</span> lowDegree=0, <span class="kwrd">uint</span> highDegree=180)
        {
            <span class="kwrd">this</span>.periodUs = periodUs;
            <span class="kwrd">this</span>.periodNs = <span class="kwrd">this</span>.periodUs * 1000;
            <span class="kwrd">this</span>.lowUs = lowUs;
            <span class="kwrd">this</span>.highUs = highUs;
            <span class="kwrd">this</span>.lowDegree = lowDegree;
            <span class="kwrd">this</span>.highDegree = highDegree;
            <span class="kwrd">this</span>.pwm = <span class="kwrd">new</span> PWM((PWM.Pin)pin);
            pwm.Set(<span class="kwrd">false</span>);
            <span class="kwrd">this</span>.lastChanged = DateTime.Now;
        }

        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// Gets or sets value to invert direction.</span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="kwrd">public</span> <span class="kwrd">bool</span> Invert
        {
            get { <span class="kwrd">return</span> invert; }
            set { <span class="kwrd">this</span>.invert = <span class="kwrd">value</span>; }
        }

        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// Gets number of microseconds (us) in the period.</span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="kwrd">public</span> <span class="kwrd">uint</span> Period
        {
            get { <span class="kwrd">return</span> periodUs / 1000; }
        }

        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// Gets or sets number of microseconds (us) in low servo range.</span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="kwrd">public</span> <span class="kwrd">uint</span> LowRange
        {
            get { <span class="kwrd">return</span> <span class="kwrd">this</span>.lowUs; }
            set { <span class="kwrd">this</span>.lowUs = <span class="kwrd">value</span>; }
        }

        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// Gets or sets number of microseconds (us) in high servo range.</span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="kwrd">public</span> <span class="kwrd">uint</span> HighRange
        {
            get { <span class="kwrd">return</span> <span class="kwrd">this</span>.highUs; }
            set { <span class="kwrd">this</span>.highUs = <span class="kwrd">value</span>; }
        }

        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// Gets datetime position was last changed.</span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="kwrd">public</span> DateTime LastChanged
        {
            get { <span class="kwrd">return</span> <span class="kwrd">this</span>.lastChanged; }
        }

        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// Sets current servo angle degree.</span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="rem">/// &lt;param name="degree"&gt;Degree to set. (i.e. 0-180)&lt;/param&gt;</span>
        <span class="kwrd">public</span> <span class="kwrd">void</span> SetDegree(<span class="kwrd">uint</span> degree)
        {
            <span class="kwrd">if</span> (degree &lt; lowDegree || degree &gt; highDegree)
                <span class="kwrd">throw</span> <span class="kwrd">new</span> ArgumentOutOfRangeException(<span class="str">"angleDegree"</span>);

            <span class="kwrd">uint</span> posUs = ScaleRange(degree, lowDegree, highDegree, lowUs, highUs);
            SetPosition(posUs);
        }

        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// Sets current servo position.</span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="rem">/// &lt;param name="positionUs"&gt;High time in microseconds.&lt;/param&gt;</span>
        <span class="kwrd">public</span> <span class="kwrd">void</span> SetPosition(<span class="kwrd">uint</span> positionUs)
        {
            <span class="kwrd">if</span> (invert)
                positionUs = (highUs - positionUs) + lowUs;

            <span class="kwrd">uint</span> posNs = positionUs * 1000; <span class="rem">// convert us to ns as SetPulse uses ns scale.</span>
            pwm.SetPulse(periodNs, posNs);
            <span class="kwrd">this</span>.lastChanged = DateTime.Now;
        }

        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// Stops holding servo at current position by setting PWM low.</span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="kwrd">public</span> <span class="kwrd">void</span> Stop()
        {
            pwm.Set(<span class="kwrd">false</span>);
        }

        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// Dispose servo instance.</span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="kwrd">public</span> <span class="kwrd">void</span> Dispose()
        {
            <span class="rem">// Try to stop servo clean on a pulse low.</span>
            Stop();
            pwm.Dispose();
        }

        <span class="kwrd">private</span> <span class="kwrd">static</span> <span class="kwrd">uint</span> ScaleRange(<span class="kwrd">uint</span> oldValue, <span class="kwrd">uint</span> oldMin, <span class="kwrd">uint</span> oldMax, <span class="kwrd">uint</span> newMin, <span class="kwrd">uint</span> newMax)
        {
            <span class="kwrd">return</span> ((oldValue - oldMin) * (newMax - newMin) / (oldMax - oldMin)) + newMin;
        }
    }
}

<span class="kwrd">using</span> System;
<span class="kwrd">using</span> GHIElectronics.NETMF.FEZ;
<span class="kwrd">using</span> GHIElectronics.NETMF.Hardware;
<span class="kwrd">using</span> Microsoft.SPOT.Hardware;

<span class="kwrd">namespace</span> MicroFezRobot
{
    <span class="kwrd">interface</span> IServo : IDisposable
    {
        <span class="kwrd">bool</span> Invert { get; set; }
        <span class="kwrd">uint</span> Period { get; }
        <span class="kwrd">uint</span> LowRange { get; set; }
        <span class="kwrd">uint</span> HighRange { get; set; }
        DateTime LastChanged { get; }
        <span class="kwrd">void</span> SetDegree(<span class="kwrd">uint</span> angleDegree);
        <span class="kwrd">void</span> SetPosition(<span class="kwrd">uint</span> position);
        <span class="kwrd">void</span> Stop();
    }

    <span class="kwrd">public</span> <span class="kwrd">class</span> ServoSoftPWM : IServo
    {
        <span class="kwrd">readonly</span> OutputCompare oc;
        <span class="kwrd">readonly</span> <span class="kwrd">uint</span> periodUs;     <span class="rem">// Normally 20,000us (i.e. 20ms)</span>
        <span class="kwrd">readonly</span> <span class="kwrd">uint</span> lowDegree;    <span class="rem">// Low degree of servo; 0 default.</span>
        <span class="kwrd">readonly</span> <span class="kwrd">uint</span> highDegree;   <span class="rem">// High degree of servo; 180 default.</span>
        <span class="kwrd">readonly</span> <span class="kwrd">uint</span>[] timings;    <span class="rem">// Used for setting OC timings.</span>
        <span class="kwrd">uint</span> lowUs;                 <span class="rem">// Small servo (e.g. 690)</span>
        <span class="kwrd">uint</span> highUs;                <span class="rem">// Small servo (e.g. 2422)</span>
        <span class="kwrd">bool</span> invert;                <span class="rem">// Invert servo direction control.</span>
        DateTime lastChanged;

        <span class="kwrd">public</span> ServoSoftPWM(FEZ_Pin.Digital pin, <span class="kwrd">uint</span> periodUs=20000, <span class="kwrd">uint</span> lowUs=1000, <span class="kwrd">uint</span> highUs=2000, <span class="kwrd">uint</span> lowDegree=0, <span class="kwrd">uint</span> highDegree=180)
        {
            <span class="kwrd">this</span>.oc = <span class="kwrd">new</span> OutputCompare((Cpu.Pin)pin, <span class="kwrd">true</span>, 2);
            <span class="kwrd">this</span>.timings = <span class="kwrd">new</span> <span class="kwrd">uint</span>[2];
            <span class="kwrd">this</span>.periodUs = periodUs;
            <span class="kwrd">this</span>.lowUs = lowUs;
            <span class="kwrd">this</span>.highUs = highUs;
            <span class="kwrd">this</span>.lowDegree = lowDegree;
            <span class="kwrd">this</span>.highDegree = highDegree;
            <span class="kwrd">this</span>.lastChanged = DateTime.Now;
        }

        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// Gets or sets a value to invert the servo direction.</span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="kwrd">public</span> <span class="kwrd">bool</span> Invert
        {
            get { <span class="kwrd">return</span> <span class="kwrd">this</span>.invert; }
            set { <span class="kwrd">this</span>.invert = <span class="kwrd">value</span>; }
        }

        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// Gets the period in microseconds.</span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="kwrd">public</span> <span class="kwrd">uint</span> Period
        {
            get { <span class="kwrd">return</span> <span class="kwrd">this</span>.periodUs; }
        }

        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// Gets or sets the low servo range in microseconds.</span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="kwrd">public</span> <span class="kwrd">uint</span> LowRange
        {
            get { <span class="kwrd">return</span> <span class="kwrd">this</span>.lowUs; }
            set { <span class="kwrd">this</span>.lowUs = <span class="kwrd">value</span>; }
        }

        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// Gets or sets the high servo range in microseconds.</span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="kwrd">public</span> <span class="kwrd">uint</span> HighRange
        {
            get { <span class="kwrd">return</span> <span class="kwrd">this</span>.highUs; }
            set { <span class="kwrd">this</span>.highUs = <span class="kwrd">value</span>; }
        }

        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// Gets datetime of last position change.</span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="kwrd">public</span> DateTime LastChanged
        {
            get { <span class="kwrd">return</span> <span class="kwrd">this</span>.lastChanged; }
        }

        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// Sets the current servo angle in degrees.</span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="rem">/// &lt;param name="degree"&gt;Degree angle to set.&lt;/param&gt;</span>
        <span class="kwrd">public</span> <span class="kwrd">void</span> SetDegree(<span class="kwrd">uint</span> degree)
        {
            <span class="kwrd">if</span> (degree &lt; lowDegree || degree &gt; highDegree)
                <span class="kwrd">throw</span> <span class="kwrd">new</span> ArgumentOutOfRangeException(<span class="str">"angleDegree"</span>);

            <span class="kwrd">uint</span> highTime = ScaleRange(degree, lowDegree, highDegree, lowUs, highUs);
            SetPosition(highTime);
        }

        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// Sets the current position of the servo.</span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="rem">/// &lt;param name="positionUs"&gt;Position in microseconds&lt;/param&gt;</span>
        <span class="kwrd">public</span> <span class="kwrd">void</span> SetPosition(<span class="kwrd">uint</span> positionUs)
        {
            <span class="kwrd">if</span> (positionUs &lt; lowUs || positionUs &gt; highUs)
                <span class="kwrd">throw</span> <span class="kwrd">new</span> ArgumentOutOfRangeException(<span class="str">"positionUs"</span>);

            <span class="kwrd">if</span> (invert)
                positionUs = (highUs - positionUs) + lowUs;

            <span class="rem">// OutputCompare uses microsecond (us) scale.</span>
            timings[0] = positionUs;
            timings[1] = periodUs - positionUs;
            oc.Set(<span class="kwrd">true</span>, timings, 0, 2, <span class="kwrd">true</span>);
            <span class="kwrd">this</span>.lastChanged = DateTime.Now;
        }

        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// Stops holding servo at current position by setting PWM low.</span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="kwrd">public</span> <span class="kwrd">void</span> Stop()
        {
            oc.Set(<span class="kwrd">false</span>);
        }

        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// Dispose servo instance.</span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="kwrd">public</span> <span class="kwrd">void</span> Dispose()
        {
            Stop();
            oc.Dispose();
        }

        <span class="kwrd">private</span> <span class="kwrd">static</span> <span class="kwrd">uint</span> ScaleRange(<span class="kwrd">uint</span> <span class="kwrd">value</span>, <span class="kwrd">uint</span> oldMin, <span class="kwrd">uint</span> oldMax, <span class="kwrd">uint</span> newMin, <span class="kwrd">uint</span> newMax)
        {
            <span class="kwrd">uint</span> v = ((<span class="kwrd">value</span> - oldMin) * (newMax - newMin) / (oldMax - oldMin)) + newMin; <span class="rem">// same good.</span>
            <span class="kwrd">return</span> v;
        }
    }
}</pre>
<p>-William</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/staceyw1.wordpress.com/276/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/staceyw1.wordpress.com/276/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/staceyw1.wordpress.com/276/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/staceyw1.wordpress.com/276/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/staceyw1.wordpress.com/276/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/staceyw1.wordpress.com/276/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/staceyw1.wordpress.com/276/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/staceyw1.wordpress.com/276/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/staceyw1.wordpress.com/276/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/staceyw1.wordpress.com/276/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/staceyw1.wordpress.com/276/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/staceyw1.wordpress.com/276/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/staceyw1.wordpress.com/276/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/staceyw1.wordpress.com/276/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=staceyw1.wordpress.com&amp;blog=16471264&amp;post=276&amp;subd=staceyw1&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://staceyw1.wordpress.com/2011/04/19/netmf-servo-classes-pwm-and-software-versions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4fa5b439a8f2b92717211098784f9867?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">staceyw1</media:title>
		</media:content>
	</item>
		<item>
		<title>NETMF Joystick Shield Driver</title>
		<link>http://staceyw1.wordpress.com/2011/04/12/netmf-joystick-shield-driver/</link>
		<comments>http://staceyw1.wordpress.com/2011/04/12/netmf-joystick-shield-driver/#comments</comments>
		<pubDate>Tue, 12 Apr 2011 06:45:00 +0000</pubDate>
		<dc:creator>staceyw1</dc:creator>
				<category><![CDATA[.Net Micro Framework]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[FEZ]]></category>
		<category><![CDATA[Robotics]]></category>
		<category><![CDATA[Electronics]]></category>
		<category><![CDATA[Joystick]]></category>
		<category><![CDATA[NETMF]]></category>
		<category><![CDATA[Shield]]></category>

		<guid isPermaLink="false">https://staceyw1.wordpress.com/2011/04/12/netmf-joystick-shield-driver/</guid>
		<description><![CDATA[Adding a joystick to your NETMF device is easy with the Sparkfun joystick shield and the following code. /* Copyright 2011 William Stacey Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in &#8230; <a href="http://staceyw1.wordpress.com/2011/04/12/netmf-joystick-shield-driver/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=staceyw1.wordpress.com&amp;blog=16471264&amp;post=273&amp;subd=staceyw1&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Adding a joystick to your NETMF device is easy with the <a href="http://www.sparkfun.com/products/9760" target="_blank">Sparkfun</a> joystick shield and the following code.</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:8747F07C-CDE8-481f-B0DF-C6CFD074BF67:4deabf91-8a22-4b3f-937d-55a3a1300315" class="wlWriterEditableSmartContent"><a href="http://staceyw1.files.wordpress.com/2011/04/joystick-8x6.jpg" title="" rel="thumbnail"><img border="0" src="http://staceyw1.files.wordpress.com/2011/04/joystick.png?w=335&#038;h=335" width="335" height="335" /></a></div>
<pre class="csharpcode"><span class="rem">/*</span>
<span class="rem">Copyright 2011 William Stacey</span>
<span class="rem">Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at</span>
<span class="rem">http://www.apache.org/licenses/LICENSE-2.0</span>
<span class="rem">Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. </span>
<span class="rem">*/</span>
<span class="kwrd">using</span> System;
<span class="kwrd">using</span> Microsoft.SPOT;
<span class="kwrd">using</span> GHIElectronics.NETMF.Hardware;
<span class="kwrd">using</span> Microsoft.SPOT.Hardware;
<span class="kwrd">using</span> GHIElectronics.NETMF.FEZ;

<span class="kwrd">namespace</span> RobotJoystickRemote
{
    <span class="rem">/// &lt;summary&gt;</span>
    <span class="rem">/// Joystick class to control Sparkfun's Joystick Shield kit.</span>
    <span class="rem">/// http://www.sparkfun.com/products/9760</span>
    <span class="rem">/// This class uses the GHI Button class found here:</span>
    <span class="rem">/// http://www.ghielectronics.com/downloads/FEZ/Component/FEZ_Components_Button.cs</span>
    <span class="rem">/// &lt;/summary&gt;</span>
    <span class="kwrd">public</span> <span class="kwrd">class</span> JoystickShield
    {
        <span class="kwrd">public</span> <span class="kwrd">event</span> FEZ_Components.Button.ButtonPressEventHandler UpClick;
        <span class="kwrd">public</span> <span class="kwrd">event</span> FEZ_Components.Button.ButtonPressEventHandler DownClick;
        <span class="kwrd">public</span> <span class="kwrd">event</span> FEZ_Components.Button.ButtonPressEventHandler LeftClick;
        <span class="kwrd">public</span> <span class="kwrd">event</span> FEZ_Components.Button.ButtonPressEventHandler RightClick;
        <span class="kwrd">public</span> <span class="kwrd">event</span> FEZ_Components.Button.ButtonPressEventHandler JoystickClick;

        AnalogIn xPin;
        AnalogIn yPin;
        FEZ_Components.Button joyClick;
        FEZ_Components.Button up;
        FEZ_Components.Button down;
        FEZ_Components.Button left;
        FEZ_Components.Button right;

        <span class="kwrd">public</span> JoystickShield()
        {
            <span class="rem">// Hookup Joystick.</span>
            xPin = <span class="kwrd">new</span> AnalogIn(AnalogIn.Pin.Ain0);
            yPin = <span class="kwrd">new</span> AnalogIn(AnalogIn.Pin.Ain1);
            xPin.SetLinearScale(-100, 101);
            yPin.SetLinearScale(-100, 101);
            joyClick = <span class="kwrd">new</span> FEZ_Components.Button(FEZ_Pin.Interrupt.Di2);
            joyClick.ButtonPressEvent += (FEZ_Pin.Interrupt pin, FEZ_Components.Button.ButtonState state) =&gt;
            {
                var ev = JoystickClick;
                <span class="kwrd">if</span> (ev != <span class="kwrd">null</span>)
                    ev(pin, state);
            };

            <span class="rem">// Hookup push buttons.</span>
            up = <span class="kwrd">new</span> FEZ_Components.Button(FEZ_Pin.Interrupt.Di4);
            down = <span class="kwrd">new</span> FEZ_Components.Button(FEZ_Pin.Interrupt.Di5);
            left = <span class="kwrd">new</span> FEZ_Components.Button(FEZ_Pin.Interrupt.Di6);
            right = <span class="kwrd">new</span> FEZ_Components.Button(FEZ_Pin.Interrupt.Di3);
            up.ButtonPressEvent += (FEZ_Pin.Interrupt pin, FEZ_Components.Button.ButtonState state) =&gt;
            {
                var ev = UpClick;
                <span class="kwrd">if</span> (ev != <span class="kwrd">null</span>)
                    ev(pin, state);
            };
            down.ButtonPressEvent += (FEZ_Pin.Interrupt pin, FEZ_Components.Button.ButtonState state) =&gt;
            {
                var ev = DownClick;
                <span class="kwrd">if</span> (ev != <span class="kwrd">null</span>)
                    ev(pin, state);
            };
            left.ButtonPressEvent += (FEZ_Pin.Interrupt pin, FEZ_Components.Button.ButtonState state) =&gt;
            {
                var ev = LeftClick;
                <span class="kwrd">if</span> (ev != <span class="kwrd">null</span>)
                    ev(pin, state);
            };
            right.ButtonPressEvent += (FEZ_Pin.Interrupt pin, FEZ_Components.Button.ButtonState state) =&gt;
            {
                var ev = RightClick;
                <span class="kwrd">if</span> (ev != <span class="kwrd">null</span>)
                    ev(pin, state);
            };
        }

        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// Gets joystick X position.</span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="kwrd">public</span> <span class="kwrd">int</span> X
        {
            get { <span class="kwrd">return</span> xPin.Read(); }
        }

        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// Gets joystick Y position.</span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="kwrd">public</span> <span class="kwrd">int</span> Y
        {
            get { <span class="kwrd">return</span> yPin.Read(); }
        }

        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// Sets the X and Y scale of the joystick.</span>
        <span class="rem">/// Default scale is -100 minimum to 101 maximum. Max scale is non-inclusive.</span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="kwrd">public</span> <span class="kwrd">void</span> SetScale(<span class="kwrd">int</span> minX=-100, <span class="kwrd">int</span> maxX=101, <span class="kwrd">int</span> minY=-100, <span class="kwrd">int</span> maxY=101)
        {
            xPin.SetLinearScale(minX, maxX);
            yPin.SetLinearScale(minY, maxY);
        }

        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// Gets current X and Y position of joystick.</span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="kwrd">public</span> JoyPosition Position
        {
            get
            {
                JoyPosition jp = <span class="kwrd">new</span> JoyPosition();
                jp.X = xPin.Read();
                jp.Y = yPin.Read();
                <span class="kwrd">return</span> jp;
            }
        }
    }

    <span class="kwrd">public</span> <span class="kwrd">struct</span> JoyPosition
    {
        <span class="kwrd">public</span> <span class="kwrd">int</span> X;
        <span class="kwrd">public</span> <span class="kwrd">int</span> Y;
        <span class="kwrd">public</span> <span class="kwrd">override</span> <span class="kwrd">string</span> ToString()
        {
            <span class="kwrd">return</span> <span class="str">"X: "</span> + X + <span class="str">" Y: "</span> + Y;
        }
    }
}</pre>
<p>Have fun.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/staceyw1.wordpress.com/273/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/staceyw1.wordpress.com/273/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/staceyw1.wordpress.com/273/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/staceyw1.wordpress.com/273/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/staceyw1.wordpress.com/273/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/staceyw1.wordpress.com/273/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/staceyw1.wordpress.com/273/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/staceyw1.wordpress.com/273/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/staceyw1.wordpress.com/273/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/staceyw1.wordpress.com/273/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/staceyw1.wordpress.com/273/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/staceyw1.wordpress.com/273/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/staceyw1.wordpress.com/273/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/staceyw1.wordpress.com/273/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=staceyw1.wordpress.com&amp;blog=16471264&amp;post=273&amp;subd=staceyw1&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://staceyw1.wordpress.com/2011/04/12/netmf-joystick-shield-driver/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4fa5b439a8f2b92717211098784f9867?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">staceyw1</media:title>
		</media:content>

		<media:content url="http://staceyw1.files.wordpress.com/2011/04/joystick.png" medium="image" />
	</item>
		<item>
		<title>Saleae Logic Review</title>
		<link>http://staceyw1.wordpress.com/2011/04/11/saleae-logic-review/</link>
		<comments>http://staceyw1.wordpress.com/2011/04/11/saleae-logic-review/#comments</comments>
		<pubDate>Mon, 11 Apr 2011 06:02:00 +0000</pubDate>
		<dc:creator>staceyw1</dc:creator>
				<category><![CDATA[.Net Micro Framework]]></category>
		<category><![CDATA[FEZ]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Diagnostics]]></category>
		<category><![CDATA[Electronics]]></category>
		<category><![CDATA[Servo]]></category>

		<guid isPermaLink="false">https://staceyw1.wordpress.com/2011/04/11/saleae-logic-review/</guid>
		<description><![CDATA[Received my Saleae Logic today. I did not think I would ever need one. But had an issue with PWM and controlling a servo from my FEZ board. Something like a logic analyzer is really the only way to drill &#8230; <a href="http://staceyw1.wordpress.com/2011/04/11/saleae-logic-review/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=staceyw1.wordpress.com&amp;blog=16471264&amp;post=269&amp;subd=staceyw1&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Received my Saleae Logic today. <img style="border-style:none;" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://staceyw1.files.wordpress.com/2011/04/wlemoticon-smile1.png?w=640"></p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:8747F07C-CDE8-481f-B0DF-C6CFD074BF67:c46a296f-1f60-480d-9bc8-5934bd5c415a" class="wlWriterEditableSmartContent"><a href="http://staceyw1.files.wordpress.com/2011/04/saleaelogic-8x6.jpg" title="" rel="thumbnail"><img border="0" src="http://staceyw1.files.wordpress.com/2011/04/saleaelogic.png?w=335&#038;h=258" width="335" height="258" /></a></div>
<p> I did not think I would ever need one. But had an issue with PWM and controlling a servo from my FEZ board. Something like a logic analyzer is really the only way to drill down and get hard evidence and stop guessing what is happening.&nbsp; Can save hours of testing.&nbsp; Anyway, I like bullet points, so here are the pros and cons.</p>
<p>Pros</p>
<ul>
<li>Nice looking hardware. Compact and elegant design.</li>
<li>Nice software. It takes a lot of work to make a really good simple abstraction.&nbsp; And it shows.</li>
<li>Capture and timing accuracy seems right on as one would hope.</li>
<li>The micro-hook probes seem are nice quality.&nbsp; The wires connectors are a bit hard to press into the hooks.</li>
<li>Nice case to store everything in.</li>
</ul>
<p>Cons:</p>
<ul>
<li>Software crashed a few times first couple times I used it. No message, just closed.&nbsp; Once doing an Export and once after setting another trigger on a different line. The 1.5 Beta seemed to solve those issues.</li>
<li>Limited documentation.&nbsp; Not even a quick start on how to hook it up.&nbsp; If this is your first analyzer, it is not obvious how to get started.&nbsp; The wire connector is not keyed, so you can incorrectly connect it (which Spark Fun says could damage it).&nbsp; Also, Black wire is normally ground, but not on this harness.&nbsp; Grey is ground and Black is pin 1. Very strange choice considering we have black (or even green) burnt into our brains as GND.&nbsp; I could guess that you need to hook ground wire to a ground on your circuit and one test wire to what you are testing – but it would be helpful to at least supply a one page document in the product to verify your assumptions instead of hoping your right.</li>
<li>They do have some limited documentation for the software online, but it is pretty thin.&nbsp; For such a well thought out device, the lack of good docs seem odd.</li>
<li>Some choices on UX not in my taste.&nbsp; For example, it would seem natural to click on square wave thinking you will get the details of the wave on the right and to make those details “sticky”.&nbsp; Instead, clicking on anything on the wave zooms down.&nbsp; There is no way to make wave details “stick” on right if you want to screen capture the details of that period.</li>
</ul>
<p>Despite some of the minor cons, this is a great little integrated device and worth the $149.&nbsp; If you don’t already have one, I would put on your wish list.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/staceyw1.wordpress.com/269/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/staceyw1.wordpress.com/269/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/staceyw1.wordpress.com/269/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/staceyw1.wordpress.com/269/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/staceyw1.wordpress.com/269/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/staceyw1.wordpress.com/269/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/staceyw1.wordpress.com/269/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/staceyw1.wordpress.com/269/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/staceyw1.wordpress.com/269/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/staceyw1.wordpress.com/269/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/staceyw1.wordpress.com/269/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/staceyw1.wordpress.com/269/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/staceyw1.wordpress.com/269/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/staceyw1.wordpress.com/269/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=staceyw1.wordpress.com&amp;blog=16471264&amp;post=269&amp;subd=staceyw1&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://staceyw1.wordpress.com/2011/04/11/saleae-logic-review/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4fa5b439a8f2b92717211098784f9867?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">staceyw1</media:title>
		</media:content>

		<media:content url="http://staceyw1.files.wordpress.com/2011/04/wlemoticon-smile1.png" medium="image">
			<media:title type="html">Smile</media:title>
		</media:content>

		<media:content url="http://staceyw1.files.wordpress.com/2011/04/saleaelogic.png" medium="image" />
	</item>
		<item>
		<title>Simple servo control from FEZ</title>
		<link>http://staceyw1.wordpress.com/2011/04/10/simple-servo-control-from-fez/</link>
		<comments>http://staceyw1.wordpress.com/2011/04/10/simple-servo-control-from-fez/#comments</comments>
		<pubDate>Sun, 10 Apr 2011 21:27:00 +0000</pubDate>
		<dc:creator>staceyw1</dc:creator>
				<category><![CDATA[.Net Micro Framework]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[FEZ]]></category>
		<category><![CDATA[Robotics]]></category>
		<category><![CDATA[Servo]]></category>
		<category><![CDATA[NETMF]]></category>

		<guid isPermaLink="false">https://staceyw1.wordpress.com/2011/04/10/simple-servo-control-from-fez/</guid>
		<description><![CDATA[If you just need the easiest possible way to hook up a servo to FEZ, it does not get easier then this.&#160; No breadboards, mosfets, or resistors.&#160; Just hook the servo wires into the fez and control.&#160; If your servo &#8230; <a href="http://staceyw1.wordpress.com/2011/04/10/simple-servo-control-from-fez/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=staceyw1.wordpress.com&amp;blog=16471264&amp;post=265&amp;subd=staceyw1&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>If you just need the easiest possible way to hook up a servo to FEZ, it does not get easier then this.&nbsp; No breadboards, mosfets, or resistors.&nbsp; Just hook the servo wires into the fez and control.&nbsp; If your servo has a normal 3 pin female connector, then just get some male-to-male jumper wires and your done.&nbsp; Use a PWM pin to control the servo’s signal wire.&nbsp; The 5v on the FEZ should be enough for small to medium servos.&nbsp; If you need more, then power from external supply.</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:8747F07C-CDE8-481f-B0DF-C6CFD074BF67:507eaaa8-adae-4a9e-aded-6cf1a456a4e2" class="wlWriterEditableSmartContent"><a href="http://staceyw1.files.wordpress.com/2011/04/fezsimpleservo-8x6.jpg" title="" rel="thumbnail"><img border="0" src="http://staceyw1.files.wordpress.com/2011/04/fezsimpleservo.png?w=484&#038;h=580" width="484" height="580" /></a></div>
<pre class="csharpcode"><span class="kwrd">const</span> <span class="kwrd">uint</span> PERIOD = 20 * 1000 * 1000; <span class="rem">// 20ms is 20000000ms(nanoseconds)</span>
<span class="kwrd">const</span> <span class="kwrd">uint</span> LowUs = 690;   <span class="rem">// min range of servo as microseconds.</span>
<span class="kwrd">const</span> <span class="kwrd">uint</span> HighUs = 2422; <span class="rem">// max range of servo as microseconds.</span>

<span class="rem">/// &lt;summary&gt;</span>
<span class="rem">/// Set servo position.</span>
<span class="rem">/// &lt;/summary&gt;</span>
<span class="rem">/// &lt;remarks&gt;</span>
<span class="rem">/// The standard range for 180degree servos is 1 to 2 milliseconds high in a 20ms period, with</span>
<span class="rem">/// neutral in the middle at 1.5ms. Exact range varies between servos. Find exact range with</span>
<span class="rem">/// a servo tester or PWM range testing.</span>
<span class="rem">/// &lt;/remarks&gt;</span>
<span class="rem">/// &lt;param name="servo"&gt;PWM pin of servo control.&lt;/param&gt;</span>
<span class="rem">/// &lt;param name="highUs"&gt;High time in microseconds (e.g. 1500us is 1.5ms or neutral)&lt;/param&gt;</span>
<span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">void</span> SetSimpleServo(PWM servo, <span class="kwrd">uint</span> highUs)
{
    Debug.Print(<span class="str">"Set servo nanoseconds: "</span> + highUs);
    servo.SetPulse(PERIOD, highUs * 1000);
}

<span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">void</span> SetSimpleServoByDegree(PWM servo, <span class="kwrd">byte</span> degree, <span class="kwrd">bool</span> invert)
{
    <span class="kwrd">if</span> (degree &lt; 0 || degree &gt; 180)
        <span class="kwrd">throw</span> <span class="kwrd">new</span> ArgumentOutOfRangeException(<span class="str">"angleDegree"</span>);

    <span class="kwrd">if</span> (invert)
        degree = (<span class="kwrd">byte</span>)(180 - degree);

    <span class="rem">// Scale degree (0-180) to servo position. Mult 1K to get to nanoseconds.</span>
    <span class="kwrd">uint</span> pos = ScaleRange((<span class="kwrd">uint</span>)degree, 0, 180, LowUs, HighUs) * 1000;
    servo.SetPulse(PERIOD, pos);

    Debug.Print(<span class="str">"Degree:"</span> + degree + <span class="str">" Position ms:"</span> + pos / (<span class="kwrd">double</span>)1000000);
}

<span class="kwrd">private</span> <span class="kwrd">static</span> <span class="kwrd">uint</span> ScaleRange(<span class="kwrd">uint</span> oldValue, <span class="kwrd">uint</span> oldMin, <span class="kwrd">uint</span> oldMax, <span class="kwrd">uint</span> newMin, <span class="kwrd">uint</span> newMax)
{
    <span class="kwrd">return</span> ((oldValue - oldMin) * (newMax - newMin) / (oldMax - oldMin)) + newMin;
}</pre>
<p>-William</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/staceyw1.wordpress.com/265/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/staceyw1.wordpress.com/265/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/staceyw1.wordpress.com/265/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/staceyw1.wordpress.com/265/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/staceyw1.wordpress.com/265/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/staceyw1.wordpress.com/265/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/staceyw1.wordpress.com/265/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/staceyw1.wordpress.com/265/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/staceyw1.wordpress.com/265/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/staceyw1.wordpress.com/265/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/staceyw1.wordpress.com/265/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/staceyw1.wordpress.com/265/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/staceyw1.wordpress.com/265/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/staceyw1.wordpress.com/265/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=staceyw1.wordpress.com&amp;blog=16471264&amp;post=265&amp;subd=staceyw1&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://staceyw1.wordpress.com/2011/04/10/simple-servo-control-from-fez/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4fa5b439a8f2b92717211098784f9867?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">staceyw1</media:title>
		</media:content>

		<media:content url="http://staceyw1.files.wordpress.com/2011/04/fezsimpleservo.png" medium="image" />
	</item>
	</channel>
</rss>
