projet en 1 main.cpp

Dependencies:   DHT11 HMC5883L

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "DHT11.h"
00003 #include "HMC5883L.h"
00004 #include "gps.h"
00005 
00006 #define PRINT_CALCULATED
00007 #define PRINT_SPEED 500 // 500 ms between prints
00008 
00009 
00010 //-------Pin Connection----///
00011 DHT11 sensor(D4);//D4= dht11 data
00012 HMC5883L bouss(PB_9, PB_8); // HMC5883L(PinName sda, PinName scl) PB_8 + PB_9
00013 Serial rfid(PA_9, PA_10); // pa9=d8 pa10=d2
00014 Serial serial(PA_0,PA_1);  /*PA_0=A0=TX PA_1=A0=RX*/
00015 AnalogIn inputx(PC_0); // input A5 for X axis
00016 AnalogIn inputy(PC_1); // input A4 for Y axis
00017 AnalogIn inputz(PB_1); // input A3 for Z axis
00018 
00019 float x=0,y=0,z=0; // variables for x,y,z axes
00020 
00021 int H, T, s;
00022 float Boussole;
00023 int Head;
00024 char buff[55];
00025 int RFIDA;
00026 
00027 int DHT_Start_Temper()
00028 {
00029     s = sensor.readData();
00030     T=sensor.readTemperature();
00031     return T;
00032 }
00033 
00034 int DHT_Start_Humid()
00035 {
00036     s = sensor.readData();
00037     H=sensor.readHumidity();
00038     return H;
00039 }
00040 
00041 
00042 int Boussole_Start()
00043 {
00044     //Head is divided by 2 because of sending data to actoboard the value is limit to 255
00045     bouss.init();
00046     Boussole= bouss.getHeadingXYDeg();
00047     Head=((int)Boussole)/2;
00048     serial.printf("\r\n-----Boussole-----\r\n%2f\r\n-----Boussole-----\r\n",Boussole);
00049     return Head;
00050 }
00051 
00052 int Accelerometre_Start_x()
00053 {
00054     x = inputx;
00055     serial.printf("\r\n-----Accelerometre-----\r\nX:%f,Y: %f,Z: %f \r\n-----Accelerometre-----\r\n",x,y,z);
00056     return x;
00057 }
00058 
00059 int Accelerometre_Start_y()
00060 {
00061     y = inputy;
00062     serial.printf("\r\n-----Accelerometre-----\r\nX:%f,Y: %f,Z: %f \r\n-----Accelerometre-----\r\n",x,y,z);
00063     return y;
00064 }
00065 
00066 int Accelerometre_Start_z()
00067 {
00068     z = inputz;
00069     serial.printf("\r\n-----Accelerometre-----\r\nX:%f,Y: %f,Z: %f \r\n-----Accelerometre-----\r\n",x,y,z);
00070     return z;
00071 }
00072 
00073 
00074 
00075 void RFID_Start()
00076 {
00077     int i;
00078     int tag[15];
00079 
00080     for(i=0; i<5; i++)
00081         tag[i]=rfid.getc();
00082 
00083     sprintf(buff,"%d%d%d%d%d",tag[0],tag[1],tag[2],tag[3],tag[4]);
00084     serial.printf("\r\n-----Tag RFID-----\r\n%s \r\n-----Tag RFID-----\r\n",buff);
00085 
00086 }
00087 //---------------
00088 
00089 int main()
00090 {
00091     //serial config
00092     serial.baud(9600);
00093     serial.format(8,SerialBase::None,1);
00094 
00095     serial.printf("\r\n Bracelet Orientation\r\n****************\r\n");
00096 
00097     char *p1lat, *p2lat, *p3lat;
00098     int intp1lat, intp2lat, intp3lat;
00099     char *p1long, *p2long, *p3long;
00100     int intp1long, intp2long, intp3long;
00101 
00102 
00103     while(1) {
00104         T=DHT_Start_Temper();
00105         H=DHT_Start_Humid();
00106         Head=Boussole_Start();
00107         x=Accelerometre_Start_x();
00108         y=Accelerometre_Start_y();
00109         z=Accelerometre_Start_z();
00110         getGPSstring();
00111 
00112 
00113         RFID_Start();
00114         RFIDA=atoi(buff);
00115         RFIDA=RFIDA/10000000;
00116 
00117         //traitement Latitude
00118         p1lat = strtok(lati,"'");
00119         p2lat= strtok(NULL, "'");//the second
00120         p3lat= strtok(NULL, ".");//the third    
00121 
00122         //conversion latitude
00123         intp1lat=atoi(p1lat);
00124         intp2lat=atoi(p2lat);
00125         intp3lat=atoi(p3lat);
00126         //concatcénation lati
00127         int latitude_complet_int;
00128         char latitude_complet[6];
00129         strcat(latitude_complet,p1lat);
00130         strcat(latitude_complet,p2lat);
00131         strcat(latitude_complet,p3lat);
00132         latitude_complet_int=atoi(latitude_complet);
00133 
00134 
00135 
00136         //traitement longitude
00137         p1long = strtok(longi,"'");
00138         p2long= strtok(NULL, "'");//the second
00139         p3long= strtok(NULL, ".");//the third
00140         intp1long=atoi(p1long);
00141         intp2long=atoi(p2long);
00142         intp3long=atoi(p3long);
00143 
00144         //concatcénation longitude
00145         int longitude_complet_int;
00146         char longitude_complet[6];
00147         strcat(longitude_complet,p1long);
00148         strcat(longitude_complet,p2long);
00149         strcat(longitude_complet,p3long);
00150         longitude_complet_int=atoi(longitude_complet);
00151 
00152         serial.printf("AT$SS=%x%x%x%x%x0%x%x%x%x%x\r\n",T,H,intp1lat,intp2lat,intp3lat,intp1long,intp2long,intp3long,RFIDA,Head);
00153 
00154         wait(5);
00155     }
00156 }