Commit 38e849ce96e6c7ccbe22081abebc0475dcce776d

Authored by csaad
1 parent 0011d96b

ajout dossier programmes arduino

progArduino/controle_led/controle_led.ino 0 → 100644
... ... @@ -0,0 +1,71 @@
  1 +// Initialisation néopixel led rgb
  2 +
  3 +#include <Adafruit_NeoPixel.h>
  4 +
  5 +# define PININ 12
  6 +# define PINOUT 8
  7 +
  8 +
  9 +Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PININ, NEO_RGB + NEO_KHZ800);
  10 +
  11 +//Initialisation photorésistance
  12 +
  13 +#define CAPTEUR A0
  14 +
  15 +// #define LED 4
  16 +
  17 +int luminosite = 0;
  18 +int seuil = 100;
  19 +
  20 +
  21 +void setup() {
  22 +
  23 + //pour les rgb
  24 + strip.begin();
  25 + strip.show(); // Initialize all pixels to 'off'
  26 +
  27 + //Initialisation de la liaison série
  28 + Serial.begin(9600);
  29 +
  30 + //Led en sortie
  31 + pinMode(PININ, OUTPUT);
  32 +
  33 +}
  34 +
  35 +
  36 +void loop() {
  37 +
  38 + //On récupère la valeur du seuil
  39 + luminosite = analogRead(CAPTEUR);
  40 + //Monitoring
  41 + Serial.print("Luminosite = ");
  42 + Serial.print(luminosite);
  43 +
  44 + //On récupère la valeur du seuil
  45 + //seuil = analogRead(SEUIL);
  46 + //Monitoring
  47 + Serial.print(" / Seuil = ");
  48 + Serial.print(seuil);
  49 +
  50 + //Allumage de la led si la luminosité est inférieur au seuil
  51 + if(luminosite < seuil) {
  52 + //digitalWrite(PININ, HIGH);
  53 + strip.setPixelColor(0,0, 0,255);
  54 + strip.show();
  55 + //Monitoring
  56 + Serial.println(" / LED ON");
  57 +
  58 + //Dans le cas contraire, on l'éteint
  59 + } else {
  60 + digitalWrite(PININ, LOW);
  61 + strip.setPixelColor(0,0, 0,255);
  62 + strip.show();
  63 + Serial.println(" / LED OFF");
  64 + }
  65 +
  66 + //Petite pause
  67 + delay(20);
  68 +}
  69 +
  70 +//strip.setBrightness(64); PERMET DE REGLER LA LUMINOSITE
  71 +
