Make it possible to consolidate simple statements

For example:

digitalWrite(led && buzzer, HIGH);

rather than writing:

digitalWrite(led, HIGH); digitalWrite(buzzer, HIGH);

Thanks

You can of course do your own consolidation with a function. But if you want both outputs to change at exactly the same time you need to directly address the port they are on.


Rob

JJC114: For example:

digitalWrite(led && buzzer, HIGH);

rather than writing:

digitalWrite(led, HIGH); digitalWrite(buzzer, HIGH);

Thanks

Arduino uses C++ (with some simplifications, but it is still C++ at the core), and that would not do what you want it to do. The code you mention:

digitalWrite(led && buzzer, HIGH);

Would be interpreted as:

if (led && buzzer) {
    digitalWrite (1, HIGH);
} else {
    digitalWrite (0, HIGH);
}

If you find yourself wanting to write to 2 pins at the same time, create a function to do this:

void digitalWrite2 (int pin1, int pin2, int value)
{
    digitalWrite (pin1, value);
    digitalWrite (pin2, value);
}

and then use it as:

void loop (void)
{
    // ...
    digitalWrite2 (led, buzzer, HIGH);
    // ...
}

That would increase the size of the arduino library for no good reason.

WizenedEE: That would increase the size of the arduino library for no good reason.

I'm not sure whether you were addressing the original poster, or my reply.

If you meant my reply, I wasn't advocating putting digitalWrite2 into the standard Adruindo library, just putting it in your sketch as a convenience function. Depending on the size of the AVR instruction set, if you call 2 digitalWrite's a lot together, having a convenience function can actually save code space. If you were always using the same 2 pins, you can make the combined code smaller, by not passing the pin numbers:

void led_and_buzzer (int value)
{
    digitalWrite (led, value);
    digitalWrite (buzzer, value);
}

"Make it possible to consolidate simple statements" is possibly a nice concept in principle, but overloading the logical AND operation in some non-intuitive way is not the way to go about it.

What is counter-intuitive is that the AND operation does not imply the formation of a list of pins on which to perfom the operation.

I think there is a valid reason for a class that writes to X number of pins at the same time, sometimes it’s required due to the hardware but if nothing else for aesthetic reasons to remove the 10 digitalWrites() in a row we often see.

As it happens I’ve just written such a collection of functions, not for the AVRs I’m afraid but you can do this sort of thing

pinGroup * pg = pinGroupCreate (OUTPUT, 3, 11); // Pins 3-11 inclusive are a group of outputs
...
pinGroupWrite (pg, 0x55);
pinGroupInc (pg);
pinGroupRotateLeft (pg);

Rob

What you want to do is readily available, though it is rather hard to find it if you don't know what you are looking for.

http://arduino.cc/en/Reference/PortManipulation

Will let you write to multiple ports, just have to be parts of the same AVR port. Ardionu ports 0 - 8 are AVR portB, 9-13 are port C