Nema17 and a4988

I noticed some errors in your code and procedure against the forum rules in your post,

It is part of the forum rules that when posting codes it is done using tags.
These tags can be easily used by clicking " < code > " in the answer board toolbar.
Redo your post by correcting this mistake.

In your code, the problem I saw is that you are using pin 0 of the Arduino to connect the button.
Neither pin 0 nor pin 1 should be used as they are used by the serial to load codes and send messages.

If your assembly was the same as the video you posted the link to, your project will not work, as there is no connection between reset with the sleep pin.
Recommended connection for the A4988 module to work.

Finally, you say that your motor has "rotate in one direction for 2 meters" .
What does it mean to run 2 meters?
How many steps will it take to rotate 2 m?

See your mock code here.
When you press the button for the first time, the motor turns one way, the second time it turns the other way, and the third time it stops.

" Step - Wokwi ESP32, STM32, Arduino Simulator