Pinmode on multiple pins

My robot arm needs 4 pins for each encoder. Is there a way to set pinMode for multiple inputs at once?
Or do I have to do them all individually?
Thanks,John

Example

pinMode (2,3,4,5, INPUT_PULLUP);

No. Put them in an array and loop through it.

Do you have an example on how to do that?

not tested

const byte inPutPins[] = {2,3,4,5,6};

#define NUM   sizeof(inPutPins) / sizeof(inPutPins[0])


for ( byte x = 0; x < NUM; x++ ) {
  pinMode(inPutPins[x],INPUT_PULLUP);
}

since they're bytes

1 Like

You can use a for/next loop
Along the lines of …


for ( x=3; x<6 ; x++)
{ 
pinMode (x,OUTPUT); 
}

Which arduino?

What is "next loop" in C/C++?

1 Like

not tested

void setup() {
//pinMode (2,3,4,5, INPUT_PULLUP);
DDRD &= B11000011;
PORTD |= B01111100;
}

What makes you think OP is using an Arduino board with an AVR processor?

It’s a description of the function that explains what it does it’s not code and certainly different to a previous loop

Great AVR hack. I love uber efficient AVR code, but it's not portable and unless a uS or two at startup is important, portability is probably better.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.