Hello.
I'm a beginner in arduino, and I have a doubt in relation to the "void" function.
Is it possible to have several arguments in "void" and hide the last ones in case it is not necessary to use?
Example:
Here I would like to use a color ,uint32_t color1 : dig(14, red);
and that the others (uint32_t color2 and uint32_t color3) already had a predefined value.
but so in the error compilation because the other 2 arguments are missing (uint32_t color2 and uint32_t color3).
How can I make the arguments (uint32_t color2 and uint32_t color3) optional ???
Good suggestions have been made.
Presented solutions will work in any function, not only void functions...
A void function is a function that does not return anything (it returns emptyness). An int function returns an int etc.
In good old pascal a void function was named a procedure.... a set of instructions to do things... whereas a function is a set of instructions where some result is sent to the caller... (sometimes only a message to acknowledge that the instructions were performed successfully)
Yes, but you'll have to declare a function prototype.
As part of its "beginner friendliness", the Arduino IDE will most times automatically generate function prototypes for any functions that don't already have one in your code as part of the sketch preprocessing step.
However, defining the default parameter value in the function definition causes the Arduino IDE to skip automatic prototype generation for that function. In order to define default arguments you'll need to write your own function prototype or define the function ahead of where it is called as you have done.
If placing the function after the loop(), remove the parameter's default values. Then, add a function prototype to before setup() that includes the defaults.