RTC, TimeAlarms, funciones

Hola a todos:

Este es mi primer proyecto con arduino en el cual quiero simular un reloj convencional donde se encienda un led por hora y estos se mantengan activos hasta las que sean las 12:59 (tanto en am y pm) donde estos se apaguen y luego comience el ciclo nuevamente cuando sean las 1 o 13hrs.
Estoy utilizando un RTC y la librería TimeAlarms.
Tengo un problema al llamar la función de apagado de los leds, donde me dice que no he ingresado correctamente la función de alarma de apagado. He revisado el código y no logro encontrar el o los errores. Les adjunto el código de programación y de error.
Desde ya muchas gracias.

// Conexion i2C :Arduino UNO  SCL-> A5   SDA->A4  VCC->5V  GND->GND
// Conexion RTC :Arduino UNO    GND->GND VCC->5V SCL-> SCL  SDA->SDA los dos pines despues del ...12,13,GND,AREF,SDA,SCL
// Conexion Rele:Arduino UNO GND->GND  VCC->5V  IN->7
// NOTA: se debe cargar dos veces este programa 1. Con la linea  RTC.adjust(DateTime(__DATE__, __TIME__)); 
//                                              2. Sin esa linea
#include <Wire.h> 
#include "RTClib.h"
#include <TimeLib.h>
#include <TimeAlarms.h>
RTC_DS3231 RTC;
int misleds[12] = {13,2,3,4,5,6,7,8,9,10,11,12};
int apagoleds[12] = {0,0,0,0,0,0,0,0,0,0,0,0};

//////////////////////  void setup()  //////////////////////////