... ...
progArduino/detectionmouv/detectionmouv.ino 0 → 100644
... ... @@ -0,0 +1,98 @@
  1 +/////////////////////////////
  2 +//VARS
  3 +
  4 +//the time we give the sensor to calibrate (10-60 secs according to the datasheet)
  5 +int calibrationTime = 30;
  6 +
  7 +//the time when the sensor outputs a low impulse
  8 +long unsigned int lowIn;
  9 +
  10 +//the amount of milliseconds the sensor has to be low
  11 +//before we assume all motion has stopped
  12 +long unsigned int pause = 5000;
  13 +
  14 +boolean lockLow = true;
  15 +boolean takeLowTime;
  16 +
  17 +int pirPin = 3; //the digital pin connected to the PIR sensor's output
  18 +int ledPin = 13;
  19 +
  20 +//var meaning the parent receives a message
  21 +int MESSAGE=0;
  22 +
  23 +//////////////////////////////
  24 +//most of the time the arduino needs 2or3 sec to detect there is no more movement right away.
  25 +/////////////////////////////
  26 +//SETUP
  27 +void setup(){
  28 + Serial.begin(9600);
  29 + pinMode(pirPin, INPUT);
  30 + pinMode(ledPin, OUTPUT);
  31 + digitalWrite(pirPin, LOW);
  32 +
  33 + //give the sensor some time to calibrate
  34 + Serial.print("calibrating sensor ");
  35 + for(int i = 0; i < calibrationTime; i++){
  36 + Serial.print(".");
  37 + delay(1000);
  38 + }
  39 + Serial.println(" done");
  40 + Serial.println("SENSOR ACTIVE");
  41 + delay(50);
  42 + }
  43 +
  44 +////////////////////////////
  45 +//LOOP
  46 +void loop(){
  47 + int i=0;
  48 + while(i<=5)
  49 + {
  50 + //MOVEMENT DETECTION
  51 + if(digitalRead(pirPin) == HIGH){
  52 + digitalWrite(ledPin, HIGH); //the led visualizes the sensors output pin state
  53 + if(lockLow){
  54 + //makes sure we wait for a transition to LOW before any further output is made:
  55 + lockLow = false;
  56 + Serial.println("---");
  57 + Serial.print("motion detected at ");
  58 + Serial.print(millis()/1000);
  59 + Serial.println(" sec");
  60 + delay(50);
  61 + }
  62 + takeLowTime = true;
  63 + }
  64 + //DETECTION'S END
  65 + if(digitalRead(pirPin) == LOW){
  66 + digitalWrite(ledPin, LOW); //the led visualizes the sensors output pin state
  67 +
  68 + if(takeLowTime){
  69 + lowIn = millis(); //save the time of the transition from high to LOW
  70 + takeLowTime = false; //make sure this is only done at the start of a LOW phase
  71 + }
  72 + //if the sensor is low for more than the given pause,
  73 + //we assume that no more motion is going to happen
  74 + if(!lockLow && millis() - lowIn > pause){
  75 + //makes sure this block of code is only executed again after
  76 + //a new motion sequence has been detected
  77 + lockLow = true;
  78 + Serial.print("motion ended at "); //output
  79 + Serial.print((millis() - pause)/1000);
  80 + Serial.println(" sec");
  81 + i++;
  82 + //CHILD IS AWAKE
  83 + if(i==5 || ((millis() - pause)/1000)-(millis()/1000)> 10 ){
  84 + Serial.println("Sommeil agite !!!");
  85 + MESSAGE = 1; //servira pour la progra html (peut-être)
  86 + Serial.println(MESSAGE);
  87 + i=0;
  88 + }
  89 + delay(50);
  90 + }
  91 + }
  92 +
  93 + }
  94 +
  95 + }
  96 +
  97 +
  98 +
... ...
progArduino/poubelle_tests/arduinocapteurmouv.fzz 0 → 100644
No preview for this file type
progArduino/poubelle_tests/led/led.ino 0 → 100644
... ... @@ -0,0 +1,29 @@
  1 +#include <Adafruit_NeoPixel.h>
  2 +
  3 +# define PININ 12
  4 +# define PINOUT 8
  5 +
  6 +// Parameter 1 = number of pixels in strip
  7 +// Parameter 2 = pin number (most are valid)
  8 +// Parameter 3 = pixel type flags, add together as needed:
  9 +// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
  10 +// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
  11 +// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
  12 +// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
  13 +Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PININ, NEO_RGB + NEO_KHZ800);
  14 +
  15 +void setup() {
  16 + strip.begin();
  17 + strip.show(); // Initialize all pixels to 'off'
  18 +}
  19 +
  20 +void loop() {
  21 +//strip.setPixelColor(n, red, green, blue);
  22 +//pas de version RGBW !!
  23 + strip.setPixelColor(0,0, 0,255);
  24 + strip.show();
  25 +}
  26 +
  27 +///EN PLUS SI NECESSAIRE
  28 +//You can also convert separate red, green and blue values into a single 32-bit type for later use:
  29 +// uint32_t magenta = strip.Color(255, 0, 255);
... ...
progArduino/poubelle_tests/led_test/led_test.ino 0 → 100644
... ... @@ -0,0 +1,15 @@
  1 +int L1=2;
  2 +
  3 +void setup() //fonction d'initialisation de la carte
  4 +{
  5 +//contenu de l'initialisation
  6 +pinMode(L1, OUTPUT); //L1 est une broche de sortie
  7 +}
  8 +void loop() //fonction principale, elle se répète (s’exécute) à l'infini
  9 +{
  10 +//contenu du programme
  11 +digitalWrite(L1, HIGH); //allumer L1
  12 +delay(1000); // attendre 1 seconde
  13 +digitalWrite(L1, LOW); // Eteindre L1
  14 +delay(2000); // attendre 2 seconde
  15 +}
