Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

ButtonApp question

Button normally-open

  • Please log in to reply
1 reply to this topic

#1 Dr Who

Dr Who

    Advanced Member

  • Members
  • PipPipPip
  • 261 posts
  • LocationNYC

Posted 11 July 2013 - 04:13 PM

[font="'lucida sans unicode', 'lucida grande', sans-serif;"]Hello![/font]

[font="'lucida sans unicode', 'lucida grande', sans-serif;"]After successfully restoring my Netduino, see http://forums.netdui...ond/#entry51353 for further details; I then turned towards confirming that all of the other well known applications to work, I then selected the regular button one. The button worn on the regular unchanged Netduino model 1 is in fact advertised in the catalogs for its parts happens to be a normally-open style. However when running the unchanged button code it behaves as a normally-closed one. Here:[/font]

using System;using System.Threading;using Microsoft.SPOT;using Microsoft.SPOT.Hardware;using SecretLabs.NETMF.Hardware;using SecretLabs.NETMF.Hardware.Netduino;/* NOTE: make sure you change the deployment target from the Emulator to your Netduino before running this * Netduino sample app.  To do this, select "Project menu > ButtonApp Properties > .NET Micro Framework" and  * then change the Transport type to USB.  Finally, close the ButtonApp properties tab to save these settings. */namespace ButtonApp{    public class Program    {        public static void Main()        {            // write your code here            OutputPort led = new OutputPort(Pins.ONBOARD_LED, true);            InputPort button = new InputPort(Pins.ONBOARD_SW1, true, Port.ResistorMode.Disabled);            bool buttonState = true;            while (true)            {                buttonState = button.Read();                led.Write(!buttonState);            }        }    }}

[font="'lucida sans unicode', 'lucida grande', sans-serif;"]I say unchanged because as it happens naturally I loaded it into my regular IDE for this, VS2010 Express, the C Sharp one, and told the system to go off and run it. In fact this is my second-go-round with the program as I've just returned to the family and am pursuing a more complicated application. I decided to try out the examples. [/font]

 

[font="'lucida sans unicode', 'lucida grande', sans-serif;"]Upon reading the description of the code in the book that's supposed to travel with these Netduinos, it is the use of the bang, or exclamation point as a not operator has the button state being interpreted that way. Nice![/font]



Doctor Who
"This signature does not exist!"

#2 iced98lx

iced98lx

    Advanced Member

  • Members
  • PipPipPip
  • 134 posts
  • LocationSouth Dakota

Posted 11 July 2013 - 08:36 PM

Ah, booleans are our friends.

 

For those that did not keep up with the Dr what he is pointing out is the cleverness of this line:

 

[color=rgb(0,0,0);font-family:monospace;font-size:13px;]led[/color][color=rgb(102,102,0);font-family:monospace;font-size:13px;].[/color][color=rgb(102,0,102);font-family:monospace;font-size:13px;]Write[/color][color=rgb(102,102,0);font-family:monospace;font-size:13px;](![/color][color=rgb(0,0,0);font-family:monospace;font-size:13px;]buttonState[/color][color=rgb(102,102,0);font-family:monospace;font-size:13px;]); [/color]

 

Which translates to

 

Write to the LED (either true or false) the opposite of whatever the state of the button is (true or false)







Also tagged with one or more of these keywords: Button, normally-open

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.