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: IM920 SDFileSystem mbed
main.cpp
00001 /*** 受信したデータをSDに保存して確認するプログラム */ 00002 00003 #include "mbed.h" 00004 #include "IM920.h" 00005 #include "SDFileSystem.h" 00006 00007 // Pin used by SD card 00008 SDFileSystem sd(p5, p6, p7, p8, "sd"); 00009 00010 // Pin used by IM920 & UART 00011 Serial pc(USBTX, USBRX); 00012 IM920 im920(p28, p27, p29, p30); 00013 00014 //Digital I/O Pin 00015 DigitalOut myled1(LED1); 00016 DigitalOut myled2(LED2); 00017 AnalogIn inpt(p20); 00018 00019 //Prottype define 00020 void SD(int num, double btry); 00021 void callback(void); 00022 00023 //Define maclo 00024 char BUF[65]; 00025 00026 int main() { 00027 float btry_lg = 0; 00028 int nmbr_lg = 0; 00029 00030 FILE *fp_csv = fopen("/sd/mydir/sdtest.csv", "w"); 00031 if(fp_csv == NULL) { 00032 error("Could not open file for write\n"); 00033 } 00034 fprintf(fp_csv, "baterry,number\n"); 00035 fclose(fp_csv); 00036 00037 00038 // FILE *fp_txt = fopen("/sd/mydir/sdtest.txt", "a"); 00039 // if(fp_txt == NULL) { 00040 // error("Could not open file for write\n"); 00041 // } 00042 // fclose(fp_txt); 00043 00044 while(1){ 00045 // test the voltage on the initialized analog pin 00046 // and if greater than 0.3 * VCC set the digital pin 00047 // to a logic 1 otherwise a logic 0 00048 btry_lg = inpt.read()*3.3; 00049 00050 //if(ain > 0.3f) { 00051 00052 //} else { 00053 00054 //} 00055 00056 // print the percentage and 16 bit normalized values 00057 //printf("percentage: %3.3f%%\n", ain.read()*100.0f); 00058 //printf("normalized: 0x%04X \n", ain.read_u16()); 00059 //wait(0.2f); 00060 00061 00062 00063 nmbr_lg++; 00064 SD(nmbr_lg, btry_lg); 00065 00066 //wait(0.1); 00067 } 00068 } 00069 00070 void SD(int num, double btry){ 00071 myled1 = 1; 00072 00073 //printf("Hello World!\n"); 00074 00075 mkdir("/sd/mydir", 0777); 00076 00077 FILE *fp_csv = fopen("/sd/mydir/sdtest.csv", "a"); 00078 if(fp_csv == NULL) { 00079 error("Could not open file for write\n"); 00080 } 00081 00082 fprintf(fp_csv, "%d,%f\n",num, btry); 00083 00084 fclose(fp_csv); 00085 00086 /*** txtファイルバージョン ***/ 00087 00088 // FILE *fp_txt = fopen("/sd/mydir/sdtest.txt", "a"); 00089 // if(fp_txt == NULL) { 00090 // error("Could not open file for write\n"); 00091 // } 00092 // fprintf(fp_txt, "Hello fun SD Card World!\n"); 00093 // fprintf(fp_txt, "Hello fun SD Card World!\n"); 00094 // fprintf(fp_txt, "%f,%f\n", btry, (float)num); 00095 // 00096 // fclose(fp_txt); 00097 00098 00099 printf("Goodbye World!\n"); 00100 myled1 = 0; 00101 } 00102 00103 void callback(void){ 00104 int i; 00105 char buf[65]; 00106 00107 i = im920.recv(buf, 64); 00108 buf[i] = 0; 00109 printf("recv: '%s' (%d)\r\n", buf, i); 00110 } 00111 00112 void IM920_read(void){ 00113 int i = 0; 00114 00115 //pc.baud(115200); 00116 pc.band(19200); 00117 pc.printf("*** IM920\r\n"); 00118 im920.init(); 00119 im920.attach(callback); 00120 myled2 = 1; 00121 00122 im920.poll(); 00123 if (pc.readable()) { 00124 char c = pc.getc(); 00125 00126 if (c == '\r') { 00127 BUF[i] = 0; 00128 printf("send: %s\r\n", BUF); 00129 im920.send(BUF, i); 00130 } 00131 else{ 00132 for (i = 0; i < 64; i++) { 00133 BUF[i] = c; 00134 } 00135 } 00136 }
Generated on Sun Jul 17 2022 12:04:33 by
1.7.2