... ...
progArduino/poubelle_tests/pirSensor_test/pirSensor_test.ino 0 → 100644
... ... @@ -0,0 +1,78 @@
  1 +/////////////////////////////
  2 +//VARS
  3 +//the time we give the sensor to calibrate (10-60 secs according to the datasheet)
  4 +int calibrationTime = 30;
  5 +
  6 +//the time when the sensor outputs a low impulse
  7 +long unsigned int lowIn;
  8 +
  9 +//the amount of milliseconds the sensor has to be low
  10 +//before we assume all motion has stopped
  11 +long unsigned int pause = 5000;
  12 +
  13 +boolean lockLow = true;
  14 +boolean takeLowTime;
  15 +
  16 +int pirPin = 3; //the digital pin connected to the PIR sensor's output
  17 +int ledPin = 13;
  18 +
  19 +
  20 +/////////////////////////////
  21 +//SETUP
  22 +void setup(){
  23 + Serial.begin(9600);
  24 + pinMode(pirPin, INPUT);
  25 + pinMode(ledPin, OUTPUT);
  26 + digitalWrite(pirPin, LOW);
  27 +
  28 + //give the sensor some time to calibrate
  29 + Serial.print("calibrating sensor ");
  30 + for(int i = 0; i < calibrationTime; i++){
  31 + Serial.print(".");
  32 + delay(1000);
  33 + }
  34 + Serial.println(" done");
  35 + Serial.println("SENSOR ACTIVE");
  36 + delay(50);
  37 + }
  38 +
  39 +////////////////////////////
  40 +//LOOP
  41 +void loop(){
  42 +
  43 + if(digitalRead(pirPin) == HIGH){
  44 + digitalWrite(ledPin, HIGH); //the led visualizes the sensors output pin state
  45 + if(lockLow){
  46 + //makes sure we wait for a transition to LOW before any further output is made:
  47 + lockLow = false;
  48 + Serial.println("---");
  49 + Serial.print("motion detected at ");
  50 + Serial.print(millis()/1000);
  51 + Serial.println(" sec");
  52 + delay(50);
  53 + }
  54 + takeLowTime = true;
  55 + }
  56 +
  57 + if(digitalRead(pirPin) == LOW){
  58 + digitalWrite(ledPin, LOW); //the led visualizes the sensors output pin state
  59 +
  60 + if(takeLowTime){
  61 + lowIn = millis(); //save the time of the transition from high to LOW
  62 + takeLowTime = false; //make sure this is only done at the start of a LOW phase
  63 + }
  64 + //if the sensor is low for more than the given pause,
  65 + //we assume that no more motion is going to happen
  66 + if(!lockLow && millis() - lowIn > pause){
  67 + //makes sure this block of code is only executed again after
  68 + //a new motion sequence has been detected
  69 + lockLow = true;
  70 + Serial.print("motion ended at "); //output
  71 + Serial.print((millis() - pause)/1000);
  72 + Serial.println(" sec");
  73 + delay(50);
  74 + }
  75 + }
  76 + }
  77 +
  78 +
