Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: HMC5883L MPU6050 SDFileSystem_fuck mbed
Fork of SDFileSystem_HelloWorld by
main.cpp
00001 //include libraries in cpp file 00002 #include "mbed.h" 00003 #include "MPU6050.h" 00004 #include "SDFileSystem.h" 00005 #include "HMC5883L.h" 00006 SDFileSystem sd(PC_12, PC_11, PC_10, PD_2, "sd"); 00007 FILE* fp; 00008 Timer t; 00009 //Ticker timer; 00010 double n=0; 00011 //creating an object of serial class 00012 //so that we can communicate with PC 00013 Serial pc(SERIAL_TX, SERIAL_RX); 00014 //setting LED1 to give digital output 00015 DigitalOut myled(LED1); 00016 //creating onject of MPU6050 class 00017 MPU6050 ark(PB_9,PB_8); 00018 HMC5883L MG(PB_9,PB_8); 00019 //int main() 00020 /*void time() 00021 { 00022 reading Temprature 00023 float temp = ark.getTemp(); 00024 pc.printf("temprature = %0.2f ^C\r\n",temp); 00025 00026 //reading Grometer readings 00027 float gyro[3]; 00028 ark.getGyro(gyro); 00029 //pc.printf("Gyro0=%f,\tGyro1=%f,\tGyro2=%f\r\n",gyro[0],gyro[1],gyro[2]); 00030 00031 //reading Acclerometer readings 00032 float acce[3]; 00033 ark.getAccelero(acce); 00034 //pc.printf("Acce0=%f,Acce1=%f,Acce2=%f\r\n",acce[0],acce[1],acce[2]); 00035 //pc.printf("%f,%f,%f,%f,%f,%f,%f\r\n",acce[0],acce[1],acce[2],gyro[0],gyro[1],gyro[2]); 00036 pc.printf("t=%f\r\n",t); 00037 t+=5; 00038 fprintf(fp,"%f,%f,%f,%f,%f,%f,%f\r\n",acce[0],acce[1],acce[2],gyro[0],gyro[1],gyro[2]); 00039 if(t>=(20)){ 00040 timer.detach(); 00041 fclose(fp); 00042 printf("Goodbye World!\n"); 00043 } 00044 } 00045 */ 00046 int main(){ 00047 pc.printf("start\r\n"); 00048 /*ディレクトリ作成*/ 00049 mkdir("/sd/test", 0777); 00050 /*ファイル作成*/ 00051 fp = fopen("/sd/test/sensor_log_AGM.csv", "wb"); 00052 00053 t.start(); 00054 if(fp == NULL) { 00055 error("Could not open file for write\n"); 00056 } 00057 //timer.attach(&time,5); 00058 while(1){ 00059 float gyro[3]; 00060 ark.getGyro(gyro); 00061 float acce[3]; 00062 ark.getAccelero(acce); 00063 int16_t Mg[3]; 00064 MG.getXYZ(Mg); 00065 n+=0.01; 00066 fprintf(fp,"%f,%f,%f,%f,%f,%f,%d,%d,%d\r\n",acce[0],acce[1],acce[2],gyro[0],gyro[1],gyro[2],Mg[0],Mg[1],Mg[2]); 00067 wait(0.01); 00068 if(n>=(60)){ 00069 //timer.detach(); 00070 t.stop(); 00071 fprintf(fp,"t=%f",t.read_ms()); 00072 fclose(fp); 00073 printf("Goodbye World!\r\n"); 00074 break; 00075 } 00076 } 00077 } 00078 00079 00080 /* 00081 #include "mbed.h" 00082 #include "SDFileSystem.h" 00083 00084 SDFileSystem sd(PC_12, PC_11, PC_10, PD_2, "sd"); //CMD(MOSI),DAT0(MISO),CLK(CSK),CD/DAT3(CS) 00085 00086 int main() { 00087 printf("Hello World!\n"); 00088 00089 mkdir("/sd/mydir", 0777); 00090 00091 FILE *fp = fopen("/sd/mydir/sdtest.txt", "w"); 00092 if(fp == NULL) { 00093 error("Could not open file for write\n"); 00094 } 00095 fprintf(fp, "Hello fun SD Card World!"); 00096 fclose(fp); 00097 00098 printf("Goodbye World!\n"); 00099 }*/
Generated on Fri Jul 22 2022 10:55:55 by
1.7.2
