Error expected '}' before 'else'

#include <Arduino.h>
#define ACCION_ENCENDER 97 // La letra a 
#define ACCION_APAGAR 98 // La letra b
#define LED_FOCO_HABITACION 2
#include <Wire.h>
#include "RTClib.h"

const int RelePin = 2;
bool state = false;


// RTC_DS1307 rtc;
RTC_DS3231 rtc;

void setup() {
  {
    Serial.begin(9600);
    pinMode(LED_FOCO_HABITACION, OUTPUT);
  }
  Serial.begin(9600);
  delay(1000);

  if (!rtc.begin()) {
    Serial.println(F("Couldn't find RTC"));
    while (1);
  }

  if (rtc.lostPower()) {
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  }
}
bool isScheduledON(DateTime date)
{
  float hours = date.hour() + date.minute() / 60.0;

  bool hourCondition = (hours > 18.00) || (hours < 06.0);
  {
    return true;
  }
  return false;
}
void loop() {
  if (Serial.available())
  {
    int accion = Serial.read();
    if (accion == ACCION_ENCENDER)
    {
      digitalWrite(LED_FOCO_HABITACION, HIGH);
    }
    else if (accion == ACCION_APAGAR)

    {
      digitalWrite(LED_FOCO_HABITACION, LOW);
    }
    {
      DateTime now = rtc.now();


      if (state == false && isScheduledON(now));
      {
        digitalWrite(RelePin, HIGH);
        state = true;
        Serial.print("Activado");
      }
      else if (state == true && !isScheduledON(now));    // Aqui esta el error
      {

        digitalWrite(RelePin, LOW);
        state = false;
        Serial.print("Desactivar");
      }
    }
    delay(3000);
#include <Arduino.h>
#define ACCION_ENCENDER 97 // La letra a 
#define ACCION_APAGAR 98 // La letra b
#define LED_FOCO_HABITACION 2
#include <Wire.h>
#include "RTClib.h"

const int RelePin = 2;
bool state = false;


// RTC_DS1307 rtc;
RTC_DS3231 rtc;

void setup() {
  {
    Serial.begin(9600);
    pinMode(LED_FOCO_HABITACION, OUTPUT);
  }
  Serial.begin(9600);
  delay(1000);

  if (!rtc.begin()) {
    Serial.println(F("Couldn't find RTC"));
    while (1);
  }

  if (rtc.lostPower()) {
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  }
}
bool isScheduledON(DateTime date)
{
  float hours = date.hour() + date.minute() / 60.0;

  bool hourCondition = (hours > 18.00) || (hours < 06.0);
  {
    return true;
  }
  return false;
}
void loop() 
{
  if (Serial.available())
  {
    int accion = Serial.read();
    if (accion == ACCION_ENCENDER)
    {
      digitalWrite(LED_FOCO_HABITACION, HIGH);
    }
    else if (accion == ACCION_APAGAR)

    {
      digitalWrite(LED_FOCO_HABITACION, LOW);
    }
    
      DateTime now = rtc.now();


      if (state == false && isScheduledON(now))
      {
        digitalWrite(RelePin, HIGH);
        state = true;
        Serial.print("Activado");
      }
      else if (state == true && !isScheduledON(now))   // Aqui esta el error
      {

        digitalWrite(RelePin, LOW);
        state = false;
        Serial.print("Desactivar");
      }
    }
    
    delay(3000);
}

Several errors. (Does doing that ↑ 'help' you to learn anything ?)

if (conditions) aren't followed by a semi-colon ;
And - Mind Your Braces.

1 Like

A couple of unnecessary semi-colons…

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.