Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: MAX31855 SDFileSystem mbed
SDSaveFunction.cpp
- Committer:
- JLarkin
- Date:
- 2016-03-17
- Revision:
- 5:a85aa204463b
- Parent:
- 3:9339e7b93415
- Child:
- 6:76e8649a643f
File content as of revision 5:a85aa204463b:
/* Program demonstrating data logging to SD card Analog data is read in (from a potentiometer). The time since program start and the voltage are written to a tab-delimited data file.
*/
#include "mbed.h"
#include "SDFileSystem.h"
#include "SDSaveFunction.h"
//Create an SDFileSystem object
SDFileSystem fs(PTD2, PTD3, PTD1, , "fs");
FILE *fp;
extern Serial pc;
int mountSDCard() {
//Mount the filesystem
int mountFailure = fs.mount();
if (mountFailure != 0) {
pc.printf("Failed to mount the SD card.\n\r");
return -1; // ends function with error status
}
else
return 0;
}
int openDataFile() {
fp = fopen("/fs/dataLog.txt", "w"); // Open file and prepare to write
if (fp == NULL) {
pc.printf("Failed to open file.\n\r");
return -1;
}
// Write a header row
fprintf(fp, "Time (s) \t Voltage (V)\n\r"); // Needs to be modified for your particular experiment
return 0;
}
int closeDateFile() { // Close the file and unmount the file system so the SD card is happy
fclose(fp);
fs.unmount();
pc.printf("It is now safe to remove the memory card.\r\n");
return 0;
}
void writeData(float firstThing, float secondThing) { // Need to modify for your particular experiment
fprintf(fp, "%.2f \t %.2f\n\r", firstThing, secondThing);
}
