![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Lecture 13 USB Example
Dependencies: FatFileSystem MSCFileSystem mbed
Fork of mbed-App-USBFlash by
Diff: main.cpp
- Revision:
- 2:c887cf1c3ed9
- Parent:
- 0:22a5db2c7926
--- a/main.cpp Mon Jul 23 09:59:38 2012 +0000 +++ b/main.cpp Tue Oct 16 15:47:35 2012 +0000 @@ -1,39 +1,23 @@ -#include "mbed.h" -#include "MSCFileSystem.h" - -MSCFileSystem sd("sd"); - - -DigitalOut led1(LED1); -DigitalOut led2(LED2); -DigitalOut led3(LED3); -DigitalOut led4(LED4); - -int main() { - - printf("This is version 1.0 of the USB host test\n"); - - FILE *fp = fopen("/sd/test.txt","w"); - printf("Create filehandle\n"); - - led1= 1; - - if (fp == NULL) { //make sure it's been opened - printf("its bad :-(\n"); - led2 = 1; - exit(1); - } - printf("its good :-)\n"); - - led3 = 1; - - fprintf(fp,"Hello world!\n"); - printf("Write to the file\n"); - - - fclose(fp); - printf("Close the handle\n"); - - led4 = 1; - printf("\n"); -} +#include "mbed.h" +#include "MSCFileSystem.h" + +MSCFileSystem fs("fs"); +DigitalOut led(LED1); +AnalogIn pot1(p19); + +int main() +{ + FILE *fp = fopen("/fs/test.csv","w"); + printf("Create filehandle for test.csv\n"); + + printf("Writing to file\n"); + for (int i=0; i<100; i++) { + fprintf(fp,"%.2f\n",pot1.read()); + wait(0.05); + led=!led; + } + + fclose(fp); + printf("Close the handle\n"); + led=1; +} \ No newline at end of file