... ...
progArduino/poubelle_tests/pirSensor_test_best/detecteurmouv/detecteurmouv.ino 0 → 100644
... ... @@ -0,0 +1,77 @@
  1 +///////// DETECTEUR DE MOUVEMENT SIGNAL ////////////////////
  2 +
  3 +//INITIALISATION POUR LE CALIBRAGE
  4 +
  5 +// calibrage du capteur (10-60 secs according to the datasheet)
  6 +int calibrationTime = 20;
  7 +
  8 +// le temps quand le capteur envoie un signal faible en entrée
  9 +long unsigned int timelowIn;
  10 +
  11 +//temps (millisecondes) durant lequel le signal est faible, soit avant qu'on suppose que tout mouvement s'est arrêté.
  12 +//on considère cela comme une pause d'insécurité sur la question: mouvement présent oui ou non?
  13 +long unsigned int pause = 5000;
  14 +
  15 +boolean lockLow = true;
  16 +boolean takeLowTime;
  17 +
  18 +int pirPin = 3; //la PIN du capteur de mouvement en 3
  19 +int ledPin = 13; //Une led modélise le signal "trop de mouv" dans un premier temps
  20 +
  21 +
  22 +//SETUP/INITIALISATION
  23 +
  24 +void setup(){
  25 + Serial.begin(9600);
  26 + pinMode(pirPin, INPUT);
  27 + pinMode(ledPin, OUTPUT);
  28 + digitalWrite(pirPin, LOW);
  29 +
  30 + //MOMENT POUR LE CALIBRAGE
  31 + Serial.print("calibrating sensor ");
  32 + for(int i = 0; i < calibrationTime; i++){
  33 + Serial.print(".");
  34 + delay(1000);
  35 + }
  36 + Serial.println(" done");
  37 + Serial.println("SENSOR ACTIVE");
  38 + delay(50);
  39 + }
  40 +
  41 +////////////////////////////
  42 +//LOOP
  43 +void loop(){
  44 + int i=0;
  45 + if(digitalRead(pirPin) == HIGH){i++;} //On pose comme condition que si il y a 5 fois du mouvement
  46 + if (i>5){
  47 + Serial.println ("Sommeil agité !!!");
  48 + i=0;
  49 + if(lockLow){
  50 + //makes sure we wait for a transition to LOW before any further output is made:
  51 + lockLow = false;
  52 + Serial.println("---");
  53 + Serial.print("motion detected at ");
  54 + Serial.print(millis()/1000);
  55 + Serial.println(" sec");
  56 + delay(50);
  57 + }
  58 + }
  59 + if(digitalRead(pirPin) == LOW){
  60 + digitalWrite(ledPin, LOW); //the led visualizes the sensors output pin state
  61 + if(takeLowTime){
  62 + timelowIn = millis(); //save the time of the transition from high to LOW
  63 + takeLowTime = false; //make sure this is only done at the start of a LOW phase
  64 + }
  65 + //if the sensor is low for more than the given pause,
  66 + //we assume that no more motion is going to happen
  67 + if(!lockLow && millis() - timelowIn > pause){
  68 + //makes sure this block of code is only executed again after
  69 + //a new motion sequence has been detected
  70 + lockLow = true;
  71 + Serial.print("motion ended at "); //output
  72 + Serial.print((millis() - pause)/1000);
  73 + Serial.println(" sec");
  74 + delay(50);
  75 + }
  76 + }
  77 + }
... ...
progArduino/poubelle_tests/pirSensor_test_best/pirSensor_test_best.ino 0 → 100644
... ... @@ -0,0 +1,78 @@
  1 +/////////////////////////////
  2 +//VARS
  3 +//the time we give the sensor to calibrate (10-60 secs according to the datasheet)
  4 +int calibrationTime = 30;
  5 +
  6 +//the time when the sensor outputs a low impulse
  7 +long unsigned int lowIn;
  8 +
  9 +//the amount of milliseconds the sensor has to be low
  10 +//before we assume all motion has stopped
  11 +long unsigned int pause = 5000;
  12 +
  13 +boolean lockLow = true;
  14 +boolean takeLowTime;
  15 +
  16 +int pirPin = 3; //the digital pin connected to the PIR sensor's output
  17 +int ledPin = 13;
  18 +
  19 +
  20 +/////////////////////////////
  21 +//SETUP
  22 +void setup(){
  23 + Serial.begin(9600);
  24 + pinMode(pirPin, INPUT);
  25 + pinMode(ledPin, OUTPUT);
  26 + digitalWrite(pirPin, LOW);
  27 +
  28 + //give the sensor some time to calibrate
  29 + Serial.print("calibrating sensor ");
  30 + for(int i = 0; i < calibrationTime; i++){
  31 + Serial.print(".");
  32 + delay(1000);
  33 + }
  34 + Serial.println(" done");
  35 + Serial.println("SENSOR ACTIVE");
  36 + delay(50);
  37 + }
  38 +
  39 +////////////////////////////
  40 +//LOOP
  41 +void loop(){
  42 +
  43 + if(digitalRead(pirPin) == HIGH){
  44 + digitalWrite(ledPin, HIGH); //the led visualizes the sensors output pin state
  45 + if(lockLow){
  46 + //makes sure we wait for a transition to LOW before any further output is made:
  47 + lockLow = false;
  48 + Serial.println("---");
  49 + Serial.print("motion detected at ");
  50 + Serial.print(millis()/1000);
  51 + Serial.println(" sec");
  52 + delay(50);
  53 + }
  54 + takeLowTime = true;
  55 + }
  56 +
  57 + if(digitalRead(pirPin) == LOW){
  58 + digitalWrite(ledPin, LOW); //the led visualizes the sensors output pin state
  59 +
  60 + if(takeLowTime){
  61 + lowIn = millis(); //save the time of the transition from high to LOW
  62 + takeLowTime = false; //make sure this is only done at the start of a LOW phase
  63 + }
  64 + //if the sensor is low for more than the given pause,
  65 + //we assume that no more motion is going to happen
  66 + if(!lockLow && millis() - lowIn > pause){
  67 + //makes sure this block of code is only executed again after
  68 + //a new motion sequence has been detected
  69 + lockLow = true;
  70 + Serial.print("motion ended at "); //output
  71 + Serial.print((millis() - pause)/1000);
  72 + Serial.println(" sec");
  73 + delay(50);
  74 + }
  75 + }
  76 + }
  77 +
  78 +
