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 SDFileSystem
Diff: main.cpp
- Revision:
- 1:34ff3ee532bd
- Parent:
- 0:b1167ebd51d9
- Child:
- 2:57bffc6f5df3
--- a/main.cpp Thu Mar 03 16:32:10 2016 +0000
+++ b/main.cpp Tue Apr 19 01:59:20 2016 +0000
@@ -0,0 +1,80 @@
+#include "mbed.h"
+#include "SDFileSystem.h"
+
+SDFileSystem fs(p5, p6, p7, p8, "fs");
+
+Serial pc(USBTX, USBRX);
+AnalogIn pot(p16);
+Timer t;
+Timer taverage; //Seperate Timer for data average
+Ticker sampleTime;
+FILE *fp;
+bool mountFailure;
+int test_time = 300; //Length of test in seconds
+void writeData();
+DigitalOut led1(LED1); //Mbed LED for SD Card Verification
+DigitalOut Red(p17); //Red LED in Pod
+DigitalOut Purple(p18); //Purple LED in Pod
+
+int main()
+{
+ mountFailure = fs.mount();
+ if (mountFailure !=0)
+ {
+ pc.printf("Failed to mount the SD card. \n\r");
+ return -1;
+ }
+ else if (mountFailure == 0)
+ {
+ for (int i=0; i<10; i++)
+ {
+ led1 = 1;
+ wait (.5);
+ led1=0;
+ wait (.5);
+ }
+ }
+ fp = fopen("/fs/dataLog.txt", "w");
+ if (fp==NULL)
+ {
+ pc.printf("Failed to open the file.\n\r");
+ return -1;
+ }
+
+ fprintf(fp, "Time (s) /t Voltage (V)\n\r");
+
+ t.start();
+ sampleTime.attach(&writeData, 1);
+
+ while (t.read()<test_time)
+ {
+
+
+ }
+ sampleTime.detach();
+ fclose(fp);
+ for (int i=0; i<10; i++) //Signals end of program for lab test purposes
+ {
+ led1 = 1;
+ wait (.5);
+ led1 = 0;
+ wait (.5);
+ }
+}
+
+void writeData()
+{
+ float sum = 0;
+ for(int i=0;i<10;i++) //Takes 10 data points per second and finds average
+ { //Hoping to avoid the waves created by 60 Hz noise in lab
+ if(taverage.read()>.1)
+ {
+ sum = sum + pot.read();
+ taverage.reset();
+ }
+
+ }
+ float average = sum/10;
+
+ fprintf(fp, "%.2f \t %.4f\n\r", t.read(), 3.3*average); //Standard file input
+}
\ No newline at end of file
