Set pinMode via const array for pin numbers?

Status
Not open for further replies.

oddson

Well-known member
Set pinMode via const array for pin numbers? (sorted sort of)

Code:
const int SO_PINS[4] = {12,1,2,3}; //array size is (M_PINS)^-2

void setup() {

    pinMode(SO_PINS[0], OUTPUT);
    //pinMode(12, OUTPUT);

}


void loop() {
digitalWrite(12,HIGH);
}

Is there a reason this will not work for me?
If I use the commented line instead it works fine.

To test I have a current-limited LED sourced by PIN12.

I was hoping to initialize a set of pins as OUTPUT with a loop. When it didn't work I determined it was not the loop but trying to read the constant array value that was failing.

Anyone have insight on this for me?

EDIT - I swear I tested this a dozen times before posting but on the first test after posting it's suddenly is working... :S
 
Last edited:
Status
Not open for further replies.
Back
Top