![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Code for measuring the signal with a specified length and sampling rate, and saving it on a SD card.
sdcard.cpp@2:8c5b6522139f, 2017-10-05 (annotated)
- Committer:
- msamadani
- Date:
- Thu Oct 05 17:44:39 2017 +0000
- Revision:
- 2:8c5b6522139f
- Parent:
- 0:c05b00be2229
A version of the code that initializes the SD RAM, activates the codec, measures the signal and saves the signal onto the SD Card.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
msamadani | 0:c05b00be2229 | 1 | #include "sdcard.h" |
msamadani | 0:c05b00be2229 | 2 | #include "MCIFileSystem.h" |
msamadani | 0:c05b00be2229 | 3 | #include "mbed.h" |
msamadani | 0:c05b00be2229 | 4 | #include <string> |
msamadani | 0:c05b00be2229 | 5 | |
msamadani | 0:c05b00be2229 | 6 | |
msamadani | 0:c05b00be2229 | 7 | void saveToSD(float signal[],int sig_length,char const *filename) |
msamadani | 0:c05b00be2229 | 8 | { |
msamadani | 0:c05b00be2229 | 9 | |
msamadani | 0:c05b00be2229 | 10 | printf("Saving to SD card...\n"); |
msamadani | 0:c05b00be2229 | 11 | |
msamadani | 0:c05b00be2229 | 12 | string str_name(filename); |
msamadani | 0:c05b00be2229 | 13 | |
msamadani | 0:c05b00be2229 | 14 | std::string fullname="/mci/"+str_name+".txt"; |
msamadani | 0:c05b00be2229 | 15 | |
msamadani | 0:c05b00be2229 | 16 | MCIFileSystem mcifs("mci", NC); |
msamadani | 0:c05b00be2229 | 17 | FILE* File = fopen(fullname.c_str(),"w"); // open file |
msamadani | 0:c05b00be2229 | 18 | |
msamadani | 0:c05b00be2229 | 19 | for (int i = 0; i < sig_length; i++) { |
msamadani | 0:c05b00be2229 | 20 | |
msamadani | 0:c05b00be2229 | 21 | //fprintf(File,"%f %f %f %f\r\n",acc_signal_f[i],xfilt[i],xAnalytic[i],xEnv[i]); |
msamadani | 0:c05b00be2229 | 22 | fprintf(File,"%f \r\n",signal[i]); |
msamadani | 0:c05b00be2229 | 23 | } |
msamadani | 0:c05b00be2229 | 24 | |
msamadani | 0:c05b00be2229 | 25 | fclose(File); |
msamadani | 0:c05b00be2229 | 26 | printf("Saved to SD card.\n\n"); |
msamadani | 0:c05b00be2229 | 27 | |
msamadani | 0:c05b00be2229 | 28 | } |