!Hello! Can you help me with a code that gives me errors in IF ELSE ?. PLEASE.

very good with everyone first, my English is not good, I still have a basic level.
My question is that I try to detect the frequency of the network, using a zero crossing detector. which looking online I found a code. what ise is to increase conditions with IF ELSE to put a maximum value and minimum. in the maximum value it works correctly but in the minimum value the led remains on. That error will be true. please help me I will thank you forever.

the code is copyrighted I just try to increase some things

                                  // period of pulse accumulation and serial output, milliseconds
const int MainPeriod = 100;
long previousMillis = 0;                      // will store last time of the cycle end
 
volatile unsigned long prevMicros=0;
volatile unsigned long duration=0;           // accumulates pulse width
volatile unsigned int pulCnt=0;
 
// interrupt handler
void contadorcero()      {
  unsigned long curMicros = micros();
  duration += curMicros - prevMicros;
  prevMicros = curMicros;
  pulCnt++;               }
  
void setup()
{
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  Serial.begin(19200);
  attachInterrupt(0, contadorcero, RISING);
}
 
void loop()
{
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis >= MainPeriod)
  {
    previousMillis = currentMillis;   
                             // frecuency
            float freq = 1e6 / float(duration) * (float)pulCnt;
            Serial.print("Frec:");
            Serial.print(freq);
            duration = 0;
            pulCnt = 0;
            delay(500);
                                // frecuency 
     // the frequency is read with decimals (60 hz * 2 = 120.00 hz)       
  if (freq >= 120.05 ) // maximum value established
      {
          digitalWrite(5, HIGH);
      }
  else if (freq <= 119.97 )//minimum value established
     {
          digitalWrite(6, HIGH);
     }
  else {
          digitalWrite(5, LOW);
          digitalWrite(6, LOW);
       }         
                 
  }  
}

What is your program supposed to do?

Only if the frequency is between 119.97 and 120.05, you switch the leds off (guessing that pins 5 and 6 control the leds). Is that what is needed? Or is one led an indication that the frequency is too high and the other one that the frequency is too low.

If the latter, an if / else if / else is the wrong choice.

thanks in advance for your answer. What I need is to make alerts when the frequency is low or high than normal. with if else or with another structure. sorry for the inconvenience

There is no inconvenience.

This might be the pseudo code that your looking for.

if frequency too high
{
  led 1 on
}
else
{
  led 1 off
}

if frequency too low
{
  led 2 on
}
else
{
  led 2 off
}

Thank you. I already solved my error.