1

Dependencies:   MMA8451Q SDFileSystemv2 TSI mbed

Files at this revision

API Documentation at this revision

Comitter:
iLyngklip
Date:
Wed Nov 25 08:53:40 2015 +0000
Commit message:
v1

Changed in this revision

MMA8451Q.lib Show annotated file Show diff for this revision Revisions of this file
SDFileSystem.lib Show annotated file Show diff for this revision Revisions of this file
TSI.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r e12892d110bd MMA8451Q.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MMA8451Q.lib	Wed Nov 25 08:53:40 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/emilmont/code/MMA8451Q/#c4d879a39775
diff -r 000000000000 -r e12892d110bd SDFileSystem.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SDFileSystem.lib	Wed Nov 25 08:53:40 2015 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/iLyngklip/code/SDFileSystemv2/#7e57976a47d8
diff -r 000000000000 -r e12892d110bd TSI.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TSI.lib	Wed Nov 25 08:53:40 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/TSI/#1a60ef257879
diff -r 000000000000 -r e12892d110bd main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Nov 25 08:53:40 2015 +0000
@@ -0,0 +1,123 @@
+//  #########################################################
+//  Includes                                                # 
+//  #########################################################
+#include "mbed.h"               // Mbed library
+#include "SDFileSystem.h"       // SD Libary
+#include "MMA8451Q.h"           // Built-in Accelerometer Libary
+#include "TSISensor.h"          // Built-in Touch-sensor Libary
+
+//  #########################################################
+//  Define settings                                         # 
+//  #########################################################
+#define SD_CARD 1
+
+//  #########################################################
+//  Adresses for talking to the I2C sensors                 # 
+//  #########################################################
+#define MMA8451_I2C_ADDRESS   (0x1d<<1)     // Accelerometer
+
+
+//  #########################################################
+//  Constructors                                            #
+//  #########################################################
+MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS);            // Built-in Accelerometer
+SDFileSystem sd(PTD2, PTD3, PTD1, PTD0, "sd");              // the pinout on the mbed Cool Components workshop board
+Serial pc(USBTX, USBRX);                                    // Serial w/ PC through wire
+TSISensor tsi; //-------------------------------------------// TouchSensor på Mbed'en 
+
+
+//  #########################################################
+//  Global Variables                                        #
+//  #########################################################
+int fileOpen = 0;
+char fileName[23] = "/sd/mydir/LOGGER00.CSV";
+int T1 = 0;
+int T2 = 0;
+
+
+
+
+
+
+int main(){
+    
+    
+pc.baud(9600);
+Timer t;
+
+
+T1 = tsi.readDistance(); 
+
+// ----------------------------------------------------------
+// Setup part - This only runs ONCE
+// ----------------------------------------------------------
+    t.start();
+    t.reset();
+    #if SD_CARD
+    mkdir("/sd/mydir", 0777); // Making the folder in where to put the file
+    int i = 1;
+    nameFinder:
+    fileName[18] = '.';                 // Making the dot in .CSV
+    fileName[17] = i%10 + '0';          // Numbering the filename
+    fileName[16] = i/10 + '0';          // to something not already there
+    i++;
+    FILE *fp = fopen(fileName, "r" );   // This checks if there is a file called fileName
+    if(fp != NULL){
+        printf("Going to namefinder %i \n", i);
+        goto nameFinder;
+    }
+    
+    if(fp == NULL){    
+        printf("Wuhu");    
+        fp = fopen(fileName, "w" ); // This creates a file called fileName
+        if(fp == NULL){
+            printf("\nFAILED\n");
+            error("failed");
+            }
+    }
+    #endif
+    
+    
+    
+        #if SD_CARD
+    fprintf(fp, "X,Y,Z,Altitude,Temperature \n");        // Prints a header telling Excel what sort of information is in which place
+
+
+    fprintf(fp, "Hej, Hej, BOV \n");
+    
+
+    #endif
+    
+    
+// ----------------------------------------------------------
+// Loop part - This runs AFTER setup
+// ----------------------------------------------------------
+    while(1){
+        /*
+        float XYZ[3];
+        acc.getAccAllAxis(XYZ);
+    
+        for(int i = 0; i < 3; i++){
+            printf("XYZ[%i]: %f", i, XYZ[i]);
+        };
+        */
+        float x = 0;
+        float y = 0;
+        float z = 0;
+        x = acc.getAccX();   //
+        y = acc.getAccY();   //-> Getting accelerometer-information
+        z = acc.getAccZ();   //
+        fprintf(fp, "%f, %f, %f, %f \n", x, y, z,t.read());
+        printf("X: %f\t  Y: %f\t  Z: %f \n", x, y, z);
+        
+        T2 = tsi.readDistance();
+        if(T2-T1 > 0.5){
+            break;         // Makes the loop stop.
+        }    
+        
+        wait(0.01);
+    }// while
+
+    fclose(fp); // Closes the SD card. Do this after every write
+
+}// main
diff -r 000000000000 -r e12892d110bd mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Nov 25 08:53:40 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/0b3ab51c8877
\ No newline at end of file