![](/media/cache/profiles/3ec0e2c7f4536e7ce9e9ce183b1de9e8.jpg.50x50_q85.jpg)
RAMDisk example for the USBFileSystem
Dependencies: mbed USBFileSystem
Fork of USBFileSystem_RAMDISK_HelloWorld by
main.cpp
- Committer:
- Sissors
- Date:
- 2013-08-04
- Revision:
- 2:1c8a3c4ba703
- Parent:
- 1:e1b0157ce547
- Child:
- 3:fc1bfb25b644
File content as of revision 2:1c8a3c4ba703:
/* This program is based on Richard Green's RAM_DISK program for the KL25Z So all hail the Hypnotoad!!!! (And Richard Green, but only after the Hypnotoad) */ #include "mbed.h" #include "USBMSD_Ram.h" DigitalOut myled(LED1); USBMSD_Ram ram; void usbCallback(bool available) { if (available) { FILE *fp = fopen("/USB/IN.txt", "r"); char buffer[100]; fgets (buffer, 100, fp); printf("%s\r\n", buffer); fclose(fp); } } int main() { ram.attachUSB(&usbCallback); wait(0.1); printf("Hello World!\r\n"); //Connect USB ram.connect(); ram.usbMode(1); //Disconnect USB when files are locally written FILE* fp; char buffer[101]; printf("Type your text here! (100 max length)\n"); while(1) { gets(buffer); myled = !myled; //Open file for write, keep trying until we succeed //This is needed because if USB happens to be writing it will fail while(1) { fp = fopen("/USB/OUT.txt", "w"); if (fp != NULL) break; } fprintf(fp, buffer); fclose(fp); } }