Pushing the Onboard Button

Both Netduino and Netduino Plus have an on onboard pushbutton labeled SW1. You can read the digital value of this pushbutton—true or false—to determine whether it is currently being pushed. Then you can take actions based on that pushbutton’s current state, such as turning an LED on and off or instructing a Netduino-powered robot to start moving its motors.

Note

By default, this pushbutton will reboot your Netduino and restart your current Netduino app. But because of a special configuration in the Netduino’s circuitry, it can alternatively be used as a digital input.

In Visual Studio, create a new project by selecting New Project in the File menu. Select Netduino Application as the template as before, and give your project a name such as “Pushbutton1.” Finally, double-click on Program.cs in the Solution Explorer to begin editing it.

In the main section of the Visual Studio editor, you are again editing Program.cs. Click on the line underneath the text // write your code here.

Now, type the following:

OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);1
InputPort button = 
  new InputPort(Pins.ONBOARD_SW1, false, Port.ResistorMode.Disabled);2
bool buttonState = false;

As with the previous example, the first line of code creates an OutputPort so that you can turn ...

Get Getting Started with Netduino 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.