diff --git a/progArduino/controle_led/controle_led.ino b/progArduino/controle_led/controle_led.ino deleted file mode 100644 index b599f8e..0000000 --- a/progArduino/controle_led/controle_led.ino +++ /dev/null @@ -1,71 +0,0 @@ -// 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 deleted file mode 100644 index 33c4a0c..0000000 --- a/progArduino/detectionmouv/detectionmouv.ino +++ /dev/null @@ -1,98 +0,0 @@ -///////////////////////////// -//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 deleted file mode 100644 index acbd4d2..0000000 Binary files a/progArduino/poubelle_tests/arduinocapteurmouv.fzz and /dev/null differ diff --git a/progArduino/poubelle_tests/led/led.ino b/progArduino/poubelle_tests/led/led.ino deleted file mode 100644 index 1fc7c59..0000000 --- a/progArduino/poubelle_tests/led/led.ino +++ /dev/null @@ -1,29 +0,0 @@ -#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 deleted file mode 100644 index 1c08c4e..0000000 --- a/progArduino/poubelle_tests/led_test/led_test.ino +++ /dev/null @@ -1,15 +0,0 @@ -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 deleted file mode 100644 index f52c1b2..0000000 --- a/progArduino/poubelle_tests/pirSensor_test/pirSensor_test.ino +++ /dev/null @@ -1,78 +0,0 @@ -///////////////////////////// -//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 deleted file mode 100644 index f8c038e..0000000 --- a/progArduino/poubelle_tests/pirSensor_test_best/detecteurmouv/detecteurmouv.ino +++ /dev/null @@ -1,77 +0,0 @@ -///////// 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 deleted file mode 100644 index f52c1b2..0000000 --- a/progArduino/poubelle_tests/pirSensor_test_best/pirSensor_test_best.ino +++ /dev/null @@ -1,78 +0,0 @@ -///////////////////////////// -//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 deleted file mode 100644 index 41b650d..0000000 --- a/progArduino/poubelle_tests/test1/test1.ino +++ /dev/null @@ -1,81 +0,0 @@ -///////// 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 deleted file mode 100644 index e8fd4ec..0000000 --- a/progArduino/poubelle_tests/test2/test2.ino +++ /dev/null @@ -1,49 +0,0 @@ - -#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 deleted file mode 100644 index 31626db..0000000 --- a/progArduino/principal/principal.ino +++ /dev/null @@ -1,512 +0,0 @@ -//////////////////////////////////////// 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 = 10; -//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 = 2 ; -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(); -} - - -/* -// fait avec application -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"); - Serial.println(i); - i++; - - //CHILD IS AWAKE - // 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"); - i=0; - } - delay(20); - } - } - } -} - - - -//fonction regroupant l'utilisation de la led de manière automatique et du capteur de mouvement. -//on veut l'utilisation du capteur (soit réalisation de mouvement) uniquement quand la led est allumée - -//--------------------------------------------------------------------------------------------------------------------automatique() -void automatique() -{ - //On récupère la valeur du seuil - luminosite = analogRead(CAPTEUR); - int i=0; - - //Monitoring - Serial.print("Luminosite = "); - Serial.print(luminosite); - Serial.print(" / Seuil = "); - Serial.print(seuil); - - // on l'éteint - if (luminosite > seuil) - { - eteindre(); - Serial.println(" / LED OFF"); - } - - //Allumage de la led si la luminosité est inférieur au seuil (on l'allume dans la couleur blanche la base) - //enfant couché il doit dormir - else - { - //Monitoring - couleur(255,255,255); - - - while(i<=5) - { - luminosite = analogRead(CAPTEUR); - - if(luminosite < seuil) - { - couleur(255,255,255); - - - //DETECTION D'UN MOUVEMENT - if(digitalRead(pirPin)==HIGH) - { - digitalWrite(ledPin,HIGH); // la led modélise la déection d'un mouvement selon l'etat du capteur - if (lockLow) - { - //être sûr d'attendre la transistion à l'état LOW du capteur pour continuer : - lockLow= false; - delay(50); - } - takeLowTime = true; - } - - //FIN DE LA DETECTION - if(digitalRead(pirPin)==LOW) - { - digitalWrite(ledPin, LOW); - if(takeLowTime) - { - lowIn= millis(); // enregistrement du temps qu'il faut pour passer de HIGH à LOW pour le capteur - takeLowTime = false; // être sûr que cela se fait uniquement au debut du passage à LOW - } - // Ainsi si le capteur est LOW plus longtemps que la pause, on suppose qu'il n'y plus de mouvement - // if > être sûr que la suite s'execute seulement après un nouveau mouvement, donc nouvelle séquence de led allumée - if(!lockLow && millis()-lowIn > pause) - { - lockLow = true; - i++; - Serial.println(i); - - //CHILD AWAKE - if(i==5) - { - Serial.println("Sommeil agite !!!"); - MESSAGE = 1; - i=0; - } - delay(20); - } - } - - delay(500); - } - else - { - eteindre(); - i=0; - } - - - } - delay(50); - } - -} - - - - -//-------------------------------------------------------------------------------------------------------------------------------------------FONCTIONS PRINCIPALES - - - - -//---------------------------------------------------------------------------------------------------------------------------------mainveilleuse() - -//fonction du programme principal (à copier plus tard dans la LOOP() -//elle permet l'utilisation de la veilleuse de manière automatique selon la position de l'interrupteur, sinon c'est l'application qui gere le contrôle -//Elle est constituée de la fusion des fonctions secondaires: lumiere_auto(), mouvement() et automatique() -void mainVeilleuse_auto() -{ - etatBouton = digitalRead(pinInter); //Rappel :pinInter = 9 - - //MODE AUTOMATIQUE - //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 - { - delay(1000); - - etatBouton = digitalRead(pinInter); - - if(etatBouton==LOW) - { - //On récupère la valeur du seuil - luminosite = analogRead(CAPTEUR); - int i=0; - - //Monitoring - Serial.print("Luminosite = "); - Serial.print(luminosite); - Serial.print(" / Seuil = "); - Serial.print(seuil); - - // on l'éteint - if (luminosite > seuil) - { - eteindre(); - Serial.println(" / LED OFF"); - } - - //Allumage de la led si la luminosité est inférieur au seuil (on l'allume dans la couleur blanche la base) - //enfant couché il doit dormir - else - { - //Monitoring - couleur(255,255,255); - - - while(i<=5 && etatBouton==LOW) - { - luminosite = analogRead(CAPTEUR); - - if(luminosite < seuil) - { - couleur(255,255,255); - - //DETECTION D'UN MOUVEMENT - if(digitalRead(pirPin)==HIGH) - { - digitalWrite(ledPin,HIGH); // la led modélise la déection d'un mouvement selon l'etat du capteur - if (lockLow) - { - //être sûr d'attendre la transistion à l'état LOW du capteur pour continuer : - lockLow= false; - delay(50); - } - takeLowTime = true; - } - - //FIN DE LA DETECTION - if(digitalRead(pirPin)==LOW) - { - digitalWrite(ledPin, LOW); - if(takeLowTime) - { - lowIn= millis(); // enregistrement du temps qu'il faut pour passer de HIGH à LOW pour le capteur - takeLowTime = false; // être sûr que cela se fait uniquement au debut du passage à LOW - } - // Ainsi si le capteur est LOW plus longtemps que la pause, on suppose qu'il n'y plus de mouvement - // if > être sûr que la suite s'execute seulement après un nouveau mouvement, donc nouvelle séquence de led allumée - if(!lockLow && millis()-lowIn > pause) - { - lockLow = true; - i++; - Serial.println(i); - - //CHILD AWAKE - if(i==5) - { - Serial.println("Sommeil agite !!!"); - MESSAGE = 1; - i=0; - } - delay(20); - } - } - - delay(500); - } - - else - { - eteindre(); - i=0; - } - - etatBouton = digitalRead(pinInter); //Rappel :pinInter = 9 - - } - delay(50); - } - } - else - { - eteindre(); - Serial.println("UTILISATION APPLICATION"); - } - - etatBouton = digitalRead(pinInter); //Rappel :pinInter = 9 - } - - //MODE MANUEL (APPLICATION) - //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"); - - delay(1000); - - -} - -//-------------------------------------------------------------------------------------------------------------------------------------------TESTS & LOOP == MAIN PROG - -//fonction permettant de faire les tests des foncions secondaires -void tests() -{ - //couleur(255,0,0); - //choix_couleur(); - //eteindre(); - //choix_intensite(); - //choix_type_allumage(); - //mouvement(); - lumiere_auto(); - //automatique(); - delay(200); -} - - -void loop() - -{ - tests(); - - //mainVeilleuse_auto(); - delay(200); -} diff --git a/progArduino/tests/controle_led/controle_led.ino b/progArduino/tests/controle_led/controle_led.ino new file mode 100644 index 0000000..b599f8e --- /dev/null +++ b/progArduino/tests/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/tests/detectionmouv/detectionmouv.ino b/progArduino/tests/detectionmouv/detectionmouv.ino new file mode 100644 index 0000000..33c4a0c --- /dev/null +++ b/progArduino/tests/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/tests/poubelle_tests/arduinocapteurmouv.fzz b/progArduino/tests/poubelle_tests/arduinocapteurmouv.fzz new file mode 100644 index 0000000..acbd4d2 Binary files /dev/null and b/progArduino/tests/poubelle_tests/arduinocapteurmouv.fzz differ diff --git a/progArduino/tests/poubelle_tests/led/led.ino b/progArduino/tests/poubelle_tests/led/led.ino new file mode 100644 index 0000000..1fc7c59 --- /dev/null +++ b/progArduino/tests/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/tests/poubelle_tests/led_test/led_test.ino b/progArduino/tests/poubelle_tests/led_test/led_test.ino new file mode 100644 index 0000000..1c08c4e --- /dev/null +++ b/progArduino/tests/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/tests/poubelle_tests/pirSensor_test/pirSensor_test.ino b/progArduino/tests/poubelle_tests/pirSensor_test/pirSensor_test.ino new file mode 100644 index 0000000..f52c1b2 --- /dev/null +++ b/progArduino/tests/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/tests/poubelle_tests/pirSensor_test_best/detecteurmouv/detecteurmouv.ino b/progArduino/tests/poubelle_tests/pirSensor_test_best/detecteurmouv/detecteurmouv.ino new file mode 100644 index 0000000..f8c038e --- /dev/null +++ b/progArduino/tests/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/tests/poubelle_tests/pirSensor_test_best/pirSensor_test_best.ino b/progArduino/tests/poubelle_tests/pirSensor_test_best/pirSensor_test_best.ino new file mode 100644 index 0000000..f52c1b2 --- /dev/null +++ b/progArduino/tests/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/tests/poubelle_tests/test1/test1.ino b/progArduino/tests/poubelle_tests/test1/test1.ino new file mode 100644 index 0000000..41b650d --- /dev/null +++ b/progArduino/tests/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/tests/poubelle_tests/test2/test2.ino b/progArduino/tests/poubelle_tests/test2/test2.ino new file mode 100644 index 0000000..e8fd4ec --- /dev/null +++ b/progArduino/tests/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/tests/principal/principal.ino b/progArduino/tests/principal/principal.ino new file mode 100644 index 0000000..31626db --- /dev/null +++ b/progArduino/tests/principal/principal.ino @@ -0,0 +1,512 @@ +//////////////////////////////////////// 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 = 10; +//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 = 2 ; +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(); +} + + +/* +// fait avec application +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"); + Serial.println(i); + i++; + + //CHILD IS AWAKE + // 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"); + i=0; + } + delay(20); + } + } + } +} + + + +//fonction regroupant l'utilisation de la led de manière automatique et du capteur de mouvement. +//on veut l'utilisation du capteur (soit réalisation de mouvement) uniquement quand la led est allumée + +//--------------------------------------------------------------------------------------------------------------------automatique() +void automatique() +{ + //On récupère la valeur du seuil + luminosite = analogRead(CAPTEUR); + int i=0; + + //Monitoring + Serial.print("Luminosite = "); + Serial.print(luminosite); + Serial.print(" / Seuil = "); + Serial.print(seuil); + + // on l'éteint + if (luminosite > seuil) + { + eteindre(); + Serial.println(" / LED OFF"); + } + + //Allumage de la led si la luminosité est inférieur au seuil (on l'allume dans la couleur blanche la base) + //enfant couché il doit dormir + else + { + //Monitoring + couleur(255,255,255); + + + while(i<=5) + { + luminosite = analogRead(CAPTEUR); + + if(luminosite < seuil) + { + couleur(255,255,255); + + + //DETECTION D'UN MOUVEMENT + if(digitalRead(pirPin)==HIGH) + { + digitalWrite(ledPin,HIGH); // la led modélise la déection d'un mouvement selon l'etat du capteur + if (lockLow) + { + //être sûr d'attendre la transistion à l'état LOW du capteur pour continuer : + lockLow= false; + delay(50); + } + takeLowTime = true; + } + + //FIN DE LA DETECTION + if(digitalRead(pirPin)==LOW) + { + digitalWrite(ledPin, LOW); + if(takeLowTime) + { + lowIn= millis(); // enregistrement du temps qu'il faut pour passer de HIGH à LOW pour le capteur + takeLowTime = false; // être sûr que cela se fait uniquement au debut du passage à LOW + } + // Ainsi si le capteur est LOW plus longtemps que la pause, on suppose qu'il n'y plus de mouvement + // if > être sûr que la suite s'execute seulement après un nouveau mouvement, donc nouvelle séquence de led allumée + if(!lockLow && millis()-lowIn > pause) + { + lockLow = true; + i++; + Serial.println(i); + + //CHILD AWAKE + if(i==5) + { + Serial.println("Sommeil agite !!!"); + MESSAGE = 1; + i=0; + } + delay(20); + } + } + + delay(500); + } + else + { + eteindre(); + i=0; + } + + + } + delay(50); + } + +} + + + + +//-------------------------------------------------------------------------------------------------------------------------------------------FONCTIONS PRINCIPALES + + + + +//---------------------------------------------------------------------------------------------------------------------------------mainveilleuse() + +//fonction du programme principal (à copier plus tard dans la LOOP() +//elle permet l'utilisation de la veilleuse de manière automatique selon la position de l'interrupteur, sinon c'est l'application qui gere le contrôle +//Elle est constituée de la fusion des fonctions secondaires: lumiere_auto(), mouvement() et automatique() +void mainVeilleuse_auto() +{ + etatBouton = digitalRead(pinInter); //Rappel :pinInter = 9 + + //MODE AUTOMATIQUE + //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 + { + delay(1000); + + etatBouton = digitalRead(pinInter); + + if(etatBouton==LOW) + { + //On récupère la valeur du seuil + luminosite = analogRead(CAPTEUR); + int i=0; + + //Monitoring + Serial.print("Luminosite = "); + Serial.print(luminosite); + Serial.print(" / Seuil = "); + Serial.print(seuil); + + // on l'éteint + if (luminosite > seuil) + { + eteindre(); + Serial.println(" / LED OFF"); + } + + //Allumage de la led si la luminosité est inférieur au seuil (on l'allume dans la couleur blanche la base) + //enfant couché il doit dormir + else + { + //Monitoring + couleur(255,255,255); + + + while(i<=5 && etatBouton==LOW) + { + luminosite = analogRead(CAPTEUR); + + if(luminosite < seuil) + { + couleur(255,255,255); + + //DETECTION D'UN MOUVEMENT + if(digitalRead(pirPin)==HIGH) + { + digitalWrite(ledPin,HIGH); // la led modélise la déection d'un mouvement selon l'etat du capteur + if (lockLow) + { + //être sûr d'attendre la transistion à l'état LOW du capteur pour continuer : + lockLow= false; + delay(50); + } + takeLowTime = true; + } + + //FIN DE LA DETECTION + if(digitalRead(pirPin)==LOW) + { + digitalWrite(ledPin, LOW); + if(takeLowTime) + { + lowIn= millis(); // enregistrement du temps qu'il faut pour passer de HIGH à LOW pour le capteur + takeLowTime = false; // être sûr que cela se fait uniquement au debut du passage à LOW + } + // Ainsi si le capteur est LOW plus longtemps que la pause, on suppose qu'il n'y plus de mouvement + // if > être sûr que la suite s'execute seulement après un nouveau mouvement, donc nouvelle séquence de led allumée + if(!lockLow && millis()-lowIn > pause) + { + lockLow = true; + i++; + Serial.println(i); + + //CHILD AWAKE + if(i==5) + { + Serial.println("Sommeil agite !!!"); + MESSAGE = 1; + i=0; + } + delay(20); + } + } + + delay(500); + } + + else + { + eteindre(); + i=0; + } + + etatBouton = digitalRead(pinInter); //Rappel :pinInter = 9 + + } + delay(50); + } + } + else + { + eteindre(); + Serial.println("UTILISATION APPLICATION"); + } + + etatBouton = digitalRead(pinInter); //Rappel :pinInter = 9 + } + + //MODE MANUEL (APPLICATION) + //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"); + + delay(1000); + + +} + +//-------------------------------------------------------------------------------------------------------------------------------------------TESTS & LOOP == MAIN PROG + +//fonction permettant de faire les tests des foncions secondaires +void tests() +{ + //couleur(255,0,0); + //choix_couleur(); + //eteindre(); + //choix_intensite(); + //choix_type_allumage(); + //mouvement(); + lumiere_auto(); + //automatique(); + delay(200); +} + + +void loop() + +{ + tests(); + + //mainVeilleuse_auto(); + delay(200); +} -- libgit2 0.21.2