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

pushing the button sample


  • Please log in to reply
3 replies to this topic

#1 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 15 June 2011 - 06:25 PM

Another simple VB-sample:

Imports Microsoft.SPOT
Imports Microsoft.SPOT.Hardware
Imports SecretLabs.NETMF.Hardware
Imports SecretLabs.NETMF.Hardware.Netduino

Module Module1

    Sub Main()
        Dim Led As OutputPort = New OutputPort(Pins.ONBOARD_LED, False)
        Dim Button As InputPort = New InputPort(Pins.ONBOARD_SW1, False, ResistorModes.PullUp)

        Do While True
            Led.Write(Button.Read())
        Loop


    End Sub

End Module

When the onboard button is pushed, the led will light up

Attached Files


"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#2 Anthony Glenwright

Anthony Glenwright

    Advanced Member

  • Members
  • PipPipPip
  • 71 posts

Posted 25 June 2011 - 07:19 AM

I hope I'm not misunderstanding, but when I tried your code it seems that ONBOARD_SW1 is back-to-front. That is, Button.Read() returns true when the switch is NOT being pressed, and false when it is. So should be "When the onboard button is pushed, the led will light up" really read "When the onboard button is pushed, the led will turn off"? PS: Thanks for the post though. Post like these are really helping me to learn how to program the Netduino.

#3 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 25 June 2011 - 07:45 AM

So should be "When the onboard button is pushed, the led will light up" really read "When the onboard button is pushed, the led will turn off"?

HI Anthony,

Welcome to the Netduino community and thanks for your feedback :)

When I wrote the code the result was actually how I described it in the first post, but I was a bit surprised as well. I think with a newer version of the beta release they've fixed something. In C# it was indeed inverted. Going to test it again later today and if needed I'll modify my code :)
That's the fun of beta software, things are always open for changes! :D
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#4 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 25 June 2011 - 05:50 PM

That is, Button.Read() returns true when the switch is NOT being pressed, and false when it is.

Technically, it is correct - the Read() method returns state of the pin (logic level) and the switch is wired in [very common] way that it causes logic low on the pin when pressed. As Stefan mentioned, it was changed in 4.2 beta firmware to match the button state (i.e. button state = pin state inverted).




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.