You probably wanted to attach the other pin to the 3.3V Vout. It sounds like you got it figured out, but I'll include some info just in case.
You might be interested in learning about pullup and pulldown resistors. By default the mbed is set to use an internal pulldown resistor, which will make the voltage go to zero when your push-switch is turned off.
If you wanted, you could connect the other pin of your switch to the ground instead and change the pin to pullup mode using the built-in mode function.
The code using a pullup resistor should look something like this:
#include "mbed.h"
DigitalIn myInputPin(p5);
int main() {
myInputPin.mode(PullUp); //set the mbed to use a pullup resistor
while(1) {
if(myInputPin.read()==1) { //a shorter way to write this is: if(myInputPin){
//insert code to do something if the input value is 1.
}
}
}
Hi,
I would like to test use the digital in function to trigger the input signal (0,1).Example: if i want to install push-On switch to simulate the trigger function,1 pin connect to the Mbed pin5 and another pin should connect to which Mbed pin?sorry, i am newbie..Thanks for help
Cheers,
Charles