LUIZ FILIPE MATTOS / Mbed 2 deprecated DataLoggerV4

Dependencies:   mbed SDFileSystem

Committer:
fisque
Date:
Thu Aug 15 18:12:23 2019 +0000
Revision:
2:aed6b2f07ad8
Parent:
0:bdbd3d6fc5d5
abobrinha;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
fisque 2:aed6b2f07ad8 1 /* Copyright (c) 2010-2011 mbed.org, MIT License
fisque 2:aed6b2f07ad8 2 *
fisque 2:aed6b2f07ad8 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
fisque 2:aed6b2f07ad8 4 * and associated documentation files (the "Software"), to deal in the Software without
fisque 2:aed6b2f07ad8 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
fisque 2:aed6b2f07ad8 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
fisque 2:aed6b2f07ad8 7 * Software is furnished to do so, subject to the following conditions:
fisque 2:aed6b2f07ad8 8 *
fisque 2:aed6b2f07ad8 9 * The above copyright notice and this permission notice shall be included in all copies or
fisque 2:aed6b2f07ad8 10 * substantial portions of the Software.
fisque 2:aed6b2f07ad8 11 *
fisque 2:aed6b2f07ad8 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
fisque 2:aed6b2f07ad8 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
fisque 2:aed6b2f07ad8 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
fisque 2:aed6b2f07ad8 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
fisque 2:aed6b2f07ad8 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
fisque 2:aed6b2f07ad8 17 */
fisque 2:aed6b2f07ad8 18
mbed_official 0:bdbd3d6fc5d5 19 #include "mbed.h"
mbed_official 0:bdbd3d6fc5d5 20 #include "SDFileSystem.h"
mbed_official 0:bdbd3d6fc5d5 21
fisque 2:aed6b2f07ad8 22 Serial pc(USBTX, USBRX);
fisque 2:aed6b2f07ad8 23 SDFileSystem sd(D11, D12, D13, D10, "FR"); // MOSI, MISO, SCK, CS
fisque 2:aed6b2f07ad8 24 FILE *fp;
mbed_official 0:bdbd3d6fc5d5 25
mbed_official 0:bdbd3d6fc5d5 26 int main() {
fisque 2:aed6b2f07ad8 27 wait(2);
fisque 2:aed6b2f07ad8 28 pc.printf("Initializing\r\n");
fisque 2:aed6b2f07ad8 29
fisque 2:aed6b2f07ad8 30 fp = fopen("/FR/hello.txt", "r");
fisque 2:aed6b2f07ad8 31 if (fp != NULL) {
fisque 2:aed6b2f07ad8 32 fclose(fp);
fisque 2:aed6b2f07ad8 33 remove("/FR/hello.txt");
fisque 2:aed6b2f07ad8 34 pc.printf("Remove an existing file with the same name\r\n");
fisque 2:aed6b2f07ad8 35 }
mbed_official 0:bdbd3d6fc5d5 36
fisque 2:aed6b2f07ad8 37 fp = fopen("/FR/hello.txt", "w");
fisque 2:aed6b2f07ad8 38 if (fp == NULL) {
fisque 2:aed6b2f07ad8 39 pc.printf("Unable to write the file\r\n");
fisque 2:aed6b2f07ad8 40 } else {
fisque 2:aed6b2f07ad8 41 fprintf(fp, "FUNCIONOU!!!!");
fisque 2:aed6b2f07ad8 42 fclose(fp);
fisque 2:aed6b2f07ad8 43 pc.printf("File successfully written!\r\n");
mbed_official 0:bdbd3d6fc5d5 44 }
fisque 2:aed6b2f07ad8 45 }