Defining a set of pins as digital input in one statement

Hi -

For one of my project, I'm using around 30 digital pins(finding it tedious to write to define each one of them as digital input),and want to define all of them as input - with just one statement!

Wondering if there is one, would be grateful if shown a way to do it and syntax, (below is example - a small portion of the coding)

int sen[]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31};
#define pinMode(A0, INPUT);
#define pinMode(A1, INPUT);
#define pinMode(A2, INPUT);
#define pinMode(A3, INPUT);
#define pinMode(A4, INPUT);
#define pinMode(A5, INPUT);
#define pinMode(A6, INPUT);
#define pinMode(A7, INPUT);

...................

...........
void setup() {

for(int i;i<32;i+1)
{
PinMode(sen*,LOW);*
}

I'm learning! thanks, could you pl help with how to designate many pins as Digital inputs in one statement

Delta_G already told you; replace LOW by INPUT.

sterretje:
Delta_G already told you; replace LOW by INPUT.

Put he didn't post it so I can just copy and paste :sob: :sob: :sob: :sob: :sob:

.

rockwellramesha:

for(int i; i<32; i++) {

pinMode(sen[i], INPUT);
}

That IS one statement. If you meant "one line" then:

for(int i; i<32; i++) {PinMode(sen[i], INPUT);}

(C++ doesn't generally care about space, tab, and newline characters between tokens.)

Delta_G, direct port manipulation - thanks for this tip

Also, pins DEFAULT to "INPUT" (possibly not including the analog pins), so you don't really need to configure them at all.

rockwellramesha:
For one of my project, I'm using around 30 digital pins(finding it tedious to write to define each one of them as digital input),and want to define all of them as input - with just one statement!

You could use

;

if you insist in using one statement to initialize all inputs (in setup), because

westfw:
pins DEFAULT to "INPUT" (possibly not including the analog pins), so you don't really need to configure them at all.

And another single statement that does the trick (using a comma expression):

  pinMode(sen[0], INPUT),  pinMode(sen[1], INPUT),  pinMode(sen[2], INPUT),  pinMode(sen[3], INPUT),  pinMode(sen[4], INPUT),  pinMode(sen[5], INPUT),  pinMode(sen[6], INPUT),  pinMode(sen[7], INPUT),  pinMode(sen[8], INPUT),  pinMode(sen[9], INPUT),  pinMode(sen[10], INPUT),  pinMode(sen[11], INPUT),  pinMode(sen[12], INPUT),  pinMode(sen[13], INPUT),  pinMode(sen[14], INPUT),  pinMode(sen[15], INPUT),  pinMode(sen[16], INPUT),  pinMode(sen[17], INPUT),  pinMode(sen[18], INPUT),  pinMode(sen[19], INPUT),  pinMode(sen[20], INPUT),  pinMode(sen[21], INPUT),  pinMode(sen[22], INPUT),  pinMode(sen[23], INPUT),  pinMode(sen[24], INPUT),  pinMode(sen[25], INPUT),  pinMode(sen[26], INPUT),  pinMode(sen[27], INPUT),  pinMode(sen[28], INPUT),  pinMode(sen[29], INPUT),  pinMode(sen[30], INPUT), pinMode(sen[31], INPUT);
int sen[]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31};

Good idea using an array. Bad idea using pins 0 and 1 on most Arduinos. Which Arduino is this for?

You don't need any of those #-defines.

Note that you can use the names printed on the PCB as the names for the pins. You might use...

int sen[]={A0,A1,A2,SDA,SCL,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31};

On some Arduinos, you even have names like TXLED as an addressable pin.

Mega2560, I've moved to pins beginning 22(realized errors!).Thx John Wasser, Delta_G and MorganS