LAURUS / Mbed 2 deprecated Datalogger

Dependencies:   SDFileSystem mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "Log.h"
00003 
00004 DigitalIn mybutton(USER_BUTTON);
00005 Serial pc(SERIAL_TX, SERIAL_RX);
00006 
00007 Log logger(SERIAL_TX, SERIAL_RX, SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS, "sd");
00008 
00009 Ticker timer;
00010 void Int_Timer();
00011 static double t;
00012 
00013 int main() {
00014     /** ログのタイトル行 **/
00015     char* str="time,button\n";
00016     if(!(logger.initialize_sdlog(str))){
00017         return 0;
00018     }
00019 
00020 //    printf("Start!\n");
00021     timer.attach(&Int_Timer, 0.1);
00022     
00023     t = 0.0;
00024     while(1){
00025         if(t > 10.0){
00026             timer.detach();
00027             break;
00028         }
00029     }
00030 
00031     logger.close();
00032     printf("Finish!\n");
00033 }
00034 
00035 
00036 void Int_Timer() {
00037     char buf[20];
00038     /** ログをとりたい値を記入 **/
00039     sprintf(buf, "%.1f,%d\n", t, (int)mybutton);
00040     logger.puts(buf);
00041     t += 0.1;
00042 }