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
main.cpp
- Committer:
- Twidmer18
- Date:
- 2016-04-19
- Revision:
- 2:57bffc6f5df3
- Parent:
- 1:34ff3ee532bd
- Child:
- 3:39d578e9ce10
File content as of revision 2:57bffc6f5df3:
#include "mbed.h"
#include "SDFileSystem.h"
SDFileSystem fs(p5, p6, p7, p8, "fs");
Serial pc(USBTX, USBRX);
AnalogIn pot(p16); //Phototransitor Voltage reading
Timer t;
Timer taverage; //Seperate Timer for data average
Ticker sampleTime;
FILE *fileRed;
FILE *filePurple;
bool mountFailure;
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
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);
}
}
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(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(fileRed);
fclose(filePurple);
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()
{
/* 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)
{
sum = sum + pot.read();
taverage.reset();
}
}
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
}
