Pages: [1]   Go Down
Author Topic: specifying digital or analog pin?  (Read 618 times)
0 Members and 1 Guest are viewing this topic.
The people's republic of Massachusetts
Offline Offline
Full Member
***
Karma: 0
Posts: 135
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?  smiley-confuse
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 551
Posts: 46215
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

The people's republic of Massachusetts
Offline Offline
Full Member
***
Karma: 0
Posts: 135
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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);

 
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 551
Posts: 46215
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

The people's republic of Massachusetts
Offline Offline
Full Member
***
Karma: 0
Posts: 135
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 551
Posts: 46215
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

The people's republic of Massachusetts
Offline Offline
Full Member
***
Karma: 0
Posts: 135
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks  smiley-cool
Logged

Pages: [1]   Go Up
Jump to: