Go Down

Topic: Pin + variable = pin number (Read 408 times) previous topic - next topic

sweddle

So im still kind of new with the C like coding.

I have variable named X it changes from 3 then 4 then 5 incrementing by 1 each time I toggle pin 8 low to high, this is working fine. What i want to do now is use this variable to change a pin out state.. my code fore using the variable looks like this:

int X = 3;

//I tried
digitalWrite(led & X, HIGH);

//and tried

digitalWrite(led(X), HIGH);

in short it should be the same as
digitalWrite(led3, HIGH);



Thanks for any help.
Shane

simond

Quote
So im still kind of new with the C like coding.

I have variable named X it changes from 3 then 4 then 5 incrementing by 1 each time I toggle pin 8 low to high, this is working fine. What i want to do now is use this variable to change a pin out state.. my code fore using the variable looks like this:

int X = 3;

//I tried
digitalWrite(led & X, HIGH);

//and tried

digitalWrite(led(X), HIGH);

in short it should be the same as
digitalWrite(led3, HIGH);



Thanks for any help.
Shane


If I'm understanding you correctly, you want to change pin X to high, yes? If so, this should be enough:

Code: [Select]

int X = 3;
digitalWrite(X, HIGH);


This will set pin 3 to HIGH. Set X = 4 and use the same digitalWrite() command to set pin 4 high, etc.

Go Up