Created
November 21, 2012 04:22
-
-
Save scottheckel/4123006 to your computer and use it in GitHub Desktop.
Simple Netduino Project – Toggle LED
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.SPOT.Hardware; | |
using Netduino = SecretLabs.NETMF.Hardware.Netduino; | |
namespace ToggleLED | |
{ | |
/// <summary> | |
/// Toggle the Netduino LED on/off based on a button press. | |
/// </summary> | |
public class Program | |
{ | |
/// <summary>Main</summary> | |
public static void Main() | |
{ | |
bool isOn = false; // initial state of LED | |
bool lastButtonState = true; // assume button initially not pressed | |
// Create our LED/Button objects | |
OutputPort led = new OutputPort(Netduino.Pins.ONBOARD_LED, isOn); | |
InputPort button = new InputPort(Netduino.Pins.ONBOARD_SW1, false, Port.ResistorMode.Disabled); | |
// Loop forever reading the button and turning on/off the LED | |
while (true) | |
{ | |
bool buttonState = button.Read(); | |
// Toggle light only if the Button is pushed | |
if (buttonState != lastButtonState && !buttonState) | |
{ | |
isOn = !isOn; | |
led.Write(isOn); | |
} | |
// Store current state as last state | |
lastButtonState = buttonState; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment