conector

hello.
I´m trying to create a code that allows me to Stop the program when i press the button STOP and continues on the same point when i press another button. Can someone help?

int const buttonPin  = 21; //botão STOP




void setup() {
  
 #define contador  0

}

void loop() {
  if (digitalRead(eletroimanon) == HIGH) { //botão start está feito
    
primeiropasso:
   if (digitalRead(contador) == 0 )// tem de verificar se o contador está a 0
   if (digitalRead(buttonPin) == LOW)
   {
   digitalWrite(suportegarramais, HIGH);//estica suporte garra
   delay (100);
   }
   else
   {
   digitalWrite(suportegarramais, LOW);//desliga o sup garra, caso nao seja ativo
   }
    if (digitalRead(buttonPin) == LOW){ // le o estado do botão stop
   delay (100);
   }
   else
   {
   digitalWrite(suportegarramais, LOW); // caso stop ativo, desliga o sup. 
   }
   if (digitalRead(buttonPin) == LOW){
   delay (100); 
   }
   else
   {
   digitalWrite(suportegarramais, LOW);
   }
   if (digitalRead(buttonPin) == LOW){
   delay (100);
   }
   else 
   {
   digitalWrite(suportegarramais, LOW);
   }
   if (digitalRead(buttonPin) == LOW){
   delay (100); 
   }
   else 
   {
   digitalWrite(suportegarramais, LOW);
   }
   if (digitalRead(buttonPin) == LOW){
   delay (100); 
   }
   else 
   {
   digitalWrite(suportegarramais, LOW);
   }
   if (digitalRead(buttonPin) == LOW){
   delay (100);
   }
   else
   {
   digitalWrite(suportegarramais, LOW);
   }
   if (digitalRead(buttonPin) == LOW){
   delay (100);   
   }
   else
   {
   digitalWrite(suportegarramais, LOW);
   }
   if (digitalRead(buttonPin) == LOW){
   delay (100);
   }
   else 
   {
   digitalWrite(suportegarramais, LOW);
   }
   if (digitalRead(buttonPin) == LOW){
   delay (100);
   }
   else 
   {
   digitalWrite(suportegarramais, LOW);
   }
   if (digitalRead(buttonPin) == LOW){
   delay (100);
   }
   else
   {
   digitalWrite(suportegarramais, LOW);
   }
   if (digitalRead(buttonPin) == LOW){
   delay (100);
   }
   else
   {
   digitalWrite(suportegarramais, LOW);
   }
   if (digitalRead(buttonPin) == LOW){
   delay (100);
   }
   else
   {
   digitalWrite(suportegarramais, LOW);
   }
   if (digitalRead(buttonPin) == LOW){
   delay (100);
   }
   else 
   {
   digitalWrite(suportegarramais, LOW);
   }
   if (digitalRead(buttonPin) == LOW){
   delay (100);
   }
   else
   {
   digitalWrite(suportegarramais, LOW);
   }
   if (digitalRead(buttonPin) == LOW){
   delay (100);
   }
   else 
   {
   digitalWrite(suportegarramais, LOW);
   }
   if (digitalRead(buttonPin) == LOW){
   delay (100);
   }
   else 
   {
   digitalWrite(suportegarramais, LOW);
   }
   if (digitalRead(buttonPin) == LOW){
   delay (100);
   }
   else
   {
   digitalWrite(suportegarramais, LOW);
   }
   if (digitalRead(buttonPin) == LOW){
   delay (100);
   }
   else 
   {
   digitalWrite(suportegarramais, LOW);
   }
   contador++;
 
  }  
   
       
segundopasso:
   if (digitalRead(contador) == 1){// tem de verificiar se contador igual a 1
   if (digitalRead(buttonPin) == LOW) {
   digitalWrite(suportegarramais, LOW);
    delay(100);
}
   else
   {
   digitalWrite(suportegarramais, LOW);
   }   
   if (digitalRead(buttonPin) == LOW){
      delay (100);
   }
   else
   {
   digitalWrite(suportegarramais, LOW);
   }
   if (digitalRead(buttonPin) == LOW){
   delay (100);
   }
   else
   {
   digitalWrite(suportegarramais, LOW);
   }
   if (digitalRead(buttonPin) == LOW){
   delay (100); 
   }
   else
   {
   digitalWrite(suportegarramais, LOW);
   }
   if (digitalRead(buttonPin) == LOW){
   delay (100);
   }
   else 
   {
   digitalWrite(suportegarramais, LOW);
   }
   if (digitalRead(buttonPin) == LOW){
   delay (100); 
   }
   else 
   {
   digitalWrite(suportegarramais, LOW);
   }
   if (digitalRead(buttonPin) == LOW){
   delay (100); 
   }
   else 
   {
   digitalWrite(suportegarramais, LOW);
   }
   if (digitalRead(buttonPin) == LOW){
   delay (100);
   }
   else
   {
   digitalWrite(suportegarramais, LOW);
   }
   if (digitalRead(buttonPin) == LOW){
   delay (100);   
   }
   else
   {
   digitalWrite(suportegarramais, LOW);
   }
   if (digitalRead(buttonPin) == LOW){
   delay (100);
   }
   else 
   {
   digitalWrite(suportegarramais, LOW);
   }
   if (digitalRead(buttonPin) == LOW){
   delay (100);
   }
   else 
   {
   digitalWrite(suportegarramais, LOW);
   }
   if (digitalRead(buttonPin) == LOW){
   delay (100);
   }
   else
   {
   digitalWrite(suportegarramais, LOW);
   }
   if (digitalRead(buttonPin) == LOW){
   delay (100);
   }
   else
   {
   digitalWrite(suportegarramais, LOW);
   }
   if (digitalRead(buttonPin) == LOW){
   delay (100);
   }
   else
   {
   digitalWrite(suportegarramais, LOW);
   }
   if (digitalRead(buttonPin) == LOW){
   delay (100);
   }
   else
   {
   digitalWrite(suportegarramais, LOW);
   }
   if (digitalRead(buttonPin) == LOW){
   delay (100);
   }
   else 
   {
   digitalWrite(suportegarramais, LOW);
   }
   if (digitalRead(buttonPin) == LOW){
   delay (100);
   }
   else
   {
   digitalWrite(suportegarramais, LOW);
   }
   if (digitalRead(buttonPin) == LOW){
   delay (100);
   }
   else 
   {
   digitalWrite(suportegarramais, LOW);
   }
   if (digitalRead(buttonPin) == LOW){
   delay (100);
   }
   else 
   {
   digitalWrite(suportegarramais, LOW);
   }
   if (digitalRead(buttonPin) == LOW){
   delay (100);
   }
   else
   {
   digitalWrite(suportegarramais, LOW);
   }
   if (digitalRead(buttonPin) == LOW){
   delay (100);
   }
   else 
   {
   digitalWrite(suportegarramais, LOW);
   contador++;
   }
   }

cheers

Each time through your loop, poll to see if the STOP button has become pressed.
If it has, just start polling the GO button until it becomes pressed.

My problem is not how stop and start again. That i was able to do. Teh real problem is to the loop continues where i stoped.

The method I described will continue loop () from very, very close to where it stopped.

Maybe you want to try a state machine.

Remove the #define from setup. #defines should go before setup.

However, you shouldn't be using a #define there at all - a #define is like "find-replace" at compile time.

So all of those places where you do things like:

contador++;

that gets turned into

0++;

which is clearly not what you want - you want to increment a variable called contador.

So remove the define, and instead declare contador (before setup):

unsigned int contador = 0; //you'll need to consider whether unsigned int is the right type - I don't feel like digging through your code to figure out what the maximum value contador needs to store is.

To solve your other problem - restructure the code in loop to get rid of delay() (see the countless tutorials and guides on "doing more than one thing at a time" - this is far and away the most frequently asked arduino programming question and lots of people have written about it). Then your loop() will be running really fast, checking whether it's in stopped-state, and if not, checking whether it's time to do something. This is the state-machine model - there's a lot written about it.

delay() is simple to understand, but as the complexity of your program increases, it quickly becomes almost useless.

Oh - and, press ctrl+T with your sketch open, it'll indent blocks for you. Makes code much easier to read, and also helps catch problems in placement of {}'s (I think you're okay here, but your code is kinda unpleasant to read through)

Ty so much for help.
The reason for i have so much delyas is to tge program stop on there. because if i put a delay of 1000. the program will only stop at the end of 1000

You shouldn't have any delay()s in your code, which is why I suggested a state machine