|
/////////////////////////////////////////////////////////////////
|
|
///////////////Lumiere///////////////////////////////////////////
|
|
/////////////////////////////////////////////////////////////////
|
|
|
|
|
|
// initialisation des variables pour la detection lumineuse
|
|
|
|
int capteurPin = A2; // the cell and 10K pulldown are connected to a0
|
|
int valeurCapteur; // Valeur analogique lu sur la broche A0
|
|
int valiLum = 0;
|
|
int valiMouv = 0;
|
|
int etalMouv = 50;
|
|
const int seuilLum = /*650*/ 650;
|
|
//initialisation des variables pour la detection de mouvement
|
|
|
|
///////////////////////////////////////////////////////////////
|
|
//////////////// Mouvement/////////////////////////////////////
|
|
///////////////////////////////////////////////////////////////
|
|
|
|
// declaration constante de broche adxl335
|
|
int valCapt_X = A5;
|
|
int valCapt_Y = A4;
|
|
int valCapt_Z = A3;
|
|
|
|
|
|
// declaration variable pour angle
|
|
int angleX = 0;// variable pour angle adxl
|
|
int angleY = 0;
|
|
int angleZ = 0;
|
|
|
|
int angleXX = 0;
|
|
int angleYY = 0;
|
|
int angleZZ = 0;
|
|
|
|
///////////////////////////////////////////////////////////////
|
|
//////////setup////////////////////////////////////////////////
|
|
///////////////////////////////////////////////////////////////
|
|
|
|
void setup(void)
|
|
{
|
|
pinMode (capteurPin, INPUT);
|
|
|
|
pinMode (valCapt_X, INPUT);
|
|
pinMode (valCapt_Y, INPUT);
|
|
pinMode (valCapt_Z, INPUT);
|
|
|
|
pinMode (9, OUTPUT); // 12 sortie (groupe de 3 leds)
|
|
pinMode (10, OUTPUT); // 10 sortie (groupe de 3 leds)
|
|
pinMode (11, OUTPUT); // 11 sortie (groupe de 3 les)
|
|
|
|
Serial.begin(9600); // ouverture du port série à 9600 bauds
|
|
}
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////
|
|
////////////Loop/////////////////////////////////////////////////
|
|
/////////////////////////////////////////////////////////////////
|
|
|
|
void loop(void)
|
|
{
|
|
|
|
valeurCapteur = analogRead(capteurPin); // valeurCapteur = valeur de A0
|
|
|
|
Serial.print("Valeur du capteur = ");
|
|
Serial.print(valeurCapteur); // lecture de la valeur brute du capteur
|
|
|
|
|
|
// début test luminosité//
|
|
|
|
valeurCapteur = analogRead(A0) ;
|
|
|
|
if (valeurCapteur > seuilLum)
|
|
{
|
|
Serial.println(" - Nuit");
|
|
|
|
valiLum = 1;
|
|
}
|
|
|
|
else
|
|
{
|
|
Serial.println(" - Jour");
|
|
|
|
valiLum = 0 ;
|
|
}
|
|
|
|
// debut test mvt//
|
|
|
|
/* acquisition conversion analogique numérique (100µs env.)
|
|
sur broche analogique indiquée - résultat 10bits (0-1023)*/
|
|
|
|
angleX = analogRead(valCapt_X);// capture de la variable tension pour l'axe x adxl335
|
|
angleY = analogRead(valCapt_Y);// l'axe y
|
|
angleZ = analogRead(valCapt_Z);// puis z
|
|
|
|
|
|
Serial.print("angle X = ");
|
|
Serial.print(angleX);
|
|
/*
|
|
Serial.print("angle y = ");
|
|
Serial.print(angleY);
|
|
Serial.print("angle z = ");
|
|
Serial.print(angleZ);
|
|
*/
|
|
|
|
if (angleX != angleXX ) /* || ((angleY != angleYY + etalMouv) || (angleY != angleYY - etalMouv)) || ((angleZ != angleZZ + etalMouv) ||(angleZ != angleZZ - etalMouv))*/
|
|
{
|
|
valiMouv = 1 ;
|
|
}
|
|
|
|
else
|
|
{
|
|
valiMouv = 0;
|
|
}
|
|
angleXX = angleX;
|
|
|
|
Serial.print("Valeur du mouvement = ");
|
|
Serial.print(valiMouv);
|
|
Serial.print("Valeur du lumiere = ");
|
|
Serial.print(valiLum);
|
|
|
|
if ( (valiMouv == 1) && (valiLum == 1))
|
|
{
|
|
digitalWrite(9, HIGH); // turn the LED on (HIGH is the voltage level)
|
|
delay(150); // wait for a second
|
|
digitalWrite(9, LOW); // turn the LED off by making the voltage LOW
|
|
delay(600); // wait for a second
|
|
digitalWrite(10, HIGH);
|
|
delay(150);
|
|
digitalWrite(10, LOW);
|
|
delay(600);
|
|
digitalWrite(11, HIGH);
|
|
delay(150);
|
|
digitalWrite(11, LOW);
|
|
delay(1000);
|
|
|
|
/* Allumage de la deuxieme sequence, allumage progressive des led
|
|
a la suite et coupure en meme temps*/
|
|
|
|
digitalWrite (9, HIGH); //Turn the first ledA3 on
|
|
delay (800);
|
|
|
|
digitalWrite( 10, HIGH); // turn the ledA4 on
|
|
delay (800);
|
|
|
|
digitalWrite (11, HIGH); // turn the ledA2 on
|
|
delay (800);
|
|
|
|
/* Sequence de clignotement bref des LED
|
|
*/
|
|
|
|
digitalWrite (9, LOW);
|
|
digitalWrite (10, LOW);
|
|
digitalWrite (11, LOW);
|
|
delay(150);// eteindre les 3 leds en meme temps
|
|
|
|
digitalWrite (9, HIGH);
|
|
digitalWrite( 10, HIGH);
|
|
digitalWrite (11, HIGH);
|
|
delay (150);
|
|
|
|
digitalWrite (9, LOW);
|
|
digitalWrite (10, LOW);
|
|
digitalWrite (11, LOW);
|
|
delay(150);//
|
|
|
|
digitalWrite (9, HIGH);
|
|
digitalWrite( 10, HIGH);
|
|
digitalWrite (11, HIGH);
|
|
delay (150);
|
|
|
|
digitalWrite (9, LOW);
|
|
digitalWrite (10, LOW);
|
|
digitalWrite (11, LOW);
|
|
delay(150);//
|
|
|
|
digitalWrite (9, HIGH);
|
|
digitalWrite( 10, HIGH);
|
|
digitalWrite (11, HIGH);
|
|
delay (150);
|
|
|
|
digitalWrite (9, LOW);
|
|
digitalWrite (10, LOW);
|
|
digitalWrite (11, LOW);
|
|
delay(600);// Eteint les trois led pdt 6ms
|
|
|
|
}
|
|
delay (1000);
|
|
}
|
|
|
|
|
|
|
|
|
|
|