Duplicate an operation on void loop()

hi
i need duplicate an action.
The program start off in the reed switch 1, i press the button and the gate open, stop when arrive the reed switch 2 and i press the other button and close and i want to stop when arrive again the switch 1.

if (a == LOW) //quando o circuito estiver fechado

  digitalWrite(LED_R, LOW); 
  digitalWrite(LED_G, LOW);
  Serial.println("portão fechado"); 
}

Is the start action but is too the final action but this one have 1 change, need to stop....
And when i duplicate this, the program have some problems and dont open the door

#include <IRremote.h>
#define IN1  9  //Input 1 da controladora L298N
#define IN2  8  //Input 2 da controladora L298N
#define ENA  10  //Enable A da controladora L298N  
#define ENB  11  //Enable B da controladora L298N
#define TRIG 12 //mandar sinal
#define ECHO 13 //receber sinal
#define switchReed1 3
#define switchReed2 2
#define IR_ABRIR      0x00FF18E7   //Botão do comando IR "▲"
#define IR_FECHAR         0x00FF4AB5   //Botão do comando IR "▼" 
#define LED_R 5
#define LED_G 4
#define IRPIN 6 //Pin de dados do sensor IR
int a = 0;
int b = 0;
enum CR 



{
  abrir, //Avançar
  fechar,//Voltar
  IRC
}

Controlo_Remoto=IRC;
IRrecv IR(IRPIN);  //IRrecv (sensor IR) lê o sinal mandado pelo comando IR 
decode_results IRresults;  
bool stopFlag = true;//Definir paragem da "flag"
bool JogFlag = false;
uint16_t JogTimeCnt = 0;
uint32_t JogTime=0;



void setup() {  
  
  pinMode(IN1, OUTPUT); //Atribuição do valor como OUTPUT (saída)
  pinMode(IN2, OUTPUT); //Atribuição do valor como OUTPUT (saída)
  pinMode(ENA, OUTPUT);  //Atribuição do valor como OUTPUT (saída)
  pinMode(ENB, OUTPUT);  //Atribuição do valor como OUTPUT (saída)
  pinMode(LED_R, OUTPUT); //Atribuição do valor como OUTPUT (saída)
  pinMode(LED_G, OUTPUT); //Atribuição do valor como OUTPUT (saída)
  pinMode(switchReed1, INPUT); //Atribuição do valor como INPUT (entrada)
  pinMode(switchReed2, INPUT); //Atribuição do valor como INPUT (entrada)
  pinMode(IRPIN, INPUT);  //Atribuição do valor como INPUT (entrada)
  Serial.begin(9600);
  IR.enableIRIn(); // Start the receiver
  digitalWrite(IRPIN, HIGH);
  }

  
/*motor dc*/
void abre() 
{
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, HIGH);
}
void fecha() 
{
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);

}
void para()
{
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, LOW);
}  


/*Definir a velocidade*/
void velocidade(int lspeed,int rspeed) //Mudar a velocidade
{
  analogWrite(ENA,lspeed); //lspeed:0-255
  analogWrite(ENB,rspeed); //rspeed:0-255   
}



void IR_Funcionamento() //Detactar o Sensor IR
{
  if(IR.decode(&IRresults))
  {
    if(IRresults.value==IR_ABRIR)
    {
      Controlo_Remoto=abrir;
    }
    else if(IRresults.value==IR_FECHAR)
    {
        Controlo_Remoto=fechar;
    }
    IRresults.value = 0;
    IR.resume();
  }
}



void Comandos_portao()
{
    switch (Controlo_Remoto) 
    {
      case abrir:
            velocidade(150,150);abre();JogFlag = true;JogTimeCnt = 3;JogTime=millis();break;
      case fechar:
            velocidade(150,150);fecha();JogFlag = true;JogTimeCnt = 1;JogTime=millis();break;
      default:break;
    }
    Controlo_Remoto=IRC;
   }






void loop()
{
  
a = digitalRead (switchReed1);
b = digitalRead (switchReed2);
{    

if (a == LOW) //quando o circuito estiver fechado

  digitalWrite(LED_R, LOW); 
  digitalWrite(LED_G, LOW);
  Serial.println("portão fechado"); 
}


if (IR_ABRIR == HIGH) 
{
  
  abre();
}
  

if ((a == HIGH) && (b == HIGH))
{
 digitalWrite (LED_R, HIGH);
 digitalWrite (LED_G, LOW);
 Serial.println("portão a abrir ou fechar");
}

if (b == LOW) //Se o circuito estiver aberto
{ 
  digitalWrite(LED_G, HIGH); 
  digitalWrite(LED_R, LOW);
  Serial.println("portão aberto");
{
  para();
}

 if (IR_FECHAR == HIGH)
 { 
    fecha();
 }
}

 
{
  IR_Funcionamento();
  Comandos_portao();
}
}

i hope someone can help me
Sorry for my english

enum CR



{
  abrir, //Avançar

Get rid of the useless white space between the statement and the {.

    switch (Controlo_Remoto)
    {
      case abrir:
            velocidade(150,150);abre();JogFlag = true;JogTimeCnt = 3;JogTime=millis();break;
      case fechar:
            velocidade(150,150);fecha();JogFlag = true;JogTimeCnt = 1;JogTime=millis();break;
      default:break;
    }

ONE statement per line.

{   

if (a == LOW) //quando o circuito estiver fechado

  digitalWrite(LED_R, LOW);
  digitalWrite(LED_G, LOW);
  Serial.println("portão fechado");
}

You can't just randomly drop curly braces into your code wherever you like. They have very specific places where they go.

PaulS:

enum CR

{
  abrir, //Avançar



Get rid of the useless white space between the statement and the {.



switch (Controlo_Remoto)
    {
      case abrir:
            velocidade(150,150);abre();JogFlag = true;JogTimeCnt = 3;JogTime=millis();break;
      case fechar:
            velocidade(150,150);fecha();JogFlag = true;JogTimeCnt = 1;JogTime=millis();break;
      default:break;
    }



ONE statement per line.



{

if (a == LOW) //quando o circuito estiver fechado

digitalWrite(LED_R, LOW);
  digitalWrite(LED_G, LOW);
  Serial.println("portão fechado");
}



You can't just randomly drop curly braces into your code wherever you like. They have very specific places where they go.

Thank you.
I dont understand this "You can't just randomly drop curly braces into your code wherever you like. They have very specific places where they go."
can u explain ?

can u explain ?

Can you use proper words? This is NOT a text-speak channel.

Some statements, such as function declarations, MUST be followed by an open and a close curly brace. There can, and usually is, code between the curly braces.

Some statements, such as if statements, for loops, while loops, etc. can be followed by a single statement or by a block of statements. If there is to be a block of statements, the block begins and ends with appropriate curly braces.

Blocks can be defined anywhere in the code, but they look out of place when they don't follow statements that can have blocks.

You have defined a useless block of code that contains an if statement that controls the execution of ONE statement. But, your indentation makes it appear as though you think that more than one statement will be executed, or shipped, depending on whether the if statement evaluates to true or false.

PaulS:
You have defined a useless block of code that contains an if statement that controls the execution of ONE statement. But, your indentation makes it appear as though you think that more than one statement will be executed, or shipped, depending on whether the if statement evaluates to true or false.

Ok.
Can u help me to do this?

Mouraa:
Ok.
Can u help me to do this?

No.

If you can't be bothered to spell simple words like "you" correctly, I can't be bothered to help you any more.