Go Down

Topic: specifying digital or analog pin? (Read 790 times) previous topic - next topic

2660

I have a MEGA 128 that has two sets of 0-15 pins, the analog ones and the digital ones.

How do I specify what pin is used?  :~

PaulS

Quote
How do I specify what pin is used?

The function you use defines that. The analogRead() function reads the analog pins. The digitalRead() doesn't.

2660

I though I needed to specify what the pins are used for?

Like this:
Quote

  pinMode(select_button_pin, INPUT);
  pinMode(zone_1_sensor, INPUT);



PaulS

The pinMode function defines whether a given pin that can be input or output IS input or output. The analog pins are input only, so there is no need to call the pinMode function to say that an analog pin is an input pin.

2660

That makes sense for the analog, should pinMode then be set for all the digital I/O that can go each way?


PaulS

Quote
should pinMode then be set for all the digital I/O that can go each way?

For all the ones that matter, yes. If the pin isn't used, there's no reason to set the mode.


Go Up