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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
how do you read whether a button is pushed or not
eg. if the button is pushed turn on a light
thanks
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.
thanks for the help