6 years, 3 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" ?

Comment on this question

1 Answer

6 years, 3 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:

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.

You need to log in to post a question