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

Programming using the ! modifier


Best Answer netiness, 21 November 2013 - 03:58 PM

Since led2 is an OutputPort, you will have to write

led2.Write(!led1.Read());

led2 and led are instances of the [color=rgb(40,40,40);font-family:helvetica, arial, sans-serif;]Microsoft.SPOT.Hardware.OutputPort class; look up the public methods and properties as to what you can do with them.[/color]

 

Kjetil

Go to the full post


  • Please log in to reply
2 replies to this topic

#1 vader7071

vader7071

    Advanced Member

  • Members
  • PipPipPip
  • 132 posts
  • LocationDothan, AL

Posted 21 November 2013 - 03:42 PM

I hope I am using the terminology correct.

 

I am just learning the Netduino and prgramming, and I read where you can use the following code for a button read:

 

buttonState = !button.Read():

 

and this will invert the input.  I tried using this concept on another line and VS 2012 pro is giving me an error.  I used:

 

led2 = !led1;  (failed) {error message Error 1 Operator '!' cannot be applied to operand of type 'Microsoft.SPOT.Hardware.OutputPort' c:...Blink-shieldProgram.cs 28 24 Blink-shield}

 

and

 

led2 = !led1.Read();  (failed as well) {error message Error 1 Cannot implicitly convert type 'bool' to 'Microsoft.SPOT.Hardware.OutputPort' c:...Blink-shieldProgram.cs 28 24 Blink-shield}

 

Am I trying to use this in a way not designed, or is my syntax wrong?

 

Guys, I know I am throwing a bunch of questions out here, and thank you for all of your help getting me up and going.



#2 netiness

netiness

    Member

  • Members
  • PipPip
  • 10 posts
  • LocationNorway

Posted 21 November 2013 - 03:58 PM   Best Answer

Since led2 is an OutputPort, you will have to write

led2.Write(!led1.Read());

led2 and led are instances of the [color=rgb(40,40,40);font-family:helvetica, arial, sans-serif;]Microsoft.SPOT.Hardware.OutputPort class; look up the public methods and properties as to what you can do with them.[/color]

 

Kjetil



#3 vader7071

vader7071

    Advanced Member

  • Members
  • PipPipPip
  • 132 posts
  • LocationDothan, AL

Posted 21 November 2013 - 04:16 PM

That fixed it.  Thank you!

 

Now to continue playing around and see what other randomly useless code I can come up with to learn this new toy.






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.