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: mbed MMA8452Q SDFileSystem
Diff: main.cpp
- Revision:
- 0:c654fb06ff86
diff -r 000000000000 -r c654fb06ff86 main.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Sun Dec 23 17:13:49 2018 +0000
@@ -0,0 +1,67 @@
+// Cecilia Schneider
+// OCE 360 Final Project
+
+#include "mbed.h"
+#include "MMA8452Q.h"
+#include "SDFileSystem.h"
+
+// AnalogIn ain(p15); // temp sensor on p15
+DigitalIn switchin(p11); // switch on p11
+
+// Accelerometer
+MMA8452Q accel(p28, p27, 0x1D); // Accelerometer - SDA, SCL, and I2C address
+
+// Serial terminal
+Serial pc(USBTX, USBRX);
+
+// SD card reader
+SDFileSystem sd(p5, p6, p7, p8, "sd");
+
+int main() {
+ // initialize accelerometer
+ accel.init();
+ float x;
+ float y;
+ float z;
+
+ // define and open file
+ FILE *file;
+ file = fopen("/sd/acceldata.txt", "w");
+
+ while(1){
+ if (switchin == 1){ // store data from accelerometer in x, y , z
+ x = accel.readX();
+ y = accel.readY();
+ z = accel.readZ();
+ fprintf(file, "%3.2f %3.2f %3.2f \n\r", x, y, z); // write accelerometer data to file
+ }
+ else ()
+ fclose(file); // close file here
+ file = fopen("/sd/acceldata.txt","r"); // reopen for reading
+ pc.printf("%3.2f %3.2f %3.2f \n\r", x, y, z); // print data to serial terminal
+ pc.printf("TEST");
+ break; // only do this once?
+ }
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+