tomi8822 Creative Commons License 2017.12.31 0 0 3298

Üdv,össze raktam magamnak egy kódot, de nem kapcsol rendesen, segítsetek kijavítani, köszönöm.

 

#include <Wire.h>
#include <RTClib.h>
#include <Time.h>
#include <TimeAlarms.h>
 
RTC_DS1307 RTC;
 
// Start Time Light 1
int sHour = 06;
int sMinute = 40;
int sSecond = 0;

// Start Time Light 2
int s2Hour = 07;
int s2Minute = 00;
int s2Second = 00;

// Start Time Light 3
int s3Hour = 07;
int s3Minute = 20;
int s3Second = 00; 

// Start Time Light 4
int s4Hour = 07;
int s4Minute = 40;
int s4Second = 00;

// Start Time Light 5
int s5Hour = 07;
int s5Minute = 00;
int s5Second = 00;

// Start Time Light 6
int s6Hour = 07;
int s6Minute = 20;
int s6Second = 24; 

// End Time Light 1
int eHour = 17;
int eMinute = 40;
int eSecond = 00;

// End Time Light 2
int e2Hour = 18;
int e2Minute = 00;
int e2Second = 00;

// End Time Light 3
int e3Hour = 18;
int e3Minute = 20;
int e3Second = 00;

// End Time Light 4
int e4Hour = 18;
int e4Minute = 40;
int e4Second = 00;

// End Time Light 5
int e5Hour = 19;
int e5Minute = 00;
int e5Second = 00;

// End Time Light 6
int e6Hour = 19;
int e6Minute = 20;
int e6Second = 00;
 
int lightRelay1 = 9;
int lightRelay2 = 2;
int lightRelay3 = 3;
int lightRelay4 = 4;
int lightRelay5 = 5;
int lightRelay6 = 6;

void setup() {
  // Set the relay to off immediately
  digitalWrite(lightRelay1, HIGH);
  digitalWrite(lightRelay2, HIGH);
  digitalWrite(lightRelay3, HIGH); 
  digitalWrite(lightRelay4, HIGH);
  digitalWrite(lightRelay5, HIGH);
  digitalWrite(lightRelay6, HIGH); 
  Serial.begin(9600);
  Wire.begin();
  RTC.begin();
   
  // Set the pinmode
  pinMode(lightRelay1, OUTPUT);
  pinMode(lightRelay2, OUTPUT);
  pinMode(lightRelay3, OUTPUT);
  pinMode(lightRelay4, OUTPUT);
  pinMode(lightRelay5, OUTPUT);
  pinMode(lightRelay6, OUTPUT);
  
  // Notify if the RTC isn't running
  if (! RTC.isrunning()) {
    Serial.println("RTC is NOT running");
  }
 
  // Get time from RTC
  DateTime current = RTC.now();
  DateTime compiled = DateTime(__DATE__, __TIME__);
  if (current.unixtime() < compiled.unixtime()) {
    Serial.println("RTC is older than compile time! Updating");
    RTC.adjust(DateTime(__DATE__, __TIME__));    
  }
    
   // Use RTC time to set the start time1
  setTime(sHour, sMinute, sSecond, current.day(), current.month(), current.year());
  time_t s = now();
  
   // Use RTC time to set the start time2
  setTime(s2Hour, s2Minute, s2Second, current.day(), current.month(), current.year());
  time_t s2 = now();
  
   // Use RTC time to set the start time3
  setTime(s3Hour, s3Minute, s3Second, current.day(), current.month(), current.year());
  time_t s3 = now();
  
   // Use RTC time to set the start time4
  setTime(s4Hour, s4Minute, s4Second, current.day(), current.month(), current.year());
  time_t s4 = now();
  
   // Use RTC time to set the start time5
  setTime(s5Hour, s5Minute, s5Second, current.day(), current.month(), current.year());
  time_t s5 = now();
  
   // Use RTC time to set the start time6
  setTime(s6Hour, s6Minute, s6Second, current.day(), current.month(), current.year());
  time_t s6 = now();
  
   // Use RTC time to set the end time1
  setTime(eHour, eMinute, eSecond, current.day(), current.month(), current.year());
  time_t e = now();
  
   // Use RTC time to set the end time2
  setTime(e2Hour, e2Minute, e2Second, current.day(), current.month(), current.year());
  time_t e2 = now();
  
   // Use RTC time to set the end time3
  setTime(e3Hour, e3Minute, e3Second, current.day(), current.month(), current.year());
  time_t e3 = now();
  
   // Use RTC time to set the end time4
  setTime(e4Hour, e4Minute, e4Second, current.day(), current.month(), current.year());
  time_t e4 = now();
  
   // Use RTC time to set the end time5
  setTime(e5Hour, e5Minute, e5Second, current.day(), current.month(), current.year());
  time_t e5 = now();
  
   // Use RTC time to set the end time6
  setTime(e6Hour, e6Minute, e6Second, current.day(), current.month(), current.year());
  time_t e6 = now();
  
   // Use RTC time to set the current time
  setTime(current.hour(), current.minute(), current.second(), current.day(), current.month(), current.year());  
  time_t n = now();
  
  // Test if grow light should be on
  if (s <= n && n <= e) {
    digitalWrite(lightRelay1, LOW);  // Sets the grow light "on"
  }
  if (s2 <= n && n <= e2) {
    digitalWrite(lightRelay2, LOW);  // Sets the grow light "on"
  }
  if (s3 <= n && n <= e3) {
    digitalWrite(lightRelay3, LOW);  // Sets the grow light "on"
  }
  if (s4 <= n && n <= e4) {
    digitalWrite(lightRelay4, LOW);  // Sets the grow light "on"
  }
  if (s5 <= n && n <= e5) {
    digitalWrite(lightRelay5, LOW);  // Sets the grow light "on"
  }
  if (s6 <= n && n <= e6) {
    digitalWrite(lightRelay6, LOW);  // Sets the grow light "on"
  }
  Alarm.alarmRepeat(sHour, sMinute, sSecond, Light1On);
  Alarm.alarmRepeat(eHour, eMinute, eSecond, Light1Off);
  Alarm.alarmRepeat(s2Hour, s2Minute, s2Second, Light2On);
  Alarm.alarmRepeat(e2Hour, e2Minute, e2Second, Light2Off);
  Alarm.alarmRepeat(s3Hour, s3Minute, s3Second, Light3On);
  Alarm.alarmRepeat(e3Hour, e3Minute, e3Second, Light3Off);
  Alarm.alarmRepeat(s4Hour, s4Minute, s4Second, Light4On);
  Alarm.alarmRepeat(e4Hour, e4Minute, e4Second, Light4Off);
  Alarm.alarmRepeat(s5Hour, s5Minute, s5Second, Light5On);
  Alarm.alarmRepeat(e5Hour, e5Minute, e5Second, Light5Off);
  Alarm.alarmRepeat(s6Hour, s6Minute, s6Second, Light6On);
  Alarm.alarmRepeat(e6Hour, e6Minute, e6Second, Light6Off);
}
 
