A Complete Program—Our First Flashlight

Example 4-1 is version 1.0 of our computer-controlled flashlight.

Example 4-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());
         }
      }
   }
}

This program implements a very simple push-button flashlight. When the input is set to high, the program switches the lamp on. When the Main method ...

Get Embedded Programming with the Microsoft® .NET Micro Framework now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.