Arduino Forum

Using Arduino => Programming Questions => Topic started by: 2632 on Jan 30, 2012, 01:11 am

Title: specifying digital or analog pin?
Post by: 2632 on Jan 30, 2012, 01:11 am
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?  :~
Title: Re: specifying digital or analog pin?
Post by: PaulS on Jan 30, 2012, 01:26 am
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.
Title: Re: specifying digital or analog pin?
Post by: 2632 on Jan 30, 2012, 01:30 am
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);


Title: Re: specifying digital or analog pin?
Post by: PaulS on Jan 30, 2012, 01:31 am
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.
Title: Re: specifying digital or analog pin?
Post by: 2632 on Jan 30, 2012, 01:36 am
That makes sense for the analog, should pinMode then be set for all the digital I/O that can go each way?

Title: Re: specifying digital or analog pin?
Post by: PaulS on Jan 30, 2012, 01:38 am
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.
Title: Re: specifying digital or analog pin?
Post by: 2632 on Jan 30, 2012, 01:39 am
Thanks  8)