Schedule actions with arduino and RTC

0

I'm making a luminaire for aquariums where in theory the sunrise, midday sun, dusk and on random days simulate a lightning storm, try to get closer to the fish habitat of rivers and avoid the stress of simply in the morning the maximum light from the luminaire would turn on and give the fish a nuisance.

I gave a summary in the code taking some other functions, I left only what interests.

I need to start some functions at certain times and only succeeded in the first function (dawn ()), after this the next (EntraDia ()) should be a complement of the initial and some time after the initial (dawn () ), it would turn off and it would only be the second (EntraDia ()) that after 8 hours would turn off, but, this does not happen, it simply resets to (dawn ()) and stays in this cycle.

If anyone knows a way to do these schedules, I'll be very grateful.

#include <Wire.h>
#include "RTClib.h"

#define RED 10  // pino PWM 13 para a cor vermelha
#define GREEN 9 // pino PWM 12 para a cor verde
#define BLUE 6// pino PWM 11 para a cor azul

//HORA A SER COMPARADA
int HoraAtual = 0;
int MinAtual = 0;

//HORARIOS DE AÇÕES
int H_amanhecer = 21;
int M_amanhecer = 20;

int H_EntraDia = 21;
int M_EntraDia = 22;



RTC_DS1307 rtc;

char daysOfTheWeek[7][12] = {"Domingo", "Segunda", "Terça", "Quarta", "Quinta", "Sexta", "Sabado"};



void setup(){
while (!Serial); // for Leonardo/Micro/Zero

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

  if (! rtc.isrunning()) {
    Serial.println("RTC is NOT running!");
    // following line sets the RTC to the date & time this sketch was compiled
    //rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));

    // This line sets the RTC with an explicit date & time, for example to set
    // January 21, 2014 at 3am you would call:
    // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
  }

  pinMode(LED_BUILTIN, OUTPUT);


  // definindo os pinos como output
  pinMode(RED, OUTPUT);
  pinMode(GREEN, OUTPUT);
  pinMode(BLUE, OUTPUT);

}

void loop(){

 DateTime now = rtc.now();

    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    Serial.print(' ');

    Serial.print(now.day(), DEC);
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.year(), DEC);

    Serial.print(" ");
    Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
    Serial.println();

    delay(1000);

    HoraAtual = now.hour(), DEC;
    MinAtual = now.minute(), DEC;


//COMPARAÇÃO DA HORA PARA INICIAR A FUNÇÃO AMANHECER
/*
 * if (HoraAtual >= H_amanhecer && HoraAtual <= H_EntraDia)
{
    if (MinAtual >= M_amanhecer && MinAtual <= M_EntraDia)
  {
   Serial.println("Amanhecer em ação");
   amanhecer();
  }
  else{
      analogWrite(RED, 255);
      analogWrite(GREEN, 68);
      analogWrite(BLUE, 0);
  }
}
*/

//COMPARAÇÃO DA HORA PARA INICIAR A FUNÇÃO ENTRA DIA
if (HoraAtual >= H_EntraDia && HoraAtual <= H_dia)
{
    if (MinAtual >= M_EntraDia && MinAtual <= M_dia)
  {
   Serial.println("Entra dia em Ação");
   EntraDia();
  }
  else{
      analogWrite(RED, 255);
      analogWrite(GREEN, 238);
      analogWrite(BLUE, 223);
  }
}





}

void EntraDia(){
  //alvo 255,238,223
  int r, g, b, vr, vg, vb;

    for(r = 10; r <= 255; r++){    
    vg = r;
    vg = map(vg, 0, 255, 68, 238);
    analogWrite(GREEN, vg);
    vb = r;
    vb = map(vb, 0, 255, 0, 223);
    analogWrite(BLUE, vb);
    delay(500);
    //7500ms para 30 min
  }

}

void amanhecer(){
  //alvo 255,108,0
  //teste 255,68,0
    int r, g, b, vg, vb;

    for(r = 10; r <= 255; r++){
    analogWrite(RED, r);

    vg = r;
    vg = map(vg, 0, 255, 5, 68);
    analogWrite(GREEN, vg);

    analogWrite(BLUE, 0);
    delay(500);
    //7500ms para 30 min
    }


  }
    
asked by anonymous 11.03.2018 / 22:55

0 answers