#include // Pour la racine carré et la puissance (pow et sqrt)Pour les lignes 239 et 242 -- #include #include "Arduino.h" #define nEchantillons 201 //---------------------------------------------- VARIABLES ------------------------------------------------------ int sensorPin = A1; //---------- broche d'entrée A0 pour le capteur de pression MPX 4250 -------------------- int octetReception=0; //--------- variable de stockage des valeurs reçues sur le port Série ------------------- long nombreReception=0; //------- variable pour nombre reçu sur port Série --------------------------------- float echantillon[nEchantillons];//-------- un tableau pour stocker les échantillons lus ------------------------ int indice = 0; //-------- l'indice de l'échantillon courant ----------------------------------- double total = 0; // ------- la somme des échantillons mémorisés --------------------------------- double moyenne = 0; // -------- la moyenne des échantillons mémorisés ------------------------------- double Diff[nEchantillons]; double ecartype; long nombreRecu = 0; float maxValPression; float minValPression; float Pression = 0; void setup() { Serial.begin(9600); // initialise connexion série à 9600 bauds for (int i = 0; i < nEchantillons; i++) { echantillon[i] = 0; } } void loop()// ******************************** début de loop *************************************************** { while (nombreReception == 0) { nombreReception = recevoirNombre(); //----------- appel de la fonction recevoirNombre ------------------- for (int i = 0; i < nEchantillons ; i++) { echantillon[i] = 0; } total = 0; moyenne = 0; ecartype = 0; indice = 0; maxValPression = 0; minValPression = 0; delay(30); } // --------------------------------------- En attente d'une valeur ------------------------------------ indice++; //---------- Incrémentation de l'indice --------------------------- echantillon[indice] =(analogRead(A1)*(0.00486)/(0.022)+20)*10;//---------------- POUR MPX4250------------ total += echantillon[indice]; moyenne = total / indice ; // calcul de la moyenne if( echantillon[indice] target="1"> maxValPression) { maxValPression = echantillon[indice]; } if( echantillon[indice] <= minValPression || minValPression == 0) { minValPression = echantillon[indice]; } delay(50); Serial.print(" Echantillon : "); Serial.print (indice); Serial.print (" "); Serial.print(" Pression : "); Serial.print (echantillon[indice]); Serial.println (" hPa"); if (indice >= nombreReception) // si fin du tableau -------------------------------------------- { Serial.println (); Serial.print(" ********* moyenne ************** : "); Serial.print (moyenne); ecart_type(); nombreReception = 0; total = 0; moyenne = 0; ecartype = 0; indice = 0; for (int i = 0; i < nEchantillons ; i++) { echantillon[i] = 0; } Serial.println (); Serial.print (" Pression MAX : "); Serial.println(maxValPression,2); Serial.println (); Serial.print (" Pression MIN : "); Serial.println(minValPression,2); Serial.println (); Serial.print ("*********************************************"); Serial.println (); } delay(250); } //************************************************* FIN DE LOOP ********************************************** long recevoirNombre() //------------ fonction de reception d'un nombre sur le port série ---------------- { int octetRecu = 0; // variable pour octet recu nombreRecu = 0; // variable locale nombre recu while (Serial.available() target="1">0) { octetRecu = Serial.read(); //------------- Lit le 1er octet reçu et le met dans la variable ------------ octetRecu = octetRecu-48; //-------------- conversion valeur ASCII en valeur décimale ----------------- if ((octetRecu>= 0)&&(octetRecu<= 9)) nombreRecu = (nombreRecu*10)+octetRecu; // calcul du nombre à partir des valeurs reçues delay(10); } if (nombreRecu <= 200) { return(nombreRecu); // renvoie le nombre calculé } } //***************************************************************************************************************** void ecart_type() /// --------------- Sous-programme pour le "Calcul de l'Ecart_type" ------------- { for (int i = 1; i < indice; i++) { Diff[i]= pow(echantillon[i]- moyenne,2); ecartype += Diff[i]; } ecartype = sqrt(ecartype / indice); Serial.println () ; Serial.print(" ********* Ecart-Type *********** : "); Serial.println(ecartype,2); } //******************************************************************************************************************** >