... ...
progArduino/poubelle_tests/test1/test1.ino 0 → 100644
... ... @@ -0,0 +1,81 @@
  1 +///////// DETECTEUR DE MOUVEMENT SIGNAL ////////////////////
  2 +
  3 +//INITIALISATION POUR LE CALIBRAGE
  4 +
  5 +// calibrage du capteur (10-60 secs according to the datasheet)
  6 +int calibrationTime = 20;
  7 +
  8 +//the time when the sensor outputs a low impulse
  9 +long unsigned int lowIn;
  10 +
  11 +//temps (millisecondes) durant lequel le signal est faible, soit avant qu'on suppose que tout mouvement s'est arrêté.
  12 +//on considère cela comme une pause d'insécurité sur la question: mouvement présent oui ou non?
  13 +long unsigned int pause = 5000;
  14 +
  15 +boolean lockLow = true;
  16 +boolean takeLowTime;
  17 +
  18 +int pirPin = 3; //la PIN du capteur de mouvement en 3
  19 +
  20 +
  21 +//SETUP/INITIALISATION
  22 +
  23 +void setup(){
  24 + Serial.begin(9600);
  25 + pinMode(pirPin, INPUT);
  26 + //pinMode(ledPin, OUTPUT);
  27 + digitalWrite(pirPin, LOW);
  28 +
  29 + //MOMENT POUR LE CALIBRAGE
  30 + Serial.print("calibrating sensor ");
  31 + for(int i = 0; i < calibrationTime; i++){
  32 + Serial.print(".");
  33 + delay(1000);
  34 + }
  35 + Serial.println(" done");
  36 + Serial.println("SENSOR ACTIVE");
  37 + delay(50);
  38 + }
  39 +
  40 +////////////////////////////
  41 +//LOOP
  42 +void loop(){
  43 + int i=0;
  44 + while (i<5){
  45 +
  46 + //Part 1 for each detection
  47 + if(digitalRead(pirPin) == HIGH){
  48 + //Serial.println("ok ");
  49 + i++;
  50 + //makes sure we wait for a transition to LOW before any further output is made :
  51 + if (lockLow){
  52 + lockLow=false;
  53 + Serial.println("---");
  54 + Serial.print("motion detected at ");
  55 + Serial.print(millis()/1000);
  56 + delay(1000);
  57 + }
  58 + takeLowTime=true;
  59 + }
  60 +
  61 + //Part 2 when there is no detection
  62 + if(digitalRead(pirPin)==LOW){
  63 + if (takeLowTime){
  64 + lowIn=millis();
  65 + takeLowTime=false;
  66 + }
  67 + if(!lockLow && millis()-lowIn > pause){
  68 + lockLow=true;
  69 + Serial.print("motion ended at ");
  70 + Serial.print((millis()-pause)/1000);
  71 + Serial.println(" sec");
  72 + delay(1000);
  73 + }
  74 + }
  75 + }
  76 + if(i==5){
  77 + Serial.println("Sommeil agité !!!");
  78 + delay(1000);
  79 + i=0;
  80 + }
  81 +}
