Hello and thanks for reading.
I'm trying to pass a function with arguments as argument to another function. But I keep getting the error "Invalid use of void expression".
When the function I try to pass has no arguments, the code compiles, error free:
int value;
void function3();
void function2();
void function1(void (*func2)(), void (*func3)(), int value);
void setup() {
Serial.begin(9600);
}
void loop() {
function1(function2, function3,7000);
}
void function1(void (*func2)(), void(*func3)(), int value){
(*func2)();
delay(value);
(*func3)();
delay(value);
}
void function2() {
Serial.println("func2");
}
void function3() {
Serial.println("func3");
}
When function2 has arguments, I get the error message.
String text;
int value;
void function3();
void function2(String text, int value2);
void function1(void (*func2)(String text, int value2), void (*func3)(), int value);
void setup() {
Serial.begin(9600);
}
void loop() {
function1(function2("test", 7), function3,7000);
}
void function1(void (*function)(), void(*other)(), int value){
(*other)();
delay(value);
(*function)();
}
void function2(String text, int value2) {
Serial.println(text);
Serial.println(value);
}
void function3() {
Serial.println("func 3");
}
I'm very new to programming, and this is my first time trying to pass a function as an argument. If I can get this working my design will, in general, be so much more elegant.
I need your expertise! Thank you in advance, oh kind Arduino community!