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:
- 2:57bffc6f5df3
- Parent:
- 1:34ff3ee532bd
- Child:
- 3:39d578e9ce10
--- a/main.cpp Tue Apr 19 01:59:20 2016 +0000
+++ b/main.cpp Tue Apr 19 03:07:19 2016 +0000
@@ -4,13 +4,14 @@
SDFileSystem fs(p5, p6, p7, p8, "fs");
Serial pc(USBTX, USBRX);
-AnalogIn pot(p16);
+AnalogIn pot(p16); //Phototransitor Voltage reading
Timer t;
Timer taverage; //Seperate Timer for data average
Ticker sampleTime;
-FILE *fp;
+FILE *fileRed;
+FILE *filePurple;
bool mountFailure;
-int test_time = 300; //Length of test in seconds
+int test_time = 10; //Length of test in seconds
void writeData();
DigitalOut led1(LED1); //Mbed LED for SD Card Verification
DigitalOut Red(p17); //Red LED in Pod
@@ -34,25 +35,32 @@
wait (.5);
}
}
- fp = fopen("/fs/dataLog.txt", "w");
- if (fp==NULL)
+ fileRed = fopen("/fs/dataLogRed.txt", "w");
+ filePurple = fopen("/fs/dataLogPurple.txt", "w");
+ if (filePurple==NULL || fileRed==NULL)
{
pc.printf("Failed to open the file.\n\r");
return -1;
}
- fprintf(fp, "Time (s) /t Voltage (V)\n\r");
-
+ fprintf(fileRed, "Time (s) /t Voltage[Red] (V)\n\r");
+ fprintf(filePurple, "Time (s) /t Voltage[Purple] (V)\n\r");
+
t.start();
sampleTime.attach(&writeData, 1);
while (t.read()<test_time)
{
-
-
+ Purple = 1;
+ Red = 0;
+ wait(1);
+ Purple = 0;
+ Red = 1;
+ wait(1);
}
sampleTime.detach();
- fclose(fp);
+ fclose(fileRed);
+ fclose(filePurple);
for (int i=0; i<10; i++) //Signals end of program for lab test purposes
{
led1 = 1;
@@ -64,17 +72,22 @@
void writeData()
{
- float sum = 0;
+ /* double 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)
+ 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
+ double average = sum/10;
+ */
+ if(Red==1)
+ {
+ fprintf(fileRed, "%.2f \t %.4f\n\r", t.read(), 3.3*pot.read()); //Standard file input
+ }
+ else
+ fprintf(filePurple, "%.2f \t %.4f\n\r", t.read(), 3.3*pot.read()); //Standard file input
}
\ No newline at end of file
