I have a problem. I have void setup, void loop and 1 fuction more. Example
Void setup(){
Intruction1;
call();
}
void call(){
Intruction2;
}
Void loop(){
Instruction3;
If (x==Y){
-----------My problem
}
Instruction4;
}
I need a command that if x=y go to, for example, void call() fuction BUT I need when void call() end not return on last postion in void loop() fuction and execute instructuion4. I need run the code from void call() like the firt time the code started, these way when the void call() end void loop() starting from instruction3. I dont want restart the program obiously. I Supose it will be necesary break the void loop() or something like that.
return setup() will give you an error. You can return a function pointer - assuming you have the function declared correctly. And you can have as many returns in a function as you want.
What it is doing is executing setup() and then returning from loop(). It is not “returning” to setup().
You could do the same thing like this:
if (k>=3) {
setup();
return;
}
If you don't believe me, try to "return to" a function that returns a value.
if (k>=3) {
setup();
return;}
Its not found. but I think that you dont use arduino software for that reason my code is wrong for you.
Anyway, if you run my code in Arduino software (change k>=3 for k==3) The result you will obtain in Serial window is the next:
IN SETUP
IN 1
-----------------0
IN 2
IN 3
-----------------1
IN 2
IN 3
-----------------2
IN 2
IN SETUP
IN 1
-----------------3
IN 2
IN 3
-----------------4
IN 2
IN 3
-----------------5
Look at when k==3 go to setup() and write “IN SETUP” after call INI() an write “IN 1” and now not exist another call thus the software run void loop, BUT (IMPORTANT) THIS MAKES IT FROM THE BEGINNING. You can see as the first tense wirte is “IN 2” and no “IN3”. Very important detail which I was loking for.
the other hand, if you only use setup(); you are calling a fuction so when de fuction setup() and INI() end the code come back after if(k==3) and will write “IN3”
It will call setup();
Then it will return from setup().
Then it will return from loop() in the exact state it was. It does not restart the program and act as if main() is calling setup() and loop() the first time.
If you do it this way:
if (k==3) {
setup();
return();
}
you also will not call IN3.
return simply is not doing what you think it is doing - it can’t!