for high school student

Dependencies:   SDFileSystem esp8266 mbed easyStepper laser

Files at this revision

API Documentation at this revision

Comitter:
Dennis_Yu
Date:
Tue Oct 16 06:43:01 2018 +0000
Parent:
0:d0e61fbedf82
Commit message:
add a laser library

Changed in this revision

Example_for_learning.cpp Show annotated file Show diff for this revision Revisions of this file
laser.lib Show annotated file Show diff for this revision Revisions of this file
--- a/Example_for_learning.cpp	Fri Sep 14 08:37:48 2018 +0000
+++ b/Example_for_learning.cpp	Tue Oct 16 06:43:01 2018 +0000
@@ -1,18 +1,43 @@
-#include <math.h>
-#include <cstring>
-#include <stdlib.h>
+#include <string>
+#include <vector>
 
 #include "mbed.h"
 #include "SDFileSystem.h"
 #include "esp8266.h"
 #include "stepper.h"
+#include "laser.h"
 
-Serial ser2usb(PA_9, PA_10);
+Serial ser2usb(PA_9, PA_10, 115200);
+
+
+//.....assumes SDFileSystem is setup in earlier code for device "/sd"
+
 
-char filename[80];
+void read_file_names(char *dir, vector<string> & filenames)
+{
+    DIR *dp;
+    struct dirent *dirp;
+    dp = opendir(dir);
+    //read all directory and file names in current directory into filename vector
+    while((dirp = readdir(dp)) != NULL) {
+        filenames.push_back(string(dirp->d_name));
+    }
+    closedir(dp);
+}
+
+
 
 int main()
 {
-    ser2usb.baud(11520);
-    strcpy("write.cpp", filename);
-}
+    ser2usb.printf("hello\r\n");
+    //....example call in your "main" code somewhere.....
+    vector<string> filenames; 
+    //filenames are stored in a vector string
+
+    // read file names into vector of strings
+    read_file_names("/sd", filenames);
+    // print filename strings from vector using an iterator
+    for(vector<string>::iterator it=filenames.begin(); it < filenames.end(); it++) {
+        ser2usb.printf("%s\n\r",(*it).c_str());
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/laser.lib	Tue Oct 16 06:43:01 2018 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/Dennis_Yu/code/laser/#9cfdf3c372b5