Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
11 years, 9 months ago.
DigitalIn switch_input(p5); switch_input.mode(PullUp); what's the meaning?
DigitalIn switch_input(p5); int switch_on = 0; switch_input.mode(PullUp); // a switch_on = switch_input; // b
I use mechanical switch in p5.
what's the meaning "switch_input.mode(PullUp) " ?
When switch pull up, check the signal of that?
What's different "a" and "b" ?
1 Answer
11 years, 9 months ago.
switch_input.mode(Pullup) tells the compiler to use the internal resisters to pull-up the value on pin 5. It doesn't check the signal for the line: it just says use the internal resisters in pull-up mode, rather than pull-down or an external resistor on that pin.
See here: http://en.wikipedia.org/wiki/Pull-up_resistor
switch_input() should actually read the value of the switch at that moment.
You would call .mode() once, before of the general "while (1)" loop, and the "switch_input" within the loop, to see if the switch had been triggered.