"call/select" multiples LEDs

Hii,

I've got something like this

int led0 = 2;
int led1 = 3;
int led2 = 4;

void setup()

pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);

digitalWrite(led0, HIGH);
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);

my question is, how can i get something like this??

digitalWrite(led0, led1, led2, HIGH);

instead of go line by line, set the 3 led in a sngle line.

my question is, how can i get something like this??

digitalWrite(led0, led1, led2, HIGH);

digitalWrite(led0,HIGH);
digitalWrite(led1,HIGH);
digitalWrite(led2,HIGH);

I suspect what you want is a for loop. Not one line but close. You'll also need to read up on arrays. An array is where you store the pin numbers that the for loop will reference to do things like setting pinModes.

The IDE has examples at - File/examples/5.control.

jmatos448:
my question is, how can i get something like this??

digitalWrite(led0, led1, led2, HIGH);

Do you mean you want a function like:

void digitalWrite3( int a, int b, int c, int hilo )
{
 digitalWrite( a, hilo );
 digitalWrite( b, hilo );
 digitalWrite( c, hilo );
}

//then in your setup(), you can call that function like:

digitalWrite3( led1, led2, led3, HIGH );

Yours,
TonyWilk

Fixed it:

void digitalWrite3(const byte a, const byte b, const byte c, const bool hilo )
{
 digitalWrite( a, hilo );
 digitalWrite( b, hilo );
 digitalWrite( c, hilo );
}

//then in your setup(), you can call that function like:

digitalWrite3( led1, led2, led3, HIGH );

Pin numbers are byte/uint8_t, not int. For dark reasons the value is a uint8_t as well but you just want to use HIGH/LOW / true/false so a bool will do.

But in reality, using arrays is the right way. The moment you start numbering stuff => arrays make it a lot easier.

I think that until the OP (hello?) comes back with more info, it's hard to say what he wants.

Loop? Array? - that's making a bit of an assumption.

Based on just what he asked, he could be asking how to write a variadic function...

Setting a random selection of LEDs by doing: setLeds( HIGH, led1 ) or setLeds( LOW, led1, led2, led4 ) might be handy. (*)

Yours,
TonyWilk

(*) but interesting if you're mixing int's and bytes for pin numbers, compiler's not going to coerce that for you - could just write multiple functions I suppose, messy tho'.

I am more interested on why the OP wants to do this. Maybe we can steer them to a different solution based on why they want this one line feature.