Can I start the void loop with an if sentence?
And if so how?
Tell us what you want to do, not how you think it ought to be done.
Nope. loop() is called over and over again after setup() executes.
If you don't want the loop() function to execute until some condition is met you can put a while loop in setup() that checks for the condition to be met.
What are you trying to accomplish?
If you only want to check the condition once, then ToddL1962's answer is what you need.
Or, if you want to repeatedly check for a condition, just make a new function with the code you want to execute and do the 'if' check repeatedly in the loop.
So...
bool condition = false;
void DoStuff()
{
// Doing stuff
}
void setup()
{
}
void loop()
{
if (condition == true) { DoStuff(); }
}
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.