Consolidating digitalWrite statements

Hi,
I have been making a metronome recently and I have come across a very small issue, but one about efficiency of programming.
A piece of code in this metronome is the following:

  digitalWrite(led1, HIGH);
  digitalWrite(led2, HIGH);
  delay(500);
  digitalWrite(led1, LOW);
  digitalWrite(led2, LOW);
  delay(500);

Because this program is barely 1000 bytes, efficiency is not really relevant, but for future use - is their a way of writing the digitalWrites as the following? (or similar)

digitalWrite(led1 && led2, HIGH);

Thanks

digitalWrite(led1 && led2, HIGH);

No.

However, if the two LEDs are on the same port, you can use port manipulation.

Thanks for that - I must say that I am a little supprised

Surprised at what?

@JJC, why not lodge that as a suggestion here

Must say it would make life easier to be able to write something like

digitalWrite((led1, led2, motorA_enable), LOW);

Jim

void WriteStuff( const uint8_t value )
{
  digitalWrite( led1, value );
  digitalWrite( led2, value );
  digitalWrite( motorA_enable, value );
}

:wink:

JimboZA:
Must say it would make life easier to be able to write something like

digitalWrite((led1, led2, motorA_enable), LOW);

It's pretty trivial to write a function that does that, if you need it. Look up va_arg.

That's cool yep... but often it's a whole bunch of pins at the top of the code being set once-off, in which case writing a function is more trouble than the once-off coding.

But indeed a good idea for frequent use (always assuming it's the same bunch of pins needing setting)

You could create your own overloaded functions:

void digitalWrite(int a, int b, int level)
{
  digitalWrite(a,level);
  digitalWrite(b,level);
}

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

etc...

majenko:
You could create your own overloaded functions:

... but first I'd have to know what an overloaded function is 8)

I'm guessing from your example, that it's to do with having essentially the same function repeated, with the same name, and which one it invokes depends on how many parameters you throw into the pot?

You could create your own overloaded functions:

No, you can't. There is a prototype for the C function digitalWrite(). You can't overload C functions like you can C++ methods.

PaulS:

You could create your own overloaded functions:

No, you can't. There is a prototype for the C function digitalWrite(). You can't overload C functions like you can C++ methods.

Yes you can.

Play nice, guys.... 8)

At least I know now what an overloaded function is.

Jim