Listing 1: A complete .NET Micro Framework flashlight

using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
namespace MicroFrameworkFlashlight
{
public class MicroFrameworkFlashlight
{
public static void Main()
{
Cpu.Pin lampPin = Cpu.Pin.GPIO_Pin1;
Cpu.Pin switchPin = Cpu.Pin.GPIO_Pin2;
OutputPort lampOutput = new OutputPort(lampPin, false);
InputPort switchInput = new InputPort(switchPin, false,
Port.ResistorMode.PullDown);
while (true)
{
lampOutput.Write(switchInput.Read());
}
}
}
}

Listing 2: A .NET Micro Framework flashlight that uses interrupts

using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
namespace MicroFrameworkFlashlight
{
public class MicroFrameworkFlashlight
{
static OutputPort lampOutput;
static InterruptPort switchInterrupt;
public static void Main()
{
Cpu.Pin lampPin = Cpu.Pin.GPIO_Pin1;
Cpu.Pin switchPin = Cpu.Pin.GPIO_Pin2;
lampOutput = new OutputPort(lampPin, false);
switchInterrupt =
new InterruptPort(
switchPin,
false,
Port.ResistorMode.PullDown,
Port.InterruptMode.InterruptEdgeBoth);
switchInterrupt.OnInterrupt +=
new GPIOInterruptEventHandler(switchInterrupt_OnInterrupt);
while (true)
{
System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);
}
}
static void switchInterrupt_OnInterrupt(Cpu.Pin port, bool state, TimeSpan time)
{
lampOutput.Write(state);
}
}
}