Can't stop the loop

Hi dear programmers, I am trying to make a “stairs drawing tool” I have Arduino pro micro and a Tact button, my arduino draws a stairs on Paint when i press the button so it is like a macro key. I am trying to break the loop when i release the button but it completes the loop and stops. I need to make that when i release the button just stop , break eveything and stop then when i press the button start from beginning and draw.

Here is my simple code for that ;

Thanks everyone for reading , time and helping.

#include <Mouse.h>

void setup() {

void loop() {

Do you have a pull down resistor on your tact switch circuit?

yes sir i have

If you wrote

I need to make that when i release the button just stop , break eveything and stop

Does this mean if you release the button after the drawing of the vertical line


immetiately stop don't draw the horizontal line?
Whenever you press the button start new with drawing the vertical line?

If you enjoy coding this for an arduino just do it.

If the main-purpose is to have a drawing-function consider using
the software Autohotkey. Of course it will take some time to learn Autohotkey-Scripting but it is very powerful.
And there is a user-forum like this forum fpr Autohotkey.

For immetiately stopping the drawing like described above use two if-conditions instead of a single while-loop.
best regards Stefan

Just looking, you'll not get immediate stoppage but you can get close by checking if the button is pressed before/after each instruction has started/completed but that won't work either.

Imagine if you will, how 'fast' the arduino is running through its loop(), so on its own a Arduino could check for a button press. Except your code uses over 1.1 seconds of do nothing time. Say your code takes 1mSecond to run. Then your code goes to do nothing state for 1.1 seconds. You'd have hardly any human time to press that button to stop the things being done, before your code goes into the do nothing.

For an Uno, you can check out the not using delay() delaying method by using millis() and then check out the Uno doing multi things with millis().