Tsuyoshi Nakashima / Mbed 2 deprecated MPU6050_1

Dependencies:   MPU6050 SDFileSystem mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MPU6050.cpp Source File

MPU6050.cpp

00001 //include libraries in cpp file
00002 #include "mbed.h"
00003 #include "MPU6050.h"
00004 #include "SDFileSystem.h"
00005 SDFileSystem sd(PC_12, PC_11, PC_10, PD_2, "sd");
00006 FILE* fp;
00007 
00008 Ticker timer;
00009 double t=0;
00010 //creating an object of serial class
00011 //so that we can communicate with PC
00012 Serial pc(SERIAL_TX, SERIAL_RX);
00013 //setting LED1 to give digital output
00014 DigitalOut myled(LED1);
00015 //creating onject of MPU6050 class
00016 MPU6050 ark(PB_9,PB_8);
00017 //int main()
00018 void time()
00019 {       
00020         /*reading Temprature
00021         float temp = ark.getTemp();
00022         pc.printf("temprature = %0.2f ^C\r\n",temp);
00023         */
00024         //reading Grometer readings
00025         float gyro[3];
00026         ark.getGyro(gyro);
00027         //pc.printf("Gyro0=%f,\tGyro1=%f,\tGyro2=%f\r\n",gyro[0],gyro[1],gyro[2]);
00028         
00029         //reading Acclerometer readings
00030         float acce[3];
00031         ark.getAccelero(acce);
00032         //pc.printf("Acce0=%f,Acce1=%f,Acce2=%f\r\n",acce[0],acce[1],acce[2]);
00033         //pc.printf("%f,%f,%f,%f,%f,%f,%f\r\n",acce[0],acce[1],acce[2],gyro[0],gyro[1],gyro[2]);
00034           pc.printf("t=%f\r\n",t);
00035          t+=5;
00036         fprintf(fp,"%f,%f,%f,%f,%f,%f,%f\r\n",acce[0],acce[1],acce[2],gyro[0],gyro[1],gyro[2]);
00037         if(t>=(20)){
00038             timer.detach();
00039             fclose(fp);
00040             printf("Goodbye World!\n");  
00041         }
00042     }
00043 int main(){
00044     
00045       /*ディレクトリ作成*/
00046     mkdir("/sd/test", 0777);
00047       /*ファイル作成*/
00048     fp = fopen("/sd/test/sensor_log.csv", "w");
00049     if(fp == NULL) {
00050         error("Could not open file for write\n");
00051     }
00052     timer.attach(&time,5);
00053     
00054     
00055     }
00056     
00057     
00058     /*
00059     #include "mbed.h"
00060 #include "SDFileSystem.h"
00061  
00062 SDFileSystem sd(PC_12, PC_11, PC_10, PD_2, "sd"); //CMD(MOSI),DAT0(MISO),CLK(CSK),CD/DAT3(CS)
00063  
00064 int main() {
00065     printf("Hello World!\n");   
00066  
00067     mkdir("/sd/mydir", 0777);
00068     
00069     FILE *fp = fopen("/sd/mydir/sdtest.txt", "w");
00070     if(fp == NULL) {
00071         error("Could not open file for write\n");
00072     }
00073     fprintf(fp, "Hello fun SD Card World!");
00074     fclose(fp); 
00075  
00076     printf("Goodbye World!\n");
00077 }*/