Overview
This example demonstrates how to blink an LED connected to a Netduino board. An LED is nothing more than a small light which like any other light be turned on and off on command. In this case it is toggled through code.
Code Sample
using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;
namespace LEDBlinkingExample
{
public class Program
{
public static void Main()
{
// write your code here
OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);
while (true)
{
led.Write(true);
Thread.Sleep(250);
led.Write(false);
Thread.Sleep(250);
}
}
}
}
Details
There is one primary object created here. The LED object which happens to be an OutputPort. The next part is a loop which blinks the LED on and off.
For those of you not familiar with Threading in .NET take this into mind. There are two calls to Thread.Sleep(..). This does nothing more than “sleep” (i.e. PAUSE) a thread for a given time frame. In this case, 250 milliseconds each time it is called.
Video Tutorial
The following video is brought to you buy Secret Labs. They have created a nifty video which shows you all the details and lays it out in great detail.