From dd13ea416283840df0546e0365d8d1bd40b87bf5 Mon Sep 17 00:00:00 2001 From: csaad Date: Sun, 7 May 2017 20:45:15 +0200 Subject: [PATCH] création automatique(), utilisation capteur presence et controle led automatique en meme temps --- progArduino/principal/principal.ino | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 57 insertions(+), 23 deletions(-) diff --git a/progArduino/principal/principal.ino b/progArduino/principal/principal.ino index ad5bf9e..cd1ad8b 100644 --- a/progArduino/principal/principal.ino +++ b/progArduino/principal/principal.ino @@ -11,7 +11,7 @@ //INIT CAPTEUR PRESENCE //temps donné pour calibrer le capteur de présence.(10-60 secs according to the datasheet) -int calibrationTime = 20; +int calibrationTime = 10; //the time when the sensor outputs a low impulse long unsigned int lowIn; //the amount of milliseconds the sensor has to be low @@ -204,10 +204,10 @@ void mouvement() { //makes sure we wait for a transition to LOW before any further output is made: lockLow = false; - Serial.println("---"); - Serial.print("motion detected at "); - Serial.print(millis()/1000); - Serial.println(" sec"); + //Serial.println("---"); + //Serial.print("motion detected at "); + //Serial.print(millis()/1000); + //Serial.println(" sec"); delay(50); } takeLowTime = true; @@ -229,12 +229,14 @@ void mouvement() //makes sure this block of code is only executed again after //a new motion sequence has been detected lockLow = true; - Serial.print("motion ended at "); //output - Serial.print((millis() - pause)/1000); - Serial.println(" sec"); + //Serial.print("motion ended at "); //output + //Serial.print((millis() - pause)/1000); + //Serial.println(" sec"); i++; + Serial.println(i); //CHILD IS AWAKE - if(i==5 || ((millis() - pause)/1000)-(millis()/1000)> 10 ){ + // if(i==5 || ((millis() - pause)/1000)-(millis()/1000)> 10 + if(i==5){ Serial.println("Sommeil agite !!!"); MESSAGE = 1; //servira pour la progra html (peut-être) Serial.println(MESSAGE); @@ -246,6 +248,41 @@ void mouvement() } } + +void automatique() +{ + //On récupère la valeur du seuil + luminosite = analogRead(CAPTEUR); + int mouv =1; + + //Monitoring + Serial.print("Luminosite = "); + Serial.print(luminosite); + Serial.print(" / Seuil = "); + Serial.print(seuil); + + //Allumage de la led si la luminosité est inférieur au seuil (on l'allume dans la couleur blanche la base) + if(luminosite < seuil) { + couleur(255,255,255); + //Monitoring + Serial.println(" / LED ON"); + } + //Dans le cas contraire, on l'éteint + else { + digitalWrite(PININ, LOW); + mouv=0; + eteindre(); + Serial.println(" / LED OFF"); + } + delay(50); + + if(mouv == 1) + { + //Serial.println("mouv"); + mouvement(); + } +} + //---------------------------------------------------------------------------------------------------------------------------FONCTIONS PRINCIPALES @@ -253,24 +290,20 @@ void mouvement() void mainVeilleuse() { etatBouton = digitalRead(pinInter); //Rappel :pinInter = 9 - + //si la veilleuse est allumé et interrupteur = LOW on utilise le mode automatique. while (etatBouton == LOW) //test si le bouton a un niveau logique HAUT - { - //le bouton est appuyée, la LED est allumée - //couleur(255,255,255); - //delay(1000); - //couleur(0,0,0); + { delay(1000); - - lumiere_auto(); - + + automatique(); + etatBouton = digitalRead(pinInter); //Rappel :pinInter = 9 } - + //on est eteint avec l'interrupteur manuel on peut tjrs utiliser l'application pour gerer la veilleuse eteindre(); //la LED reste éteinte - Serial.println("UTILISATION APPLICATION: application"); + Serial.println("UTILISATION APPLICATION"); } @@ -285,8 +318,9 @@ void tests() //eteindre(); //choix_intensite(); //choix_type_allumage(); - mouvement(); + //mouvement(); //lumiere_auto(); + automatique(); delay(200); } @@ -297,8 +331,8 @@ void tests() void loop() { - tests(); + //tests(); - //mainVeilleuse(); + mainVeilleuse(); delay(200); } -- libgit2 0.21.2