What We're DoingUp to this point we have focused entirely on outputs, time to get our Netduino to listen, watch and feel. We'll start with a simple pushbutton. Wiring up the pushbutton is easy. There is one component, the pull up resistor, that might seem out of place. This is included because a Netduino doesn't sense the same way we do (ie button pressed, button unpressed). Instead it looks at the voltage on the pin and decides whether it is HIGH or LOW. The button is set up to pull the Netduino's pin LOW when it is pressed, however, when the button is unpressed the voltage of the pin will float (causing occasional errors). To get the Netduino to reliably read the pin as HIGH when the button is unpressed, we add the pull up resistor.

public static void Main() /// The Main loop (run at power up) ///
{
/// Setup Portion of Program, runs once at startup ///
while (true) /// Do Forever ///
{
turnLEDOnWithButton(); //Turns the LED on when button one is pre //ssed and off when not
//turnLEDOnOffWithButtons(); //Turns the LED on when button 1 is press //ed and off when button 2 is pressed
} /// Close Forever Loop ///
} /// Close the Main() Loop ///

///
/// If button 1 is pressed the light is turned on if it isn't the light is turned of //f
///
static void turnLEDOnWithButton()
{
//a false condition means the button is being pressed
if (button1.Read()) //Checks if the button is pressed
{
led.Write(false); //If button 1 isn't pressed turn the light off
}
else
{
led.Write(true); //If button 1 is pressed turn the light on
}
}

Light Not Turning On The pushbutton is square and because of this it is easy to put it in the wrong way. Give it a 90 degree twist and see if it starts working.

Light Not Fading A bit of a silly mistake we constantly made, when you switch from simple on off to fading remember to move the LED wire from pin 13 to pin 9.

Underwhelmed? No worries these nciruits are all super stripped down to make playing with the components easy, but once you throw them together the sky is the limit.

Making it Better?

On button off button:The initial example may be a little underwhelming (ie. I don't really need an Netduino to do this), let's make it a little more complicated. One button will turn the LED on the other will turn the LED off. Change the code after while (true) to:

//turnLEDOnWithButton(); turnLEDOnOffWithButtons();

Debug the program to your board, and start toggling the LED on and off.

Fading up and down:Lets use the buttons to control an analog signal. To do this you will need to change the wire connecting the LED from pin 13 to pin 9.