void setup() {
    
    Wire.begin();    
    Serial.begin(9600);                           
    RTC.begin();                                // Inicia la comunicaci¢n con el RTC
 
  //RTC.adjust(DateTime(__DATE__, __TIME__)); // Lee la fecha y hora del PC (Solo en la primera carga)
                                             // el anterior se usa solo en la configuracion inicial luego se pone como comentario
                                             // y se vuelve a cargar el programa sin esa linea.

  ////////  salidas  /////////
    pinMode(13,OUTPUT);
    pinMode(2,OUTPUT);
    pinMode(3,OUTPUT);
    pinMode(4,OUTPUT);
    pinMode(5,OUTPUT);
    pinMode(6,OUTPUT);
    pinMode(7,OUTPUT);
    pinMode(8,OUTPUT);
    pinMode(9,OUTPUT);
    pinMode(10,OUTPUT);
    pinMode(11,OUTPUT);
    pinMode(12,OUTPUT);
    
  for(int i=0 ;i<12; i++)
  {
    pinMode(misleds[i],OUTPUT);
  }
        ///////////////  alarmas  /////////////// 
  Alarm.alarmRepeat(1, 0, 0, PrendoLed13);  //enciendehora1
  Alarm.alarmRepeat(2, 0, 0, PrendoLed2);
  Alarm.alarmRepeat(3, 0, 0, PrendoLed3);
  Alarm.alarmRepeat(4, 0, 0, PrendoLed4);
  Alarm.alarmRepeat(5, 0, 0, PrendoLed5);
  Alarm.alarmRepeat(6, 0, 0, PrendoLed6);
  Alarm.alarmRepeat(7, 0, 0, PrendoLed7);
  Alarm.alarmRepeat(8, 0, 0, PrendoLed8);
  Alarm.alarmRepeat(9, 0, 0, PrendoLed9);
  Alarm.alarmRepeat(10, 0, 0, PrendoLed10);
  Alarm.alarmRepeat(11, 0, 0, PrendoLed11);
  Alarm.alarmRepeat(12, 0, 0, PrendoLed12);
//
  Alarm.alarmRepeat(13, 0, 0, PrendoLed13);
  Alarm.alarmRepeat(14, 0, 0, PrendoLed2);
  Alarm.alarmRepeat(15, 0, 0, PrendoLed3);
  Alarm.alarmRepeat(16, 0, 0, PrendoLed4);
  Alarm.alarmRepeat(17, 0, 0, PrendoLed5);
  Alarm.alarmRepeat(18, 0, 0, PrendoLed6);
  Alarm.alarmRepeat(19, 0, 0, PrendoLed7);
  Alarm.alarmRepeat(20, 0, 0, PrendoLed8);
  Alarm.alarmRepeat(21, 0, 0, PrendoLed9);
  Alarm.alarmRepeat(22, 0, 0, PrendoLed10);
  Alarm.alarmRepeat(23, 0, 0, PrendoLed11);
  Alarm.alarmRepeat(00, 0, 0, PrendoLed12);
//
        /////alarma de apagado/////
  Alarm.alarmRepeat(00,59,0, ApagoLed(misleds[i]); 
  Alarm.alarmRepeat(12,59,0, ApagoLed(misleds[i]);
}
//////////////////////  void loop () ///////////////////
void loop () {
  
  digitalClockDisplay();
  Alarm.delay(1000);                         // esperar 1 segundo entre displays
  DateTime now = RTC.now();                  // Obtiene la fecha y hora del RTC
}
  
  /////// callback alarmas  //////
  
  void PrendoLed13(){                ///1am
    Serial.println ("PrendoLed13");
    digitalWrite (13,HIGH);
  }
  void PrendoLed2(){                 ///2am
    Serial.println ("PrendoLed2");
    digitalWrite (2,HIGH); 
  }
  void PrendoLed3(){                 ///3am
    Serial.println ("prendoLed3");
    digitalWrite (3,HIGH); 
  }
  void PrendoLed4(){                 ///4am
    Serial.println ("PrendoLed4");
    digitalWrite (4,HIGH);
  }
  void PrendoLed5()
  {                 ///5am
    Serial.println ("PrendoLed5");
    digitalWrite (5,HIGH); 
  }
  void PrendoLed6(){                 ///6am
    Serial.println ("PrendoLed6");
    digitalWrite (6,HIGH);
  }
  void PrendoLed7(){                 ///7am  
    Serial.println ("PrendoLed7");
    digitalWrite (7,HIGH); 
  }
  void PrendoLed8(){                 ///8am
    Serial.println ("PrendoLed8");
    digitalWrite (8,HIGH); 
  }
  void PrendoLed9(){                 ///9am
    Serial.println ("PrendoLed9");
    digitalWrite (9,HIGH); 
  }
  void PrendoLed10 (){                ///10am
    Serial.println ("PrendoLed10");
    digitalWrite (10,HIGH); 
  } 
  void PrendoLed11(){                ///11am
    Serial.println ("PrendoLed11");
    digitalWrite (11,HIGH); 
  } 
  void PrendoLed12(){                ///12am
    Serial.println ("PrendoLed12");
    digitalWrite (12,HIGH); 
  } 
///  
 void ApagoLed(misled[i]){ 

  for(int i=0 ;i<12; i++)
   {
   digitalWrite (misleds[i],apagoleds[i]); 
    Serial.println ("ApagoLeds");}
  }

////////    PM   ///////     
  void PrendoLed13(){                ///1pm
    Serial.println ("PrendoLed13");
    digitalWrite (13,HIGH); 
  }
  void PrendoLed2(){                 ///2pm
    Serial.println ("PrendoLed2");
    digitalWrite (2,HIGH); 
  }
  void PrendoLed3(){                 ///3pm
    Serial.println ("PrendoLed3");
    digitalWrite (3,HIGH); 
  }
  void PrendoLed4(){                 ///4pm
    Serial.println ("PrendoLed4");
    digitalWrite (4,HIGH); 
  }
  void PrendoLed5(){                 ///5pm
    Serial.println ("PrendoLed5");
    digitalWrite (5,HIGH); 
  }
  void PrendoLed6(){                 ///6pm
    Serial.println ("PrendoLed6");
    digitalWrite (6,HIGH); 
  }
  void PrendoLed7(){                 ///7pm  
    Serial.println ("PrendoLed7");
    digitalWrite (7,HIGH); 
  }
  void PrendoLed8 (){                 ///8pm
    Serial.println ("PrendoLed8");
    digitalWrite (8,HIGH); 
  }
  void PrendoLed9(){                 ///9pm
    Serial.println ("PrendoLed9");
    digitalWrite (9,HIGH); 
  }
  void PrendoLed10(){                ///10pm
    Serial.println ("PrendoLed10")
    digitalWrite (10,HIGH) 
  } 
  void PrendoLed11 (){                ///11pm
    Serial.println ("PrendoLed11");
    digitalWrite (11,HIGH); 
  } 
  void PrendoLed12(){                ///12pm
    Serial.println ("PrendoLed12");
    digitalWrite (12,HIGH); 
  } 
///
 void ApagoLed(misled[i]){ 

  for(int i=0 ;i<12; i++)
   {
   digitalWrite (misleds[i],apagoleds[i]); 
    Serial.println ("ApagoLeds");}
  }

 void digitalClockDisplay()
{
 // digital clock display of the time
 Serial.print(hour());
 printDigits(minute());
 printDigits(second());
 Serial.println(); 
}
 
void printDigits(int digits)
{
 Serial.print(":");
 if(digits < 10)
 Serial.print('0');
 Serial.print(digits);
}

Aquí les dejo el error:

pruebareloj:135:15: error: variable or field 'ApagoLed' declared void

  void ApagoLed(misled[i]){ 

               ^

pruebareloj:135:15: error: 'misled' was not declared in this scope

pruebareloj:135:22: error: 'i' was not declared in this scope

  void ApagoLed(misled[i]){ 

                      ^

C:UsersWladimirDocumentsArduinopruebarelojpruebareloj.ino: In function 'void setup()':

pruebareloj:72:47: error: 'i' was not declared in this scope

   Alarm.alarmRepeat(00,59,0, ApagoLed(misleds[i]); 

                                               ^

pruebareloj:72:49: error: 'ApagoLed' was not declared in this scope

   Alarm.alarmRepeat(00,59,0, ApagoLed(misleds[i]); 

                                                 ^

C:UsersWladimirDocumentsArduinopruebarelojpruebareloj.ino: At global scope:

pruebareloj:135:16: error: variable or field 'ApagoLed' declared void

  void ApagoLed(misled[i]){ 

                ^

pruebareloj:135:16: error: 'misled' was not declared in this scope

pruebareloj:135:23: error: 'i' was not declared in this scope

  void ApagoLed(misled[i]){ 

                       ^

exit status 1
variable or field 'ApagoLed' declared void

Tienes repetidas las funciones..
Si llamas a algo PrendoLed13 no puedes ponerlo para AM y PM. Con una basta porque será la misma.

Elimina todo lo repetido incluso el apagoLed

Todo repetido.

Cambié lo que está repetido, pero aun persiste el error mencionado para la alarma ApagoLed

La funcion apagoled() esta mal declarada. Quita el argumento.

void apagoled(){
}

He quitado el argumento de "ApagoLed", pero ahora me dice que no he declarado las alarmas. En los ejemplos que he visto esto no es necesario.

In function 'void setup()':

pruebareloj:30:30: error: 'PrendoLed' was not declared in this scope

   Alarm.alarmRepeat(1, 0, 0, PrendoLed);  //enciendehora1
[code]


Inclusive ahora me arroja error al declarar las librerías, claramente algo no está bien.


[code]

pruebareloj:9:19: error: expected initializer before 'setup'

 #include <TimeAlarms.h>

                   ^

pruebareloj:12:1: error: expected initializer before 'void'

 void setup() {

 ^

exit status 1
expected initializer before 'setup'
[code]

Gracias.

No te dijo que lo quites, te dijo que quites el argumento

de esto

void ApagoLed(misled[i]){

a esto

void ApagoLed(){

Prueba esto:

// Conexion i2C :Arduino UNO  SCL-> A5   SDA->A4  VCC->5V  GND->GND
// Conexion RTC :Arduino UNO    GND->GND VCC->5V SCL-> SCL  SDA->SDA los dos pines despues del ...12,13,GND,AREF,SDA,SCL
// Conexion Rele:Arduino UNO GND->GND  VCC->5V  IN->7
// NOTA: se debe cargar dos veces este programa 1. Con la linea  RTC.adjust(DateTime(__DATE__, __TIME__)); 
//                                              2. Sin esa linea
#include <Wire.h> 
#include "RTClib.h"
#include <TimeLib.h>
#include <TimeAlarms.h>
RTC_DS3231 RTC;
int misleds[12]   = {13, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12};
int apagoleds[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

//////////////////////  void setup()  //////////////////////////

void setup() {
    
    Wire.begin();    
    Serial.begin(9600);                           
    RTC.begin();                                // Inicia la comunicaci¢n con el RTC
 
  //RTC.adjust(DateTime(__DATE__, __TIME__)); // Lee la fecha y hora del PC (Solo en la primera carga)
                                             // el anterior se usa solo en la configuracion inicial luego se pone como comentario
                                             // y se vuelve a cargar el programa sin esa linea.

  ////////  salidas  /////////
   
  for(int i=0 ; i<12; i++)  {
    pinMode(misleds[i], OUTPUT);
  }
        ///////////////  alarmas  /////////////// 
  Alarm.alarmRepeat( 2, 0, 0, PrendoLed2);
  Alarm.alarmRepeat( 3, 0, 0, PrendoLed3);
  Alarm.alarmRepeat( 4, 0, 0, PrendoLed4);
  Alarm.alarmRepeat( 5, 0, 0, PrendoLed5);
  Alarm.alarmRepeat( 6, 0, 0, PrendoLed6);
  Alarm.alarmRepeat( 7, 0, 0, PrendoLed7);
  Alarm.alarmRepeat( 8, 0, 0, PrendoLed8);
  Alarm.alarmRepeat( 9, 0, 0, PrendoLed9);
  Alarm.alarmRepeat(10, 0, 0, PrendoLed10);
  Alarm.alarmRepeat(11, 0, 0, PrendoLed11);
  Alarm.alarmRepeat(12, 0, 0, PrendoLed12);
  Alarm.alarmRepeat( 1, 0, 0, PrendoLed13);  //enciendehora1  
//
  Alarm.alarmRepeat(14, 0, 0, PrendoLed2);
  Alarm.alarmRepeat(15, 0, 0, PrendoLed3);
  Alarm.alarmRepeat(16, 0, 0, PrendoLed4);
  Alarm.alarmRepeat(17, 0, 0, PrendoLed5);
  Alarm.alarmRepeat(18, 0, 0, PrendoLed6);
  Alarm.alarmRepeat(19, 0, 0, PrendoLed7);
  Alarm.alarmRepeat(20, 0, 0, PrendoLed8);
  Alarm.alarmRepeat(21, 0, 0, PrendoLed9);
  Alarm.alarmRepeat(22, 0, 0, PrendoLed10);
  Alarm.alarmRepeat(23, 0, 0, PrendoLed11);
  Alarm.alarmRepeat(00, 0, 0, PrendoLed12);
  Alarm.alarmRepeat(13, 0, 0, PrendoLed13);
//
        /////alarma de apagado/////
  Alarm.alarmRepeat(00,59,0, ApagoLed); 
  Alarm.alarmRepeat(12,59,0, ApagoLed);
}

//////////////////////  void loop () ///////////////////
void loop () {
  
  digitalClockDisplay();
  Alarm.delay(1000);                         // esperar 1 segundo entre displays
  DateTime now = RTC.now();                  // Obtiene la fecha y hora del RTC
}
  
/////// callback alarmas  //////

void PrendoLed13(){                ///1am
  Serial.println ("PrendoLed13");
  digitalWrite (13,HIGH);
}
void PrendoLed2(){                 ///2am
  Serial.println ("PrendoLed2");
  digitalWrite (2,HIGH); 
}
void PrendoLed3(){                 ///3am
  Serial.println ("prendoLed3");
  digitalWrite (3,HIGH); 
}
void PrendoLed4(){                 ///4am
  Serial.println ("PrendoLed4");
  digitalWrite (4,HIGH);
}
void PrendoLed5()
{                 ///5am
  Serial.println ("PrendoLed5");
  digitalWrite (5,HIGH); 
}
void PrendoLed6(){                 ///6am
  Serial.println ("PrendoLed6");
  digitalWrite (6,HIGH);
}
void PrendoLed7(){                 ///7am  
  Serial.println ("PrendoLed7");
  digitalWrite (7,HIGH); 
}
void PrendoLed8(){                 ///8am
  Serial.println ("PrendoLed8");
  digitalWrite (8,HIGH); 
}
void PrendoLed9(){                 ///9am
  Serial.println ("PrendoLed9");
  digitalWrite (9,HIGH); 
}
void PrendoLed10 (){                ///10am
  Serial.println ("PrendoLed10");
  digitalWrite (10,HIGH); 
} 
void PrendoLed11(){                ///11am
  Serial.println ("PrendoLed11");
  digitalWrite (11,HIGH); 
} 
void PrendoLed12(){                ///12am
  Serial.println ("PrendoLed12");
  digitalWrite (12,HIGH); 
} 

void ApagoLed(){ 

  for (int i=0 ;i<12; i++) {
      digitalWrite (misleds[i],apagoleds[i]); 
      Serial.println ("ApagoLeds");}
}

void digitalClockDisplay() {
  // digital clock display of the time
  char buffer[10];
  sprintf(buffer, "%02d:%02d:%02d", hour(), minute(), second());
  Serial.println(buffer); 
}

Cuidado con el uso de now.
Lo asignas en el loop pero no lo usas.

D:/Dropbox/Arduino/Foro/Borrar/Cin/389046.ino:68:12: warning: variable 'now' set but not used [-Wunused-but-set-variable]
DateTime now = RTC.now();                  // Obtiene la fecha y hora del RTC
^

En realidad no se necesita tanta libreria y hay que aprovechar mas la matriz.

#include <Wire.h>    // Conexion i2C :Arduino UNO  SCL-> A5   SDA->A4
#include <RTClib.h>

RTC_DS3231 RTC;
const byte misleds[12] = {13,2,3,4,5,6,7,8,9,10,11,12};
DateTime now;

void setup() { 
   Serial.begin(9600);                           
   Wire.begin();    
   RTC.begin();                                // Inicia la comunicación con el RTC
   //RTC.adjust(DateTime(__DATE__, __TIME__)); // Lee la fecha y hora del PC (Solo en la primera carga)

   ////////  salidas  /////////
   for (byte i=0; i<12; i++){
      pinMode(misleds[i], OUTPUT);
   }
}

void loop() {
   now = RTC.now();
   byte hora;
   digitalClockDisplay();
   if (now.unixtime()%3600 == 0){
      if (now.hour() <12){
         hora = now.hour();
      }else{
         hora = now.hour() - 12;
      }
      digitalWrite(misleds[hora], HIGH);
   }
   if (now.hour()%12 == 0 && now.minute() == 59 && now.second() == 59){
      for (byte i=0; i<12; i++){
         digitalWrite(misleds[i], LOW); 
      }
      Serial.println ("ApagoLeds");
   }
}

//Mostrar hora por consola
void digitalClockDisplay(){
   Serial.print(now.hour());
   printDigits(now.minute());
   printDigits(now.second());
   Serial.println(); 
}

void printDigits(byte digits){
   Serial.print(":");
   if (digits<10){
      Serial.print('0');
   }
   Serial.print(digits);
}

Perdón por no responder. Muchas gracias por las sugerencias, probaré ambas opciones. Les cuento como me va en cuanto pueda hacerlo.

Fijate que declaraste el array misleds[12] y después llamás al void ApagoLed(misled*). Hay un error de ortografía, uno singular y el otro en plural. El compilador interpreta que misled y misleds son distintos.*

Tienes razó Pablo pero como tantos errores de lo que se publica aquí. Hay varios errores mas que no hemos comentado de { ; etc.
Ese que mencionas es otro.

Pablo_Lucini:
Fijate que declaraste el array misleds[12] y después llamás al void ApagoLed(misled*). Hay un error de ortografía, uno singular y el otro en plural. El compilador interpreta que misled y misleds son distintos.[/quote]*
1. La matriz misleds[] es publica por lo que la función Apagoled() no requiere argumento.
2. Al definir el evento incluye la matriz publica como argumento y con una variable que no existe llamada i.
* *Alarm.alarmRepeat(00,59,0, ApagoLed(misleds[i]); Alarm.alarmRepeat(12,59,0, ApagoLed(misleds[i]);* *
La solución a dicho problema es quitar el argumento en ambos casos así:
```
*Alarm.alarmRepeat(00,59,0, ApagoLed();
Alarm.alarmRepeat(12,59,0, ApagoLed();

void ApagoLed(){
  for (int i=0 ;i<12; i++)  {
      digitalWrite(misleds[i], apagoleds[i]);  //Es igual que poner digitalWrite(misleds[i], LOW);
      Serial.println("ApagoLeds");}
  }
}        //Falta esta llave en tu codigo*

```

Corregí el error de "ApagoLed" como lo mencionó Surbyte y Kike, pude compilar el programa, muchas gracias.
Por lo pronto, debido al trabajo no tendré a mano mi arduino para montar el circuito y verificar el programa por un tiempo, por lo que estoy tratando de simularlo en Proteus 8.7. Pero no se enciende ningún Led a la hora de llamar cualquier alarma. No sé si es necesario tener la librería TimeAlarms en Proteus para que pueda funcionar el programa o el sketch no está bien configurado. Busqué alguna posible librería para Proteus, pero no la encuentro.
Saludos.

Kike, intenté compilar tu segunda opción sin utilizar las librerías, pero me arroja este error:

exit status 1
'hora' was not declared in this scope

Lo cual me parece extraño porque veo que ya lo declaraste en el mismo void.
Saludos y gracias.

A ver.. cuando algo no esta declarado hay que esforzarse y buscarle la vuelta.

void loop() {
   DateTime now = RTC.now();
   digitalClockDisplay();
   if (now.unixtime()%3600 == 0){
      if (now.hour() <=12){
         byte hora = now.hour();  // <= aca lo define
      }else{
         byte hora = now.hour() - 12;   <= aca lo define de nuevo

Conclusión, no era mas facil definirlo asi?

void loop() {
   byte hora;
   DateTime now = RTC.now();
   digitalClockDisplay();
   if (now.unixtime()%3600 == 0){
      if (now.hour() <=12){
         hora = now.hour();
      }else{
         hora = now.hour() - 12;
      }
      digitalWrite(misleds[now.hour(hora)], HIGH);
   }
   if (now.hour()%12 == 0 && now.minute() == 59 && now.second() == 59){
      for (byte i=0; i<12; i++){
         digitalWrite(misleds[i], LOW); 
      }
      Serial.println ("ApagoLeds");
   }
}

wparada:
Kike, intenté compilar tu segunda opción sin utilizar las librerías, pero me arroja este error:

Opps, tienes razón, la variable now yo la declaraba en loop(), pero tenia que ser publica porque se usa también en la función digitalClockDisplay().

Edite mi mensaje anterior, por favor vuelve a intentar con ese código.

PD: También cambie la variable hora como nos sugiere SurByte, gracias.

Para probar tu reloj tendras que estarlo mirando durante horas y eso te tomara mucho tiempo. Con el mismo hardware prueba este codigo que es mas rapido.

#include <RTClib.h>
RTC_Millis rtc;
const byte led[12] = {13,2,3,4,5,6,7,8,9,10,11,12};

void setup() { 
   rtc.adjust(DateTime(__DATE__, __TIME__));
   for (byte i=0; i<12; i++){
      pinMode(led[i], OUTPUT);
   }
}

void loop() {
   DateTime hoy = rtc.now();
   if (hoy.unixtime()%5 == 0){
      for (byte i=0; i<12; i++){
         digitalWrite(led[i], LOW);
      }
      byte hora = hoy.second()/5;
      digitalWrite(led[hora], HIGH);
   }
}

Finalmente logré terminar el proyecto con la programación que me sugirió Kiki_GL, la simulación del reloj se realiza a la perfección.
Sin embargo, no lo pude hacer con las modificaciones que le hice al utilizar la función de Time Alarms, revisé una y otra vez y no pude encontrar el error.
Igualmente muchas gracias a surbyte y a los que aportaron en este post.
No sé si poner como solucionado el post haciendo referencia al tema principal de las funciones.
Saludos

Que es lo que no funciona?