Input file name type .csv and use local file system to store data taken from 4 ADC inputs.

Dependencies:   mbed

Fork of LocalFileSystem_HelloWorld by mbed official

Files at this revision

API Documentation at this revision

Comitter:
cvitas
Date:
Wed Oct 16 18:14:15 2013 +0000
Parent:
0:cc465aef98cf
Commit message:
First time ever published

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r cc465aef98cf -r b71192bf4318 main.cpp
--- a/main.cpp	Wed Feb 13 16:36:26 2013 +0000
+++ b/main.cpp	Wed Oct 16 18:14:15 2013 +0000
@@ -1,9 +1,63 @@
 #include "mbed.h"
- 
+
 LocalFileSystem local("local");               // Create the local filesystem under the name "local"
- 
-int main() {
-    FILE *fp = fopen("/local/out.txt", "w");  // Open "out.txt" on the local file system for writing
-    fprintf(fp, "Hello World!");
+DigitalOut myled(LED1);
+AnalogIn AinSensA(p17);
+AnalogIn AinSensB(p18);
+AnalogIn AinSensC(p19);
+AnalogIn AinSensD(p20);
+
+Serial pc(USBTX, USBRX); // comms to host PC
+int ADCdata1, ADCdata2, ADCdata3, ADCdata4;
+char ime[20];
+char staza[20];
+char ekstenzija[20];
+int mjeri;
+int i=0;
+
+int main()
+{
+    while (1){
+    pc.printf("\n\rUpisi ime datoteke\n\r");
+    pc.scanf( " %s", ime);
+    pc.printf("\n\rDatoteka je %s\n\r",ime);
+
+    strcpy(staza,  "/local/");
+    strcpy(ekstenzija,  ".csv");
+
+    strcat(staza,ime);
+    strcat(staza,ekstenzija);
+    //pc.printf("\n\rOdrediste je %s\n\r",staza);
+    mjeri=1;
+    i=0;
+
+    FILE *fp = fopen(staza, "w");  // Open "xxx.cvs" on the local file system for writing
+    while (mjeri==1) {
+        pc.printf("\n\rPodesi polozaj senzora.... Unesi M - mjeri, S - stop\n\r");
+        char c = pc.getc();         // get keyboard data (note numerical ascii range)
+
+        if (c=='s'or c=='S') {
+            mjeri=0;
+        }
+        if (c=='m'or c=='M') {
+            mjeri=1;
+            myled=1;
+            i++;
+            ADCdata1 = AinSensA*1000;
+            ADCdata2 = AinSensB*1000;
+            ADCdata3 = AinSensC*1000;
+            ADCdata4 = AinSensD*1000;
+                        
+            fprintf(fp, "%d ,%d ,%d ,%d , %d\n", ADCdata1,ADCdata2,ADCdata3,ADCdata4, i);
+            printf("\n\rSa %d  Sb %d  Sc %d  Sd %d  zapis br. %d\n\r", ADCdata1, ADCdata2, ADCdata3,ADCdata4, i);
+
+            wait(0.5);
+            myled=0;
+        }
+    }
+
     fclose(fp);
+    myled= 1;
+    pc.printf("\n\rSTOP\n\r");
+    }
 }
\ No newline at end of file