Turn on LED_BUILTIN and another LED with single digitalWrite command?

I want to turn ON/OFF both the LED_BUILTIN and another LED on pin D7 with a single HIGH or LOW command, I have to do this about a dozen times in my sketch and I'm just trying to simplify the sketch. I've tried all kinds of functions and labels but nothing works. Is it impossible?

Why do you have to do this? There are lots of ways to turn on lots of Pins at the same time but if you must do it a way that doesn’t work then it won’t work. What are your actual requirements and limitations

yes, it possible, if both LED are connected to pins on the same controller port. Exact instruction to doing that depends from the controller family

void setLEDs (int state) 
{
  digitalWrite (LED_BUILTIN, state);
  digitalWrite (7, state);
}

I told you why. I'm just trying to save lines of code. Rght now I do it with two commands:

digitalWrite (7, HIGH)
digitalWrite (LED_BUILTIN, HIGH)

I was hoping for some way to say digitalWrite (something, HIGH)

Any code that is repeated should be put in it's own function, which can then be called using one command. It's called refactoring, and when done properly, reduces complexity and errors. RavenholmTouristBoard's answer is your solution.

Perhaps use the same pin as LED_BUILTIN for your external LED?

Calling a function with two digitalWrites, once the function is composed, takes one line - but one LED precedes the other.
Using Port Manipulation can get the LEDs on at the same time, but requires a function as well.

...if they're on the same port

I wouldn't be wasting your time if they were on the same pin. That's a no-brainer. Arduino doesn't give a pin number for the built-in LED, like D13 for older models. The label the LED "L" and in their newer BLINK example they turn it on and off with digitalWrite(LED_BUILTIN HIGH or LOW). I tried the following two functions but good old IDE came up with another cryptic complaint

void LEDson() {

digitalWrite(7, HIGH);
digitalWrite(LED_BUILTIN, HIGH); }
void LEDsoff() {
digitalWrite(7, LOW);
digitalWrite(LED_BUILTIN, LOW); }

Try void toggleLEDs ()

...which you didn't post

I tried to find the error message but couldn't because I had changed so much with all the fiddle farting around.
I remember it said something like "...expected (::slight_smile: before ..." And it was double colons, not semi-colons, and it was persistent.
Have you ever seen Arduino asking for (::slight_smile: before?

Do you really have a space between"toogle" and "leds"?

What is the emoji there for?

Pseudocode
Digitalwrite ledpin !ledstate

Well @OLDokasional when I stuck that into the good old ide with a setup() and loop() it compiled for me with no complaints, cryptic or otherwise.

image

So you can call it 13 still if you like, @OLDokasional .

void setup() {
  pinMode(7, OUTPUT);
  pinMode(LED_BUILTIN, OUTPUT);}
void togglem() {
  digitalWrite(7, !digitalRead(7));
  digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));}

void loop() {
  togglem();
  delay(1000); }

Here's how to control both LEDs with a toggle command.

Nice work, Owlet. I wish more of the "experts" taught with examples like that. I believe my problem was what

we used to call "cockpit error". This sketch loads and runs perfectly but I was unable to satisfy
the good old IDE with the functions in the loop function and had to put them in the setup function.

void setup() {}
void LEDson() {
digitalWrite(7, HIGH);
digitalWrite(LED_BUILTIN, HIGH);}
void LEDsoff() {
digitalWrite(7, LOW);
digitalWrite(LED_BUILTIN, LOW);}
void loop() {
LEDson();
delay(1000);
LEDsoff();
delay(1000);}

They are not in setup. Functions should not be in another function