hello,
i didn't do much of a research about it (not much free time), but i think the library does not provide an easy/efficient way to toggle a pin.
anyway, i modified wiring.h and added:
... #define HIGH 0x1 #define LOW 0x0 #define TOGGLE 0x2 // added line
...
and wiring_digital.c and changed to:
if (val == LOW) *out &= ~bit; if (val == HIGH) *out |= bit; // added line
__ if (val == TOGGLE) *out ^= bit; // added line__
__ // replaced line // else *out |= bit;__
now it looks like i can write for example:
digitalWrite(ledPin, TOGGLE);
instead of calling other functions or keeping the state of the pin in the program.
if this modification does not create any issues, i think it would be a nice addition to a next version.
Ah. Using the PINx magic toggle port, and a variation of the FastDigitalWrite macro that has been floating around, it should be possible to create a "digitalToggle()" function (macro) that takes up no space unless it is used, and operates in a single cycle if all the arguments are constant, and IT DOESN'T HAVE TO BE BACKWARD COMPATIBLE WITH ANYTHING!
Well, changing the "any non-zero value causes a 1 to be written" behavior may screw up any number of existing sketches...
I don't necessarily think this is "one of those times", but sometimes you have to decide to say "fsck backwards compatibility" and make a change "for the better".
Hello,
I think it is a good idea.
The same thing should be done to reverse the direction of a pin
(an input becomes an output, and an output becomes an input).
It would be great to write
pinMode(ThisPin, REVERSE);
Best regards,