Remy пре 5 година
родитељ
комит
e4d8c40539
1 измењених фајлова са 118 додато и 25 уклоњено
  1. 118 25
      Soft/tmp/tmp.ino

+ 118 - 25
Soft/tmp/tmp.ino

@@ -4,11 +4,29 @@
 #include <DS3231.h>
 #include <Wire.h>
 
-#define ONE_WIRE_BUS 3
+#define ONE_WIRE_BUS 2
 
-const int ExtracteurPin = 2;
-const int Rouge1Pin = 3;
-const int Rouge2Pin = 4;
+//pin relay
+const int ExtracteurPin   = 3;
+const int Rouge1Pin       = 4;
+const int Rouge2Pin       = 5;
+const int Bleu1Pin        = 6;
+const int Bleu2Pin        = 7;
+const int Bleu3Pin        = 8;
+const int DehumPin        = 9;
+
+//pin inter
+const int inter1  = 22;
+const int inter2  = 23;
+const int inter3  = 24;
+const int inter4  = 25;
+const int inter5  = 26;
+const int inter6  = 27;
+const int inter7  = 28;
+const int inter8  = 29;
+const int inter9  = 30;
+const int inter10 = 31;
+const int inter11 = 32;
 
 OneWire oneWire(ONE_WIRE_BUS);
 DS18B20 sensor(&oneWire);
@@ -17,38 +35,113 @@ DS3231 Clock;
 
 uint32_t start, stop;
 
-void setup(){
+void setup() {
   Serial.begin(9600);
-  Wire.begin();
+
+
+  /***********************************************************************
+                         init des pins
+  * *********************************************************************
+  */
   pinMode(ExtracteurPin, OUTPUT);
+  pinMode(Rouge1Pin, OUTPUT);
+  pinMode(Rouge2Pin, OUTPUT);
+  pinMode(Bleu1Pin, OUTPUT);
+  pinMode(Bleu2Pin, OUTPUT);
+  pinMode(DehumPin, OUTPUT);
+
+  pinMode(inter1, INPUT);   //inter extinction lumiere
+  pinMode(inter2, INPUT);   //inter marche forcé ventilation
+  pinMode(inter3, INPUT);   //60%
+  pinMode(inter4, INPUT);   //70%
+  pinMode(inter5, INPUT);   //80%
+  pinMode(inter6, INPUT);   //croissance mere
+  pinMode(inter7, INPUT);   //croissance mere + serre
+  pinMode(inter8, INPUT);   //Arrosage1 on
+  pinMode(inter9, INPUT);   //Arrosage2 on
+  pinMode(inter10, INPUT);  //pompe vidange on
+  pinMode(inter11, INPUT);
+
+  /***********************************************************************
+                         init des capteurs
+  * *********************************************************************
+  */
+  Wire.begin();
   sensor.begin();
   sensor.setResolution(12);
 }
 
 
-void loop(){
+void loop() {
+
+  /***********************************************************************
+                         Gestion des capteurs
+  * *********************************************************************
+  */
+  //temperature
   sensor.requestTemperatures();
   while (!sensor.isConversionComplete());
   float temp = sensor.getTempC();
+
+  //heure
+  bool h24, am;
+  int heure = Clock.getHour(h24, am );
   int minu = Clock.getMinute();
-  bool h24,am;
-  int heure = Clock.getHour(h24,am );
-  Serial.println("salut");
-  Serial.println(minu);
-  Serial.println(temp);
-  
-  if (minu==0 | minu == 1 | minu == 15 | minu == 16 | minu == 30 | minu == 31 | minu == 45 | minu == 46 |temp >= 27)
-    digitalWrite(ExtracteurPin,LOW);
-  else
-    digitalWrite(ExtracteurPin,HIGH);
+  int HMin = heure * 60 + minu; // heure en minute
+
+  //Hydrometrie
+
+  /***********************************************************************
+                          Gestion de la lumiere
+   * *********************************************************************
+  */
+  int newDay = 1; // Variable pour savoir si nouveau jour.
+  int HAFlo;  //heure allumage floraison en minute (9H45 ou 10H15)
+  int HEFlo;  //heure extinction floraison en minute (HaFlo +12H +/-15min)
+  int HACro;  //heure allumage croissance en minute (4H45 ou 5H15)
+  int HECro;  //heure extinction croissance en minute (HaFlo +18H +/-15min)
 
-  if(heure==10 | heure== 11 | heure== 12  | heure== 13 | heure== 14 | heure== 15 | heure== 16 | heure== 17 | heure== 18 | heure== 20  | heure== 21){
-    digitalWrite(Rouge1Pin,LOW);
-    digitalWrite(Rouge2Pin,LOW);  
+  if (newDay) {
+    newDay = 0;
+    HAFlo = random (585, 615);
+    HEFlo = HAFlo + 705 + random(30);
+    HACro = random (285, 315);
+    HECro = HACro + 1065 + random(30);
   }
-  else{
-    digitalWrite(Rouge1Pin,HIGH);
-    digitalWrite(Rouge2Pin,HIGH);
-  }   
-  delay(10000);
+
+  if (HMin == 0)
+    newDay = 1;
+
+  if (HMin >= HAFlo & HMin < HEFlo) {
+    digitalWrite(Rouge1Pin, LOW);
+    digitalWrite(Rouge2Pin, LOW);
+  }
+  else {
+    digitalWrite(Rouge1Pin, HIGH);
+    digitalWrite(Rouge2Pin, HIGH);
+  }
+
+  if (HMin >= HAFlo & HMin < HEFlo) {
+    digitalWrite(Bleu1Pin, LOW);
+    digitalWrite(Bleu2Pin, LOW);
+    digitalWrite(Bleu3Pin, LOW);
+  }
+  else {
+    digitalWrite(Bleu1Pin, HIGH);
+    digitalWrite(Bleu2Pin, HIGH);
+    digitalWrite(Bleu3Pin, HIGH);
+  }
+
+
+  /***********************************************************************
+                         Gestion de l'extraction
+  * *********************************************************************
+  */
+  if (minu == 0 | minu == 1 | temp >= 27)
+    digitalWrite(ExtracteurPin, LOW);
+  else
+    digitalWrite(ExtracteurPin, HIGH);
+
+
+  delay(1000);
 }