Commit dd13ea416283840df0546e0365d8d1bd40b87bf5

Authored by csaad
1 parent 291f2cfa

création automatique(), utilisation capteur presence et controle led automatique en meme temps

Showing 1 changed file with 57 additions and 23 deletions   Show diff stats
progArduino/principal/principal.ino
@@ -11,7 +11,7 @@ @@ -11,7 +11,7 @@
11 //INIT CAPTEUR PRESENCE 11 //INIT CAPTEUR PRESENCE
12 12
13 //temps donné pour calibrer le capteur de présence.(10-60 secs according to the datasheet) 13 //temps donné pour calibrer le capteur de présence.(10-60 secs according to the datasheet)
14 -int calibrationTime = 20; 14 +int calibrationTime = 10;
15 //the time when the sensor outputs a low impulse 15 //the time when the sensor outputs a low impulse
16 long unsigned int lowIn; 16 long unsigned int lowIn;
17 //the amount of milliseconds the sensor has to be low 17 //the amount of milliseconds the sensor has to be low
@@ -204,10 +204,10 @@ void mouvement() @@ -204,10 +204,10 @@ void mouvement()
204 { 204 {
205 //makes sure we wait for a transition to LOW before any further output is made: 205 //makes sure we wait for a transition to LOW before any further output is made:
206 lockLow = false; 206 lockLow = false;
207 - Serial.println("---");  
208 - Serial.print("motion detected at ");  
209 - Serial.print(millis()/1000);  
210 - Serial.println(" sec"); 207 + //Serial.println("---");
  208 + //Serial.print("motion detected at ");
  209 + //Serial.print(millis()/1000);
  210 + //Serial.println(" sec");
211 delay(50); 211 delay(50);
212 } 212 }
213 takeLowTime = true; 213 takeLowTime = true;
@@ -229,12 +229,14 @@ void mouvement() @@ -229,12 +229,14 @@ void mouvement()
229 //makes sure this block of code is only executed again after 229 //makes sure this block of code is only executed again after
230 //a new motion sequence has been detected 230 //a new motion sequence has been detected
231 lockLow = true; 231 lockLow = true;
232 - Serial.print("motion ended at "); //output  
233 - Serial.print((millis() - pause)/1000);  
234 - Serial.println(" sec"); 232 + //Serial.print("motion ended at "); //output
  233 + //Serial.print((millis() - pause)/1000);
  234 + //Serial.println(" sec");
235 i++; 235 i++;
  236 + Serial.println(i);
236 //CHILD IS AWAKE 237 //CHILD IS AWAKE
237 - if(i==5 || ((millis() - pause)/1000)-(millis()/1000)> 10 ){ 238 + // if(i==5 || ((millis() - pause)/1000)-(millis()/1000)> 10
  239 + if(i==5){
238 Serial.println("Sommeil agite !!!"); 240 Serial.println("Sommeil agite !!!");
239 MESSAGE = 1; //servira pour la progra html (peut-être) 241 MESSAGE = 1; //servira pour la progra html (peut-être)
240 Serial.println(MESSAGE); 242 Serial.println(MESSAGE);
@@ -246,6 +248,41 @@ void mouvement() @@ -246,6 +248,41 @@ void mouvement()
246 } 248 }
247 } 249 }
248 250
  251 +
  252 +void automatique()
  253 +{
  254 + //On récupère la valeur du seuil
  255 + luminosite = analogRead(CAPTEUR);
  256 + int mouv =1;
  257 +
  258 + //Monitoring
  259 + Serial.print("Luminosite = ");
  260 + Serial.print(luminosite);
  261 + Serial.print(" / Seuil = ");
  262 + Serial.print(seuil);
  263 +
  264 + //Allumage de la led si la luminosité est inférieur au seuil (on l'allume dans la couleur blanche la base)
  265 + if(luminosite < seuil) {
  266 + couleur(255,255,255);
  267 + //Monitoring
  268 + Serial.println(" / LED ON");
  269 + }
  270 + //Dans le cas contraire, on l'éteint
  271 + else {
  272 + digitalWrite(PININ, LOW);
  273 + mouv=0;
  274 + eteindre();
  275 + Serial.println(" / LED OFF");
  276 + }
  277 + delay(50);
  278 +
  279 + if(mouv == 1)
  280 + {
  281 + //Serial.println("mouv");
  282 + mouvement();
  283 + }
  284 +}
  285 +
249 //---------------------------------------------------------------------------------------------------------------------------FONCTIONS PRINCIPALES 286 //---------------------------------------------------------------------------------------------------------------------------FONCTIONS PRINCIPALES
250 287
251 288
@@ -253,24 +290,20 @@ void mouvement() @@ -253,24 +290,20 @@ void mouvement()
253 void mainVeilleuse() 290 void mainVeilleuse()
254 { 291 {
255 etatBouton = digitalRead(pinInter); //Rappel :pinInter = 9 292 etatBouton = digitalRead(pinInter); //Rappel :pinInter = 9
256 - 293 +
257 //si la veilleuse est allumé et interrupteur = LOW on utilise le mode automatique. 294 //si la veilleuse est allumé et interrupteur = LOW on utilise le mode automatique.
258 while (etatBouton == LOW) //test si le bouton a un niveau logique HAUT 295 while (etatBouton == LOW) //test si le bouton a un niveau logique HAUT
259 - {  
260 - //le bouton est appuyée, la LED est allumée  
261 - //couleur(255,255,255);  
262 - //delay(1000);  
263 - //couleur(0,0,0); 296 + {
264 delay(1000); 297 delay(1000);
265 -  
266 - lumiere_auto();  
267 - 298 +
  299 + automatique();
  300 +
268 etatBouton = digitalRead(pinInter); //Rappel :pinInter = 9 301 etatBouton = digitalRead(pinInter); //Rappel :pinInter = 9
269 } 302 }
270 - 303 +
271 //on est eteint avec l'interrupteur manuel on peut tjrs utiliser l'application pour gerer la veilleuse 304 //on est eteint avec l'interrupteur manuel on peut tjrs utiliser l'application pour gerer la veilleuse
272 eteindre(); //la LED reste éteinte 305 eteindre(); //la LED reste éteinte
273 - Serial.println("UTILISATION APPLICATION: application"); 306 + Serial.println("UTILISATION APPLICATION");
274 307
275 308
276 } 309 }
@@ -285,8 +318,9 @@ void tests() @@ -285,8 +318,9 @@ void tests()
285 //eteindre(); 318 //eteindre();
286 //choix_intensite(); 319 //choix_intensite();
287 //choix_type_allumage(); 320 //choix_type_allumage();
288 - mouvement(); 321 + //mouvement();
289 //lumiere_auto(); 322 //lumiere_auto();
  323 + automatique();
290 delay(200); 324 delay(200);
291 } 325 }
292 326
@@ -297,8 +331,8 @@ void tests() @@ -297,8 +331,8 @@ void tests()
297 void loop() 331 void loop()
298 332
299 { 333 {
300 - tests(); 334 + //tests();
301 335
302 - //mainVeilleuse(); 336 + mainVeilleuse();
303 delay(200); 337 delay(200);
304 } 338 }