From 38e849ce96e6c7ccbe22081abebc0475dcce776d Mon Sep 17 00:00:00 2001 From: csaad Date: Wed, 3 May 2017 22:09:42 +0200 Subject: [PATCH] ajout dossier programmes arduino --- progArduino/controle_led/controle_led.ino | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ progArduino/detectionmouv/detectionmouv.ino | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ progArduino/poubelle_tests/arduinocapteurmouv.fzz | Bin 0 -> 22473 bytes progArduino/poubelle_tests/led/led.ino | 29 +++++++++++++++++++++++++++++ progArduino/poubelle_tests/led_test/led_test.ino | 15 +++++++++++++++ progArduino/poubelle_tests/pirSensor_test/pirSensor_test.ino | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ progArduino/poubelle_tests/pirSensor_test_best/detecteurmouv/detecteurmouv.ino | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ progArduino/poubelle_tests/pirSensor_test_best/pirSensor_test_best.ino | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ progArduino/poubelle_tests/test1/test1.ino | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ progArduino/poubelle_tests/test2/test2.ino | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ progArduino/principal/principal.ino | 304 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 11 files changed, 880 insertions(+), 0 deletions(-) create mode 100644 progArduino/controle_led/controle_led.ino create mode 100644 progArduino/detectionmouv/detectionmouv.ino create mode 100644 progArduino/poubelle_tests/arduinocapteurmouv.fzz create mode 100644 progArduino/poubelle_tests/led/led.ino create mode 100644 progArduino/poubelle_tests/led_test/led_test.ino create mode 100644 progArduino/poubelle_tests/pirSensor_test/pirSensor_test.ino create mode 100644 progArduino/poubelle_tests/pirSensor_test_best/detecteurmouv/detecteurmouv.ino create mode 100644 progArduino/poubelle_tests/pirSensor_test_best/pirSensor_test_best.ino create mode 100644 progArduino/poubelle_tests/test1/test1.ino create mode 100644 progArduino/poubelle_tests/test2/test2.ino create mode 100644 progArduino/principal/principal.ino diff --git a/progArduino/controle_led/controle_led.ino b/progArduino/controle_led/controle_led.ino new file mode 100644 index 0000000..b599f8e --- /dev/null +++ b/progArduino/controle_led/controle_led.ino @@ -0,0 +1,71 @@ +// Initialisation néopixel led rgb + +#include + +# define PININ 12 +# define PINOUT 8 + + +Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PININ, NEO_RGB + NEO_KHZ800); + +//Initialisation photorésistance + +#define CAPTEUR A0 + +// #define LED 4 + +int luminosite = 0; +int seuil = 100; + + +void setup() { + + //pour les rgb + strip.begin(); + strip.show(); // Initialize all pixels to 'off' + + //Initialisation de la liaison série + Serial.begin(9600); + + //Led en sortie + pinMode(PININ, OUTPUT); + +} + + +void loop() { + + //On récupère la valeur du seuil + luminosite = analogRead(CAPTEUR); + //Monitoring + Serial.print("Luminosite = "); + Serial.print(luminosite); + + //On récupère la valeur du seuil + //seuil = analogRead(SEUIL); + //Monitoring + Serial.print(" / Seuil = "); + Serial.print(seuil); + + //Allumage de la led si la luminosité est inférieur au seuil + if(luminosite < seuil) { + //digitalWrite(PININ, HIGH); + strip.setPixelColor(0,0, 0,255); + strip.show(); + //Monitoring + Serial.println(" / LED ON"); + + //Dans le cas contraire, on l'éteint + } else { + digitalWrite(PININ, LOW); + strip.setPixelColor(0,0, 0,255); + strip.show(); + Serial.println(" / LED OFF"); + } + + //Petite pause + delay(20); +} + +//strip.setBrightness(64); PERMET DE REGLER LA LUMINOSITE + diff --git a/progArduino/detectionmouv/detectionmouv.ino b/progArduino/detectionmouv/detectionmouv.ino new file mode 100644 index 0000000..33c4a0c --- /dev/null +++ b/progArduino/detectionmouv/detectionmouv.ino @@ -0,0 +1,98 @@ +///////////////////////////// +//VARS + +//the time we give the sensor to calibrate (10-60 secs according to the datasheet) +int calibrationTime = 30; + +//the time when the sensor outputs a low impulse +long unsigned int lowIn; + +//the amount of milliseconds the sensor has to be low +//before we assume all motion has stopped +long unsigned int pause = 5000; + +boolean lockLow = true; +boolean takeLowTime; + +int pirPin = 3; //the digital pin connected to the PIR sensor's output +int ledPin = 13; + +//var meaning the parent receives a message +int MESSAGE=0; + +////////////////////////////// +//most of the time the arduino needs 2or3 sec to detect there is no more movement right away. +///////////////////////////// +//SETUP +void setup(){ + Serial.begin(9600); + pinMode(pirPin, INPUT); + pinMode(ledPin, OUTPUT); + digitalWrite(pirPin, LOW); + + //give the sensor some time to calibrate + Serial.print("calibrating sensor "); + for(int i = 0; i < calibrationTime; i++){ + Serial.print("."); + delay(1000); + } + Serial.println(" done"); + Serial.println("SENSOR ACTIVE"); + delay(50); + } + +//////////////////////////// +//LOOP +void loop(){ + int i=0; + while(i<=5) + { + //MOVEMENT DETECTION + if(digitalRead(pirPin) == HIGH){ + digitalWrite(ledPin, HIGH); //the led visualizes the sensors output pin state + if(lockLow){ + //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"); + delay(50); + } + takeLowTime = true; + } + //DETECTION'S END + if(digitalRead(pirPin) == LOW){ + digitalWrite(ledPin, LOW); //the led visualizes the sensors output pin state + + if(takeLowTime){ + lowIn = millis(); //save the time of the transition from high to LOW + takeLowTime = false; //make sure this is only done at the start of a LOW phase + } + //if the sensor is low for more than the given pause, + //we assume that no more motion is going to happen + if(!lockLow && millis() - lowIn > pause){ + //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"); + i++; + //CHILD IS AWAKE + if(i==5 || ((millis() - pause)/1000)-(millis()/1000)> 10 ){ + Serial.println("Sommeil agite !!!"); + MESSAGE = 1; //servira pour la progra html (peut-être) + Serial.println(MESSAGE); + i=0; + } + delay(50); + } + } + + } + + } + + + diff --git a/progArduino/poubelle_tests/arduinocapteurmouv.fzz b/progArduino/poubelle_tests/arduinocapteurmouv.fzz new file mode 100644 index 0000000..acbd4d2 Binary files /dev/null and b/progArduino/poubelle_tests/arduinocapteurmouv.fzz differ diff --git a/progArduino/poubelle_tests/led/led.ino b/progArduino/poubelle_tests/led/led.ino new file mode 100644 index 0000000..1fc7c59 --- /dev/null +++ b/progArduino/poubelle_tests/led/led.ino @@ -0,0 +1,29 @@ +#include + +# define PININ 12 +# define PINOUT 8 + +// Parameter 1 = number of pixels in strip +// Parameter 2 = pin number (most are valid) +// Parameter 3 = pixel type flags, add together as needed: +// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) +// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) +// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) +// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) +Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PININ, NEO_RGB + NEO_KHZ800); + +void setup() { + strip.begin(); + strip.show(); // Initialize all pixels to 'off' +} + +void loop() { +//strip.setPixelColor(n, red, green, blue); +//pas de version RGBW !! + strip.setPixelColor(0,0, 0,255); + strip.show(); +} + +///EN PLUS SI NECESSAIRE +//You can also convert separate red, green and blue values into a single 32-bit type for later use: +// uint32_t magenta = strip.Color(255, 0, 255); diff --git a/progArduino/poubelle_tests/led_test/led_test.ino b/progArduino/poubelle_tests/led_test/led_test.ino new file mode 100644 index 0000000..1c08c4e --- /dev/null +++ b/progArduino/poubelle_tests/led_test/led_test.ino @@ -0,0 +1,15 @@ +int L1=2; + +void setup() //fonction d'initialisation de la carte +{ +//contenu de l'initialisation +pinMode(L1, OUTPUT); //L1 est une broche de sortie +} +void loop() //fonction principale, elle se répète (s’exécute) à l'infini +{ +//contenu du programme +digitalWrite(L1, HIGH); //allumer L1 +delay(1000); // attendre 1 seconde +digitalWrite(L1, LOW); // Eteindre L1 +delay(2000); // attendre 2 seconde +} diff --git a/progArduino/poubelle_tests/pirSensor_test/pirSensor_test.ino b/progArduino/poubelle_tests/pirSensor_test/pirSensor_test.ino new file mode 100644 index 0000000..f52c1b2 --- /dev/null +++ b/progArduino/poubelle_tests/pirSensor_test/pirSensor_test.ino @@ -0,0 +1,78 @@ +///////////////////////////// +//VARS +//the time we give the sensor to calibrate (10-60 secs according to the datasheet) +int calibrationTime = 30; + +//the time when the sensor outputs a low impulse +long unsigned int lowIn; + +//the amount of milliseconds the sensor has to be low +//before we assume all motion has stopped +long unsigned int pause = 5000; + +boolean lockLow = true; +boolean takeLowTime; + +int pirPin = 3; //the digital pin connected to the PIR sensor's output +int ledPin = 13; + + +///////////////////////////// +//SETUP +void setup(){ + Serial.begin(9600); + pinMode(pirPin, INPUT); + pinMode(ledPin, OUTPUT); + digitalWrite(pirPin, LOW); + + //give the sensor some time to calibrate + Serial.print("calibrating sensor "); + for(int i = 0; i < calibrationTime; i++){ + Serial.print("."); + delay(1000); + } + Serial.println(" done"); + Serial.println("SENSOR ACTIVE"); + delay(50); + } + +//////////////////////////// +//LOOP +void loop(){ + + if(digitalRead(pirPin) == HIGH){ + digitalWrite(ledPin, HIGH); //the led visualizes the sensors output pin state + if(lockLow){ + //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"); + delay(50); + } + takeLowTime = true; + } + + if(digitalRead(pirPin) == LOW){ + digitalWrite(ledPin, LOW); //the led visualizes the sensors output pin state + + if(takeLowTime){ + lowIn = millis(); //save the time of the transition from high to LOW + takeLowTime = false; //make sure this is only done at the start of a LOW phase + } + //if the sensor is low for more than the given pause, + //we assume that no more motion is going to happen + if(!lockLow && millis() - lowIn > pause){ + //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"); + delay(50); + } + } + } + + diff --git a/progArduino/poubelle_tests/pirSensor_test_best/detecteurmouv/detecteurmouv.ino b/progArduino/poubelle_tests/pirSensor_test_best/detecteurmouv/detecteurmouv.ino new file mode 100644 index 0000000..f8c038e --- /dev/null +++ b/progArduino/poubelle_tests/pirSensor_test_best/detecteurmouv/detecteurmouv.ino @@ -0,0 +1,77 @@ +///////// DETECTEUR DE MOUVEMENT SIGNAL //////////////////// + +//INITIALISATION POUR LE CALIBRAGE + +// calibrage du capteur (10-60 secs according to the datasheet) +int calibrationTime = 20; + +// le temps quand le capteur envoie un signal faible en entrée +long unsigned int timelowIn; + +//temps (millisecondes) durant lequel le signal est faible, soit avant qu'on suppose que tout mouvement s'est arrêté. +//on considère cela comme une pause d'insécurité sur la question: mouvement présent oui ou non? +long unsigned int pause = 5000; + +boolean lockLow = true; +boolean takeLowTime; + +int pirPin = 3; //la PIN du capteur de mouvement en 3 +int ledPin = 13; //Une led modélise le signal "trop de mouv" dans un premier temps + + +//SETUP/INITIALISATION + +void setup(){ + Serial.begin(9600); + pinMode(pirPin, INPUT); + pinMode(ledPin, OUTPUT); + digitalWrite(pirPin, LOW); + + //MOMENT POUR LE CALIBRAGE + Serial.print("calibrating sensor "); + for(int i = 0; i < calibrationTime; i++){ + Serial.print("."); + delay(1000); + } + Serial.println(" done"); + Serial.println("SENSOR ACTIVE"); + delay(50); + } + +//////////////////////////// +//LOOP +void loop(){ + int i=0; + if(digitalRead(pirPin) == HIGH){i++;} //On pose comme condition que si il y a 5 fois du mouvement + if (i>5){ + Serial.println ("Sommeil agité !!!"); + i=0; + if(lockLow){ + //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"); + delay(50); + } + } + if(digitalRead(pirPin) == LOW){ + digitalWrite(ledPin, LOW); //the led visualizes the sensors output pin state + if(takeLowTime){ + timelowIn = millis(); //save the time of the transition from high to LOW + takeLowTime = false; //make sure this is only done at the start of a LOW phase + } + //if the sensor is low for more than the given pause, + //we assume that no more motion is going to happen + if(!lockLow && millis() - timelowIn > pause){ + //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"); + delay(50); + } + } + } diff --git a/progArduino/poubelle_tests/pirSensor_test_best/pirSensor_test_best.ino b/progArduino/poubelle_tests/pirSensor_test_best/pirSensor_test_best.ino new file mode 100644 index 0000000..f52c1b2 --- /dev/null +++ b/progArduino/poubelle_tests/pirSensor_test_best/pirSensor_test_best.ino @@ -0,0 +1,78 @@ +///////////////////////////// +//VARS +//the time we give the sensor to calibrate (10-60 secs according to the datasheet) +int calibrationTime = 30; + +//the time when the sensor outputs a low impulse +long unsigned int lowIn; + +//the amount of milliseconds the sensor has to be low +//before we assume all motion has stopped +long unsigned int pause = 5000; + +boolean lockLow = true; +boolean takeLowTime; + +int pirPin = 3; //the digital pin connected to the PIR sensor's output +int ledPin = 13; + + +///////////////////////////// +//SETUP +void setup(){ + Serial.begin(9600); + pinMode(pirPin, INPUT); + pinMode(ledPin, OUTPUT); + digitalWrite(pirPin, LOW); + + //give the sensor some time to calibrate + Serial.print("calibrating sensor "); + for(int i = 0; i < calibrationTime; i++){ + Serial.print("."); + delay(1000); + } + Serial.println(" done"); + Serial.println("SENSOR ACTIVE"); + delay(50); + } + +//////////////////////////// +//LOOP +void loop(){ + + if(digitalRead(pirPin) == HIGH){ + digitalWrite(ledPin, HIGH); //the led visualizes the sensors output pin state + if(lockLow){ + //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"); + delay(50); + } + takeLowTime = true; + } + + if(digitalRead(pirPin) == LOW){ + digitalWrite(ledPin, LOW); //the led visualizes the sensors output pin state + + if(takeLowTime){ + lowIn = millis(); //save the time of the transition from high to LOW + takeLowTime = false; //make sure this is only done at the start of a LOW phase + } + //if the sensor is low for more than the given pause, + //we assume that no more motion is going to happen + if(!lockLow && millis() - lowIn > pause){ + //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"); + delay(50); + } + } + } + + diff --git a/progArduino/poubelle_tests/test1/test1.ino b/progArduino/poubelle_tests/test1/test1.ino new file mode 100644 index 0000000..41b650d --- /dev/null +++ b/progArduino/poubelle_tests/test1/test1.ino @@ -0,0 +1,81 @@ +///////// DETECTEUR DE MOUVEMENT SIGNAL //////////////////// + +//INITIALISATION POUR LE CALIBRAGE + +// calibrage du capteur (10-60 secs according to the datasheet) +int calibrationTime = 20; + +//the time when the sensor outputs a low impulse +long unsigned int lowIn; + +//temps (millisecondes) durant lequel le signal est faible, soit avant qu'on suppose que tout mouvement s'est arrêté. +//on considère cela comme une pause d'insécurité sur la question: mouvement présent oui ou non? +long unsigned int pause = 5000; + +boolean lockLow = true; +boolean takeLowTime; + +int pirPin = 3; //la PIN du capteur de mouvement en 3 + + +//SETUP/INITIALISATION + +void setup(){ + Serial.begin(9600); + pinMode(pirPin, INPUT); + //pinMode(ledPin, OUTPUT); + digitalWrite(pirPin, LOW); + + //MOMENT POUR LE CALIBRAGE + Serial.print("calibrating sensor "); + for(int i = 0; i < calibrationTime; i++){ + Serial.print("."); + delay(1000); + } + Serial.println(" done"); + Serial.println("SENSOR ACTIVE"); + delay(50); + } + +//////////////////////////// +//LOOP +void loop(){ + int i=0; + while (i<5){ + + //Part 1 for each detection + if(digitalRead(pirPin) == HIGH){ + //Serial.println("ok "); + i++; + //makes sure we wait for a transition to LOW before any further output is made : + if (lockLow){ + lockLow=false; + Serial.println("---"); + Serial.print("motion detected at "); + Serial.print(millis()/1000); + delay(1000); + } + takeLowTime=true; + } + + //Part 2 when there is no detection + if(digitalRead(pirPin)==LOW){ + if (takeLowTime){ + lowIn=millis(); + takeLowTime=false; + } + if(!lockLow && millis()-lowIn > pause){ + lockLow=true; + Serial.print("motion ended at "); + Serial.print((millis()-pause)/1000); + Serial.println(" sec"); + delay(1000); + } + } + } + if(i==5){ + Serial.println("Sommeil agité !!!"); + delay(1000); + i=0; + } +} diff --git a/progArduino/poubelle_tests/test2/test2.ino b/progArduino/poubelle_tests/test2/test2.ino new file mode 100644 index 0000000..e8fd4ec --- /dev/null +++ b/progArduino/poubelle_tests/test2/test2.ino @@ -0,0 +1,49 @@ + +#define CAPTEUR A0 +//#define SEUIL A1 + +#define LED 4 + +//Valeurs par défaut +int luminosite = 0; +int seuil = 100; + +void setup() { + //Initialisation de la liaison série + Serial.begin(9600); + + //Led en sortie + pinMode(LED, OUTPUT); + +} + +void loop() { + + //On récupère la valeur du seuil + luminosite = analogRead(CAPTEUR); + //Monitoring + Serial.print("Luminosite = "); + Serial.print(luminosite); + + //On récupère la valeur du seuil + //seuil = analogRead(SEUIL); + //Monitoring + Serial.print(" / Seuil = "); + Serial.print(seuil); + + //Allumage de la led si la luminosité est inférieur au seuil + if(luminosite < seuil) { + digitalWrite(LED, HIGH); + //Monitoring + Serial.println(" / LED ON"); + + //Dans le cas contraire, on l'éteint + } else { + digitalWrite(LED, LOW); + //Monitoring + Serial.println(" / LED OFF"); + } + + //Petite pause + delay(20); +} diff --git a/progArduino/principal/principal.ino b/progArduino/principal/principal.ino new file mode 100644 index 0000000..ad5bf9e --- /dev/null +++ b/progArduino/principal/principal.ino @@ -0,0 +1,304 @@ +//////////////////////////////////////// PROJET SC: VEILLEUSE CONNECTEE (IMA3) +//Claire Vandamme +//Justine Senellart +//Camille Saâd + + + +//--------------------------------------------------------------------------------------------------------------- INITIALISATION CONSTANTES et paramètres + + +//INIT CAPTEUR PRESENCE + +//temps donné pour calibrer le capteur de présence.(10-60 secs according to the datasheet) +int calibrationTime = 20; +//the time when the sensor outputs a low impulse +long unsigned int lowIn; +//the amount of milliseconds the sensor has to be low +//before we assume all motion has stopped +long unsigned int pause = 500; + +boolean lockLow = true; +boolean takeLowTime; +int pirPin = 3; //the digital pin connected to the PIR sensor's output +int ledPin = 13; +//var meaning the parent receives a message +int MESSAGE=0; + + +//INIT NEOPIXEL LED RGB + +//add the library +#include +//control pin +# define PININ 12 +# define PINOUT 8 + +// Parameter 1 = number of pixels in strip +// Parameter 2 = pin number (most are valid) +// Parameter 3 = pixel type flags, add together as needed: +// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) +// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) +// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) +// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) +Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PININ, NEO_RGB + NEO_KHZ800); + + +//INIT PHOTRESISTANCE (LUMINOSITE AMBIANTE) +#define CAPTEUR A0 +int luminosite = 0; +int seuil = 200; + +//INIT interrupteur +const int pinInter = 9 ; +int etatBouton; + + +//--------------------------------------------------------------------------------------------------------------------------------------SETUP () + + +void setup() { + //SETUP LIAISON SERIE + Serial.begin(9600); + + //SETUP INTER + pinMode(pinInter, INPUT_PULLUP); //le bouton est une entrée + etatBouton = HIGH; //on initialise l'état du bouton comme "relaché" + + //SETUP LEDS + //pour les RGB + strip.begin(); + strip.show(); // Initialize all pixels to 'off' + + //Led en sortie + pinMode(PININ, OUTPUT); + + + //SETUP CAPTEUR PRESENCE ET LED ROUGE + pinMode(pirPin, INPUT); + pinMode(ledPin, OUTPUT); + digitalWrite(pirPin, LOW); + //give the sensor some time to calibrate + Serial.print("calibrating sensor "); + for(int i = 0; i < calibrationTime; i++){ + Serial.print("."); + delay(1000); + } + Serial.println(" done"); + Serial.println("SENSOR ACTIVE"); + + + delay(50); +} + + +//------------------------------------------------------------------------------------------------------------------------FONCTIONS SECONDAIRES + +void couleur(int R, int G, int B) +{ + strip.setPixelColor(0,R,G,B); + strip.show(); +} + +/* +void choix_couleur() +{ + int R,G,B; + + Serial.println(" Rouge ="); + while (Serial.available()<0){ delay(10);} + R=Serial.read(); + Serial.print(R); + Serial.print(" Vert ="); + while (Serial.available()<0){ delay(10);} + G=Serial.read(); + Serial.print(G); + Serial.print(" Bleu ="); + while (Serial.available()<0){ delay(10);} + B=Serial.read(); + Serial.print(B); + + delay(3000); + couleur(R,G,B); +} +*/ + +void eteindre() +{ + strip.setPixelColor(0,0,0,0); + strip.show(); + digitalWrite(pirPin, LOW); + digitalWrite(ledPin, LOW); + digitalWrite(PININ, LOW); +} + +void choix_intensite() +{ + int k; + k=Serial.read(); + strip.setBrightness(k); //permet de régler la luminosité +} + +//fonction qui allume les led de manière automatique selon la luminosité ambiante +void lumiere_auto() +{ + //On récupère la valeur du seuil + luminosite = analogRead(CAPTEUR); + + //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); + eteindre(); + Serial.println(" / LED OFF"); + } + delay(50); +} + +/* +void choix_type_allumage() +{ + int choix; + Serial.println("Vous pouvez choisir entre l'allumage automatique (choix=1) de la veilleuse et l'allumage manuel (choix=2)."); + choix= Serial.read(); + if(choix==1) + { + lumiere_auto(); + } + else if (choix==2) + { + int on_off; + Serial.println("Voulez vous allumer la veilleuse? (non = 0; oui =1)"); + on_off=Serial.read(); + //permet d'utiliser un allumage application. + } + else + { + Serial.println("ERROR CHOIX ALLUMAGE."); + } +} +*/ + +void mouvement() +{ + int i=0; + while(i<5) + { + + //MOVEMENT DETECTION + if(digitalRead(pirPin) == HIGH) + { + digitalWrite(ledPin, HIGH); //the led visualizes the sensors output pin state + if(lockLow) + { + //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"); + delay(50); + } + takeLowTime = true; + } + + //DETECTION'S END + if(digitalRead(pirPin) == LOW) + { + digitalWrite(ledPin, LOW); //the led visualizes the sensors output pin state + + if(takeLowTime) + { + lowIn = millis(); //save the time of the transition from high to LOW + takeLowTime = false; //make sure this is only done at the start of a LOW phase + } + //if the sensor is low for more than the given pause, + //we assume that no more motion is going to happen + if(!lockLow && millis() - lowIn > pause){ + //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"); + i++; + //CHILD IS AWAKE + if(i==5 || ((millis() - pause)/1000)-(millis()/1000)> 10 ){ + Serial.println("Sommeil agite !!!"); + MESSAGE = 1; //servira pour la progra html (peut-être) + Serial.println(MESSAGE); + i=0; + } + delay(50); + } + } + } +} + +//---------------------------------------------------------------------------------------------------------------------------FONCTIONS PRINCIPALES + + +//fonction du programme principal (à copier plus tard dans la LOOP() +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(); + + 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"); + + +} + + + +//fonction permettant de faire les tests des foncions secondaires +void tests() +{ + //couleur(0,255,0); + //choix_couleur(); + //eteindre(); + //choix_intensite(); + //choix_type_allumage(); + mouvement(); + //lumiere_auto(); + delay(200); +} + + + + +//----------------------------------------------------------------------------------------------------------------------------LOOP == MAIN PROG +void loop() + +{ + tests(); + + //mainVeilleuse(); + delay(200); +} -- libgit2 0.21.2