void loop() {
  DateTime now = RTC.now();
  setTime(now.hour(), now.minute(), now.second(), now.day(), now.month(), now.year());
   
  Serial.print("Current time: ");
  Serial.print(now.year(), DEC);
  Serial.print('/');
  Serial.print(now.month(), DEC);
  Serial.print('/');
  Serial.print(now.day(), DEC);
  Serial.print(' ');
  Serial.print(now.hour(), DEC);
  Serial.print(':');
  Serial.print(now.minute(), DEC);
  Serial.print(':');
  Serial.print(now.second(), DEC);
  Serial.println();
     
  Serial.println();
  Alarm.delay(600000);
}
void Light1On() {
  Serial.println("Turning Light 1 On");
  digitalWrite(lightRelay1, LOW);
}
void Light1Off() {
  Serial.println("Turning Light 1 Off");
  digitalWrite(lightRelay1, HIGH);
}
 void Light2On() {
  Serial.println("Turning Light 2 On");
  digitalWrite(lightRelay2, LOW);
}
void Light2Off() {
  Serial.println("Turning Light 2 Off");
  digitalWrite(lightRelay2, HIGH);
}
 void Light3On() {
  Serial.println("Turning Light 3 On");
  digitalWrite(lightRelay3, LOW);
}
void Light3Off() {
  Serial.println("Turning Light 3 Off");
  digitalWrite(lightRelay3, HIGH);
}
 void Light4On() {
  Serial.println("Turning Light 4 On");
  digitalWrite(lightRelay4, LOW);
}
void Light4Off() {
  Serial.println("Turning Light 4 Off");
  digitalWrite(lightRelay4, HIGH);
}
 void Light5On() {
  Serial.println("Turning Light 5 On");
  digitalWrite(lightRelay5, LOW);
}
void Light5Off() {
  Serial.println("Turning Light 5 Off");
  digitalWrite(lightRelay5, HIGH);
}
 void Light6On() {
  Serial.println("Turning Light 6 On");
  digitalWrite(lightRelay6, LOW);
}
void Light6Off() {
  Serial.println("Turning Light 6 Off");
  digitalWrite(lightRelay6, HIGH);
}