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: SDFileSystem mbed
Fork of wmx_laser by
main.cpp
- Committer:
- Dennis_Yu
- Date:
- 2018-09-07
- Revision:
- 8:edb685e9d93e
- Parent:
- 6:48c44bebe8fb
- Child:
- 10:40d607be2e87
File content as of revision 8:edb685e9d93e:
#include "mbed.h"
#include <math.h>
#include <cstring>
#include <stdlib.h>
#include "SDFileSystem.h"
Serial pc(PA_9, PA_10);
//Serial serial(PA_2, PA_3);
char fileName[64];
char buff[1024];
FILE * fp_open;
// mosi, miso, sclk, cs, name
SDFileSystem sd(PB_15, PB_14, PB_13, PB_12, "sd");
void getFileName ()
{
pc.printf("type in a file name:\r\n");
pc.scanf("%s", fileName);
pc.printf("got file name:%s\r\n", fileName);
}
void readFile(char * name)
{
fp_open = fopen(name, "r");
pc.printf("reading\r\n");
for (int i = 0; fscanf(fp_open, "(%s)", buff) == 1; i++)
{
pc.printf("(%s)\r\n", buff);
}
pc.printf("read done.\r\n");
}
void writeFile(char * name)
{
int a = 0,
b = 0,
c = 0;
fp_open = fopen(name, "w");
pc.printf("writing\r\n");
pc.printf("type in data(use '0 0 0' to end)\r\n");
while(1)
{
pc.scanf("%d %d %d", &a, &b, &c);
if (a == 0 && b == 0 && c == 0)
break;
else
{
pc.printf("writing data: (%d,%d,%d)\r\n", a, b, c);
fprintf(fp_open, "(%d,%d,%d)", a, b, c);
}
}
fclose(fp_open);
pc.printf("write done.\r\n");
}
int main ()
{
pc.baud(115200);
pc.printf("hello\r\n");
getFileName();
writeFile(fileName);
readFile(fileName);
}
