A Complete Program—A Flashlight Using Interrupts
We can now make a flashlight that operates under interrupt control (Example 4-2).
Example 4-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); ...
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.