Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "SDFileSystem.h"
00003 //comment
00004 Serial pc(USBTX, USBRX); // tx, rx
00005 DigitalOut led1(LED1);
00006 SDFileSystem sd(p5, p6, p7, p8, "sd"); //i, o, clk, cs, const : on the card 3,7,5,2
00007 Ticker logger;
00008 
00009 void loggit() {
00010     time_t seconds = time(NULL);
00011     int mins = seconds/60;
00012     int hours = seconds/3600;
00013     int secs = seconds - (mins*60) - (hours * 3600);
00014     pc.printf("FORMATTED ");
00015     pc.printf("%04.4i:%02.2i:%02.2i \n\r", hours,mins,secs);
00016 
00017     char  strh[4];
00018     char  strm[2];
00019     char  strs[2];
00020 
00021     sprintf(strh, "%04.4i",hours);
00022     sprintf(strm, "%02.2i",mins);
00023     sprintf(strs, "%02.2i",secs);
00024     FILE *lp = fopen("/sd/log.csv", "a");
00025     pc.printf("Open");
00026     fprintf(lp,strh);
00027     fprintf(lp,":");
00028     fprintf(lp,strm);
00029     fprintf(lp,":");
00030     fprintf(lp,strs);
00031     fprintf(lp,",");
00032     fprintf(lp,"12 \r");
00033     fclose(lp);
00034     pc.printf("Closed");
00035 }
00036 
00037 int main() {
00038 
00039     set_time(1);
00040 
00041     logger.attach(&loggit, 2.0);
00042 
00043 
00044     while (1) {
00045         led1 = !led1;
00046         wait(1);
00047 
00048     }
00049 
00050 }