... ...
progArduino/poubelle_tests/test2/test2.ino 0 → 100644
... ... @@ -0,0 +1,49 @@
  1 +
  2 +#define CAPTEUR A0
  3 +//#define SEUIL A1
  4 +
  5 +#define LED 4
  6 +
  7 +//Valeurs par défaut
  8 +int luminosite = 0;
  9 +int seuil = 100;
  10 +
  11 +void setup() {
  12 + //Initialisation de la liaison série
  13 + Serial.begin(9600);
  14 +
  15 + //Led en sortie
  16 + pinMode(LED, OUTPUT);
  17 +
  18 +}
  19 +
  20 +void loop() {
  21 +
  22 + //On récupère la valeur du seuil
  23 + luminosite = analogRead(CAPTEUR);
  24 + //Monitoring
  25 + Serial.print("Luminosite = ");
  26 + Serial.print(luminosite);
  27 +
  28 + //On récupère la valeur du seuil
  29 + //seuil = analogRead(SEUIL);
  30 + //Monitoring
  31 + Serial.print(" / Seuil = ");
  32 + Serial.print(seuil);
  33 +
  34 + //Allumage de la led si la luminosité est inférieur au seuil
  35 + if(luminosite < seuil) {
  36 + digitalWrite(LED, HIGH);
  37 + //Monitoring
  38 + Serial.println(" / LED ON");
  39 +
  40 + //Dans le cas contraire, on l'éteint
  41 + } else {
  42 + digitalWrite(LED, LOW);
  43 + //Monitoring
  44 + Serial.println(" / LED OFF");
  45 + }
  46 +
  47 + //Petite pause
  48 + delay(20);
  49 +}
