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:
- DanielBlomdahl
- Date:
- 2016-04-13
- Revision:
- 9:c97cd10b11ac
- Parent:
- 8:882ccc7bbc8a
File content as of revision 9:c97cd10b11ac:
/* 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(PTE3, PTE1, PTE2, PTE4, "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 Temp1 (C) \t Temp2 (C) \t Voltage (V)\n\r"); // Needs to be modified for your particular experiment
return 0;
}
int closeDataFile() { // 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 time, float temp1, float temp2, float voltage) {
fprintf(fp, "%.2f \t %.2f \t %.2f \t %.2f \n\r", time , temp1 , temp2 , voltage);
}
