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.
Diff: main.cpp
- Revision:
- 6:892ecb5fcfb9
- Parent:
- 5:603c549bfefa
- Child:
- 7:f7368fed0a2f
--- a/main.cpp Thu Apr 05 15:42:25 2018 +0000
+++ b/main.cpp Tue Apr 10 21:34:08 2018 +0000
@@ -1,14 +1,19 @@
#include "mbed.h"
+#include "ExtendedTimer.h"
#include "SDFileSystem.h"
AnalogIn lightSensor(p20);
DigitalOut ledRed(p25);
DigitalOut ledBlue(p26);
DigitalOut ledError(LED3);
+DigitalOut powerOn(p16);
+DigitalOut sdMount(p15);
//This is our timer
Ticker countClock;
+ExtendedTimer timeClock;
+
SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board
Serial pc(USBTX,USBRX);
@@ -23,34 +28,46 @@
FILE *fp = NULL;
-int main() {
+int main() {
+ powerOn = 1;
+ timeClock.start();
+ sdMount = false;
+ if (sd.mount() != 0) {
+ pc.printf("Failed to mount the SD card.\r\n");
+ sdMount = true;
+ return -1; // ends program with error status
+ }
+
fp = fopen("/sd/mydir/sdtest.txt", "a");
+
if(fp == NULL) {
+ sdMount = true;
+ ledError = true;
error("Could not open file for write\n");
+ return -1;
}
- int checkTimes = 10;
+
+ int checkTimes = 60;
ledRed = true;
ledBlue = false;
-
-
- if(fp == NULL) {
- error("Could not open file for write\n");
- ledError = true;
- }
countClock.attach(&save, 10);
- fprintf(fp,"\n\r\n\r\n\rBlue Light, Red Light\n\r\n\r\n\r");
+ fprintf(fp,"\r\n\r\n\r\n\r\nBlue Light, Time Blue Data Taken, Red Light, Time Red Data Taken\n\r\n\r\n\r");
while(true) {
//Blue Light
ledSwitch();
pc.printf("%.4f, ", checkLightSensor(checkTimes));
+ pc.printf("%.1f, ", timeClock.read());
fprintf(fp,"%.4f, ", checkLightSensor(checkTimes));
- wait(0.2);
+ fprintf(fp,"%.1f, ", timeClock.read());
+ wait(1);
//Red Light
ledSwitch();
- pc.printf("%.4f\r\n", checkLightSensor(checkTimes));
- fprintf(fp,"%.4f\r\n", checkLightSensor(checkTimes));
- wait(0.2);
+ pc.printf("%.4f, ", checkLightSensor(checkTimes));
+ pc.printf("%.1f\r\n ", timeClock.read());
+ fprintf(fp,"%.4f, ", checkLightSensor(checkTimes));
+ fprintf(fp,"%.1f\r\n", timeClock.read());
+ wait(1);
}
}
@@ -71,6 +88,7 @@
void save(){
ledError = true;
+ sdMount = true;
fclose(fp);
fp = fopen("/sd/mydir/sdtest.txt", "a");
if(fp == NULL) {
@@ -79,4 +97,5 @@
}
pc.printf("\n\rSaved\n\r");
ledError = false;
+ sdMount = false;
}
\ No newline at end of file