... ...
progArduino/principal/principal.ino 0 → 100644
... ... @@ -0,0 +1,304 @@
  1 +//////////////////////////////////////// PROJET SC: VEILLEUSE CONNECTEE (IMA3)
  2 +//Claire Vandamme
  3 +//Justine Senellart
  4 +//Camille Saâd
  5 +
  6 +
  7 +
  8 +//--------------------------------------------------------------------------------------------------------------- INITIALISATION CONSTANTES et paramètres
  9 +
  10 +
  11 +//INIT CAPTEUR PRESENCE
  12 +
  13 +//temps donné pour calibrer le capteur de présence.(10-60 secs according to the datasheet)
  14 +int calibrationTime = 20;
  15 +//the time when the sensor outputs a low impulse
  16 +long unsigned int lowIn;
  17 +//the amount of milliseconds the sensor has to be low
  18 +//before we assume all motion has stopped
  19 +long unsigned int pause = 500;
  20 +
  21 +boolean lockLow = true;
  22 +boolean takeLowTime;
  23 +int pirPin = 3; //the digital pin connected to the PIR sensor's output
  24 +int ledPin = 13;
  25 +//var meaning the parent receives a message
  26 +int MESSAGE=0;
  27 +
  28 +
  29 +//INIT NEOPIXEL LED RGB
  30 +
  31 +//add the library
  32 +#include <Adafruit_NeoPixel.h>
  33 +//control pin
  34 +# define PININ 12
  35 +# define PINOUT 8
  36 +
  37 +// Parameter 1 = number of pixels in strip
  38 +// Parameter 2 = pin number (most are valid)
  39 +// Parameter 3 = pixel type flags, add together as needed:
  40 +// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
  41 +// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
  42 +// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
  43 +// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
  44 +Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PININ, NEO_RGB + NEO_KHZ800);
  45 +
  46 +
  47 +//INIT PHOTRESISTANCE (LUMINOSITE AMBIANTE)
  48 +#define CAPTEUR A0
  49 +int luminosite = 0;
  50 +int seuil = 200;
  51 +
  52 +//INIT interrupteur
  53 +const int pinInter = 9 ;
  54 +int etatBouton;
  55 +
  56 +
  57 +//--------------------------------------------------------------------------------------------------------------------------------------SETUP ()
  58 +
  59 +
  60 +void setup() {
  61 + //SETUP LIAISON SERIE
  62 + Serial.begin(9600);
  63 +
  64 + //SETUP INTER
  65 + pinMode(pinInter, INPUT_PULLUP); //le bouton est une entrée
  66 + etatBouton = HIGH; //on initialise l'état du bouton comme "relaché"
  67 +
  68 + //SETUP LEDS
  69 + //pour les RGB
  70 + strip.begin();
  71 + strip.show(); // Initialize all pixels to 'off'
  72 +
  73 + //Led en sortie
  74 + pinMode(PININ, OUTPUT);
  75 +
  76 +
  77 + //SETUP CAPTEUR PRESENCE ET LED ROUGE
  78 + pinMode(pirPin, INPUT);
  79 + pinMode(ledPin, OUTPUT);
  80 + digitalWrite(pirPin, LOW);
  81 + //give the sensor some time to calibrate
  82 + Serial.print("calibrating sensor ");
  83 + for(int i = 0; i < calibrationTime; i++){
  84 + Serial.print(".");
  85 + delay(1000);
  86 + }
  87 + Serial.println(" done");
  88 + Serial.println("SENSOR ACTIVE");
  89 +
  90 +
  91 + delay(50);
  92 +}
  93 +
  94 +
  95 +//------------------------------------------------------------------------------------------------------------------------FONCTIONS SECONDAIRES
  96 +
  97 +void couleur(int R, int G, int B)
  98 +{
  99 + strip.setPixelColor(0,R,G,B);
  100 + strip.show();
  101 +}
  102 +
  103 +/*
  104 +void choix_couleur()
  105 +{
  106 + int R,G,B;
  107 +
  108 + Serial.println(" Rouge =");
  109 + while (Serial.available()<0){ delay(10);}
  110 + R=Serial.read();
  111 + Serial.print(R);
  112 + Serial.print(" Vert =");
  113 + while (Serial.available()<0){ delay(10);}
  114 + G=Serial.read();
  115 + Serial.print(G);
  116 + Serial.print(" Bleu =");
  117 + while (Serial.available()<0){ delay(10);}
  118 + B=Serial.read();
  119 + Serial.print(B);
  120 +
  121 + delay(3000);
  122 + couleur(R,G,B);
  123 +}
  124 +*/
  125 +
  126 +void eteindre()
  127 +{
  128 + strip.setPixelColor(0,0,0,0);
  129 + strip.show();
  130 + digitalWrite(pirPin, LOW);
  131 + digitalWrite(ledPin, LOW);
  132 + digitalWrite(PININ, LOW);
  133 +}
  134 +
  135 +void choix_intensite()
  136 +{
  137 + int k;
  138 + k=Serial.read();
  139 + strip.setBrightness(k); //permet de régler la luminosité
  140 +}
  141 +
  142 +//fonction qui allume les led de manière automatique selon la luminosité ambiante
  143 +void lumiere_auto()
  144 +{
  145 + //On récupère la valeur du seuil
  146 + luminosite = analogRead(CAPTEUR);
  147 +
  148 + //Monitoring
  149 + Serial.print("Luminosite = ");
  150 + Serial.print(luminosite);
  151 + Serial.print(" / Seuil = ");
  152 + Serial.print(seuil);
  153 +
  154 + //Allumage de la led si la luminosité est inférieur au seuil (on l'allume dans la couleur blanche la base)
  155 + if(luminosite < seuil) {
  156 + couleur(255,255,255);
  157 + //Monitoring
  158 + Serial.println(" / LED ON");
  159 + }
  160 + //Dans le cas contraire, on l'éteint
  161 + else {
  162 + digitalWrite(PININ, LOW);
  163 + eteindre();
  164 + Serial.println(" / LED OFF");
  165 + }
  166 + delay(50);
  167 +}
  168 +
  169 +/*
  170 +void choix_type_allumage()
  171 +{
  172 + int choix;
  173 + Serial.println("Vous pouvez choisir entre l'allumage automatique (choix=1) de la veilleuse et l'allumage manuel (choix=2).");
  174 + choix= Serial.read();
  175 + if(choix==1)
  176 + {
  177 + lumiere_auto();
  178 + }
  179 + else if (choix==2)
  180 + {
  181 + int on_off;
  182 + Serial.println("Voulez vous allumer la veilleuse? (non = 0; oui =1)");
  183 + on_off=Serial.read();
  184 + //permet d'utiliser un allumage application.
  185 + }
  186 + else
  187 + {
  188 + Serial.println("ERROR CHOIX ALLUMAGE.");
  189 + }
  190 +}
  191 +*/
  192 +
  193 +void mouvement()
  194 +{
  195 + int i=0;
  196 + while(i<5)
  197 + {
  198 +
  199 + //MOVEMENT DETECTION
  200 + if(digitalRead(pirPin) == HIGH)
  201 + {
  202 + digitalWrite(ledPin, HIGH); //the led visualizes the sensors output pin state
  203 + if(lockLow)
  204 + {
  205 + //makes sure we wait for a transition to LOW before any further output is made:
  206 + lockLow = false;
  207 + Serial.println("---");
  208 + Serial.print("motion detected at ");
  209 + Serial.print(millis()/1000);
  210 + Serial.println(" sec");
  211 + delay(50);
  212 + }
  213 + takeLowTime = true;
  214 + }
  215 +
  216 + //DETECTION'S END
  217 + if(digitalRead(pirPin) == LOW)
  218 + {
  219 + digitalWrite(ledPin, LOW); //the led visualizes the sensors output pin state
  220 +
  221 + if(takeLowTime)
  222 + {
  223 + lowIn = millis(); //save the time of the transition from high to LOW
  224 + takeLowTime = false; //make sure this is only done at the start of a LOW phase
  225 + }
  226 + //if the sensor is low for more than the given pause,
  227 + //we assume that no more motion is going to happen
  228 + if(!lockLow && millis() - lowIn > pause){
  229 + //makes sure this block of code is only executed again after
  230 + //a new motion sequence has been detected
  231 + lockLow = true;
  232 + Serial.print("motion ended at "); //output
  233 + Serial.print((millis() - pause)/1000);
  234 + Serial.println(" sec");
  235 + i++;
  236 + //CHILD IS AWAKE
  237 + if(i==5 || ((millis() - pause)/1000)-(millis()/1000)> 10 ){
  238 + Serial.println("Sommeil agite !!!");
  239 + MESSAGE = 1; //servira pour la progra html (peut-être)
  240 + Serial.println(MESSAGE);
  241 + i=0;
  242 + }
  243 + delay(50);
  244 + }
  245 + }
  246 + }
  247 +}
  248 +
  249 +//---------------------------------------------------------------------------------------------------------------------------FONCTIONS PRINCIPALES
  250 +
  251 +
  252 +//fonction du programme principal (à copier plus tard dans la LOOP()
  253 +void mainVeilleuse()
  254 +{
  255 + etatBouton = digitalRead(pinInter); //Rappel :pinInter = 9
  256 +
  257 + //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
  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);
  264 + delay(1000);
  265 +
  266 + lumiere_auto();
  267 +
  268 + etatBouton = digitalRead(pinInter); //Rappel :pinInter = 9
  269 + }
  270 +
  271 + //on est eteint avec l'interrupteur manuel on peut tjrs utiliser l'application pour gerer la veilleuse
  272 + eteindre(); //la LED reste éteinte
  273 + Serial.println("UTILISATION APPLICATION: application");
  274 +
  275 +
  276 +}
  277 +
  278 +
  279 +
  280 +//fonction permettant de faire les tests des foncions secondaires
  281 +void tests()
  282 +{
  283 + //couleur(0,255,0);
  284 + //choix_couleur();
  285 + //eteindre();
  286 + //choix_intensite();
  287 + //choix_type_allumage();
  288 + mouvement();
  289 + //lumiere_auto();
  290 + delay(200);
  291 +}
  292 +
  293 +
  294 +
  295 +
  296 +//----------------------------------------------------------------------------------------------------------------------------LOOP == MAIN PROG
  297 +void loop()
  298 +
  299 +{
  300 + tests();
  301 +
  302 + //mainVeilleuse();
  303 + delay(200);
  304 +}
... ...