Yes, you are wasting a teensy amount of clock cycles. When you write ledChange(LOW)
, it is compiled to a CALL type instruction (which tells the program counter register to jump to the location of the method).
So, this will basically compile to:
- Put
LOW
in some register or the stack - jump to the location of
ledChange()
- Fetch
led
from memory, and put it along withLOW
somewhere - jump to
digitalWrite()
- do whatever is in
digitalWrite()
- jump back
- jump back
Note that a CALL
jump involves a lot of messing with the stack, and takes a lot longer than a regular JMP
instruction.
On the other hand, doing just digitalWrite(led,LOW)
will do:
- Fetch
led
,LOW
from somewhere on the memory and put them somewhere accessible - jump to
ditigalWrite()
- do whatever is in
digitalWrite()
- jump back
I'm not entirely sure how arguments are passed in the corresponding compiled code, it's probably a part of the call. Also note that compilers vary, and some are smarter than others.
You can see that your encapsulation of the function made the program take up more clock cycles every time you while running it. However, this isn't really worth optimizing; I don't see much capacity in such encapsulation to slow down the Arduino. Besides, like I mentioned, some compilers optimize such things.
This has nothing to do with the function being a void
. If it was an int
function, it would be ever-so-slightly slower since storing the int before return involves a MV
or stack operation (forgot which).