Menu

reading a pushed button?

Help
2008-03-18
2013-05-30
  • Nobody/Anonymous

    how do you read whether a button is pushed or not
    eg. if the button is pushed turn on a light
    thanks

     
    • Hugh Considine

      Hugh Considine - 2008-03-19

      How is the button connected?

      If the button is connected between Vcc and the input, and there is a 10k or so resistor between the input and ground, then the pin will be on when the button is pressed and off when the button is released (active high).

      If the button is connected between ground and the input, and the resistor is connected between Vcc and the input, then the pin will be on when the button is released and off when the button is pressed (active low).

      Reading the pin is pretty simple. If you're reading from PORTB bit 2 for example, then this is the code you need:

      If PORTB.2 = On Then
      'Code to run if pin is on
      Else
      'Code to run if pin is off
      End If

      You can omit the Else if it is not needed.

       
      • Nobody/Anonymous

        thanks for the help

         

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.