test capteurs BMP085 météo

Dependencies:   mbed

Committer:
bouaziz
Date:
Fri Oct 14 18:44:39 2011 +0000
Revision:
0:ad2afb285975
v1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bouaziz 0:ad2afb285975 1 #include "mbed.h"
bouaziz 0:ad2afb285975 2 #include "BMP085.h"
bouaziz 0:ad2afb285975 3 #include "string.h"
bouaziz 0:ad2afb285975 4
bouaziz 0:ad2afb285975 5 BMP085 bmp085(p9, p10);
bouaziz 0:ad2afb285975 6
bouaziz 0:ad2afb285975 7 DigitalOut myled(LED1);
bouaziz 0:ad2afb285975 8 DigitalOut myled4(LED4);
bouaziz 0:ad2afb285975 9 Serial pc(USBTX, USBRX);
bouaziz 0:ad2afb285975 10
bouaziz 0:ad2afb285975 11 LocalFileSystem local("local");
bouaziz 0:ad2afb285975 12
bouaziz 0:ad2afb285975 13 int main() {
bouaziz 0:ad2afb285975 14 float p, t;
bouaziz 0:ad2afb285975 15 int ii=0;
bouaziz 0:ad2afb285975 16 char pname[12],stval[6];
bouaziz 0:ad2afb285975 17 DIR *d = opendir("/local"); // Opens the root directory of the local file system
bouaziz 0:ad2afb285975 18 struct dirent *pdir;
bouaziz 0:ad2afb285975 19 int indice=1;
bouaziz 0:ad2afb285975 20 while((pdir = readdir(d)) != NULL) { // Print the names of the files in the local file system
bouaziz 0:ad2afb285975 21 pc.printf("%u %s\r",indice, pdir->d_name);
bouaziz 0:ad2afb285975 22 if(strstr(pdir->d_name,"OUT")== pdir->d_name) {
bouaziz 0:ad2afb285975 23 indice++;
bouaziz 0:ad2afb285975 24 }
bouaziz 0:ad2afb285975 25 }
bouaziz 0:ad2afb285975 26 closedir(d);
bouaziz 0:ad2afb285975 27 strcpy(pname,"/local/out");
bouaziz 0:ad2afb285975 28 sprintf(stval,"%02u",indice);
bouaziz 0:ad2afb285975 29 strcat(pname,stval);
bouaziz 0:ad2afb285975 30 strcat(pname,".txt");
bouaziz 0:ad2afb285975 31
bouaziz 0:ad2afb285975 32 FILE *fp = fopen(pname, "w"); // Open "out.txt" on the local file system for writing
bouaziz 0:ad2afb285975 33 myled4=0;
bouaziz 0:ad2afb285975 34 while(1) {
bouaziz 0:ad2afb285975 35 myled = 1;
bouaziz 0:ad2afb285975 36
bouaziz 0:ad2afb285975 37 bmp085.update();
bouaziz 0:ad2afb285975 38 p = bmp085.get_pressure();
bouaziz 0:ad2afb285975 39 t = bmp085.get_temperature();
bouaziz 0:ad2afb285975 40 // if(t>24.0){
bouaziz 0:ad2afb285975 41 // myled4=1;
bouaziz 0:ad2afb285975 42 // }else{
bouaziz 0:ad2afb285975 43 // myled4=0;
bouaziz 0:ad2afb285975 44 // }
bouaziz 0:ad2afb285975 45 pc.printf("p:%6.2f hPa / t:%6.2f C\r", p, t);
bouaziz 0:ad2afb285975 46
bouaziz 0:ad2afb285975 47 if(ii<60){
bouaziz 0:ad2afb285975 48 ii=ii+1;
bouaziz 0:ad2afb285975 49 fprintf(fp,"p:%6.2f hPa / t:%6.2f C\r", p, t);
bouaziz 0:ad2afb285975 50 }else{
bouaziz 0:ad2afb285975 51 fclose(fp);
bouaziz 0:ad2afb285975 52 myled4=1;
bouaziz 0:ad2afb285975 53 }
bouaziz 0:ad2afb285975 54
bouaziz 0:ad2afb285975 55 myled = 0;
bouaziz 0:ad2afb285975 56 wait(0.5);
bouaziz 0:ad2afb285975 57 }
bouaziz 0:ad2afb285975 58 }