A First Program
The .NET Micro Framework exposes the hardware by means of an object model. This little snippet of code should give you some idea of how this works, and also how similar/identical the code looks to C# programs for PCs.
public static void Main()
{
Microsoft.SPOT.Hardware.Cpu.Pin ledPin =
Microsoft.SPOT.Hardware.Stamp.Pins.GPIO9_SER2_TDX;
Microsoft.SPOT.Hardware.OutputPort ledOutput =
new Microsoft.SPOT.Hardware.OutputPort(ledPin, true);
while (true)
{
ledOutput.Write(false);
System.Threading.Thread.Sleep(500);
ledOutput.Write(true);
System.Threading.Thread.Sleep(500);
}
}
The program will simply flash a led connected to one of the pins. An OutputPort instance is created from that pin and then methods on the instance are called to set the output high (true) and low (false). Note that the standard thread management code is used to pause the program for half a second after each change of state of the led.
Reader Comments (10)
Please contiunue this blog with more samples about .net micro framework. I was trying your example code, but I can't find the assembly of
Microsoft.SPOT.Hardware.Stamp.Pins
there is Cpu.Pin but no Stamp.Pins. How is this possible?
can you please provide a step by step procedure to develop a simple program on .net micro framework using Visual C# which will help beginers like me.
http://www.microsoft.com/netmf/default.mspx