removes all ambiguity about what you are printing.
I hate do/while loops, because they iterate at least once, even if the end condition is true. A while loop is almost always better, since the condition is checked first AND is stated at the top of the block.
I don't think this is your problem, but you don't want an else if with only two cases, an else will do fine. I think two that braces are better style when using else-ifs.
This is wrong, but probably not causing your problem:
if (degree_prev-degree_now>=0) goal = degree_prev - degree_now;
else if (degree_prev-degree_now < 0)goal = degree_prev + 360 - abs(degree_now);
There are two problems: the second ‘if’ is redundant since it must be true if the first condition is false; if there had been any situation where both conditions were false then goal would not be set.
There’s no obvious way for the code to get stuck so I suggest you need to look for non-obvious ways. To do that, add print statements before and after each function/method call in the loop and see whether execution is blocking somewhere. Add a delay(100) or similar after each print statement to allow time for the serial output to be sent, in case something is blocking with interrupts disabled, or crashing in a way that kills the serial output.
Aside from the issue of why the code is not executing, the logic associated with goal looks pretty dodgy. What’s it intended to do?
Tried with a delay before the end loop but it still gets stuck , im a noob,does the baud rate affect the output of the serial monitor ? If yes in what way exactly ?
Slightly off topic:
This is wrong, but probably not causing your problem:
if (degree_prev-degree_now>=0) goal = degree_prev - degree_now;
else if (degree_prev-degree_now < 0)goal = degree_prev + 360 - abs(degree_now);
You mean the general logic behind it or just the redundant “if” ?
DeathByCh0c0:
Tried with a delay before the end loop but it still gets stuck , im a noob,does the baud rate affect the output of the serial monitor ? If yes in what way exactly ?
Slightly off topic:
This is wrong, but probably not causing your problem:
if (degree_prev-degree_now>=0) goal = degree_prev - degree_now;