Running servo for loop delay with separate pushbutton if statements

This is code that is blocking.
// stay INSIDE this for-loop until the counting up from 0 to 180 has finished
// which needs 181 * 55 milliseconds = 9900 milliseconds = 9,9 seconds

To make the code responsive again that at the code is reacting on button-presses
at any time requires
non-blocking coding.

The basic principle of non-blocking coding is

  • avoid all and any for-loops

  • avoid all and any while-loops

  • avoid all and any delay()

  • the only thing that is looping is
    void loop() itself

  • if code shall not be executed all the time the execution has to be made conditional with if-conditions or switch-case-break-statements.

  • to achieve the goal that parts of the code shall be only executed after some time
    non-blocking timing must be used.

From this description you can see going beyond some small demo-programs requires quite some knowledge of more advanced programming-techniques

Of course there are a lot of tutorials online for that. Most of them really bad in explaining.
Some of them of medium quality but don't use everyday examples which would make it easier to understand.

And in very rare cases easy to understand tutorials that use everyday examples (as analogons) to explain what the code does.

Still the main thing is: understanding the concepts of

  • non-blocking timing
  • state-machines
  • looping through using of void loop() combined with using quickly___ jump-in / jump-out functions

This is not a trivial matter of 15 minutes. It is more of some hours with very good tutorials and it is a matter of days with medium quality tutorials.

As a starting point give this tutorial about non-blocking timing a try

best regards Stefan