AES TEAM
/
USBHostMSD_HelloWorld
save data to memory stick
Fork of USBHostMSD_HelloWorld by
main.cpp@9:dadf8d23bcf2, 2015-01-29 (annotated)
- Committer:
- cathal66
- Date:
- Thu Jan 29 17:29:50 2015 +0000
- Revision:
- 9:dadf8d23bcf2
- Parent:
- 4:f8a5c8aa895a
save data to flash disk
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
samux | 0:0d68fe822228 | 1 | #include "mbed.h" |
samux | 0:0d68fe822228 | 2 | #include "USBHostMSD.h" |
samux | 0:0d68fe822228 | 3 | |
samux | 0:0d68fe822228 | 4 | DigitalOut led(LED1); |
samux | 0:0d68fe822228 | 5 | |
cathal66 | 9:dadf8d23bcf2 | 6 | AnalogIn pot1(p19); |
cathal66 | 9:dadf8d23bcf2 | 7 | |
samux | 0:0d68fe822228 | 8 | void msd_task(void const *) { |
samux | 0:0d68fe822228 | 9 | |
samux | 0:0d68fe822228 | 10 | USBHostMSD msd("usb"); |
samux | 0:0d68fe822228 | 11 | |
cathal66 | 9:dadf8d23bcf2 | 12 | |
samux | 0:0d68fe822228 | 13 | |
samux | 1:473f339c54c1 | 14 | // try to connect a MSD device |
samux | 1:473f339c54c1 | 15 | while(!msd.connect()) { |
samux | 1:473f339c54c1 | 16 | Thread::wait(500); |
samux | 1:473f339c54c1 | 17 | } |
cathal66 | 9:dadf8d23bcf2 | 18 | // append a file |
cathal66 | 9:dadf8d23bcf2 | 19 | FILE * fp = fopen("/usb/test.csv", "w"); |
cathal66 | 9:dadf8d23bcf2 | 20 | for (int i=0; i<100; i++) { |
cathal66 | 9:dadf8d23bcf2 | 21 | fprintf(fp,"%.2f\n",pot1.read()); |
samux | 1:473f339c54c1 | 22 | |
cathal66 | 9:dadf8d23bcf2 | 23 | led=!led; |
samux | 1:473f339c54c1 | 24 | } |
cathal66 | 9:dadf8d23bcf2 | 25 | fclose(fp); |
cathal66 | 9:dadf8d23bcf2 | 26 | |
samux | 0:0d68fe822228 | 27 | } |
samux | 0:0d68fe822228 | 28 | |
samux | 0:0d68fe822228 | 29 | |
samux | 0:0d68fe822228 | 30 | int main() { |
samux | 2:3e3df7a79050 | 31 | Thread msdTask(msd_task, NULL, osPriorityNormal, 1024 * 4); |
samux | 0:0d68fe822228 | 32 | while(1) { |
samux | 0:0d68fe822228 | 33 | led=!led; |
samux | 0:0d68fe822228 | 34 | Thread::wait(500); |
samux | 0:0d68fe822228 | 35 | } |
samux | 0:0d68fe822228 | 36 | } |