Bert

Dependencies:   mbed SDFileSystem AS7265x

Files at this revision

API Documentation at this revision

Comitter:
nthompson22
Date:
Thu Mar 21 15:10:34 2019 +0000
Commit message:
Recording data with BRT printing it to the computer and recording it to an SD card

Changed in this revision

AS7265x.lib Show annotated file Show diff for this revision Revisions of this file
SDFileSystem.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/AS7265x.lib	Thu Mar 21 15:10:34 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/nthompson22/code/AS7265x/#3699cacb5a93
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SDFileSystem.lib	Thu Mar 21 15:10:34 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/neilt6/code/SDFileSystem/#e4d2567200db
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Mar 21 15:10:34 2019 +0000
@@ -0,0 +1,68 @@
+#include <mbed.h>
+#include "AS7265xfunctions.h"
+#include "SDFileSystem.h"
+I2C i2c(p9, p10);
+AS7265x lightSensor(i2c, 0x92);
+SDFileSystem fs(p5, p6, p7, p8, "fs");
+Serial pc(USBTX,USBRX);
+DigitalOut led600(p18);
+DigitalOut led405(p19);
+DigitalOut ledWhite(p20);
+AnalogIn   uvSensor(p17);
+
+int main() {
+        // Mount the filesystem
+    bool mountFailure = fs.mount();
+    if (mountFailure != 0) {
+        pc.printf("Failed to mount the SD card.\r\n");
+        return -1;  // ends program with error status
+    }
+    FILE* fp = fopen("/fs/log.txt","w");
+    if (fp == NULL) {
+        pc.printf("Failed to open the file.\r\n");
+        fs.unmount();
+        return -1;
+    } 
+    // Write a header row 
+    fprintf(fp, "Time (s) \t Light Reading\r\n");
+
+    float dt=2;
+    lightSensor.setBank(2);
+    lightSensor.setGain(3);
+    lightSensor.setAllLeds(0);
+    lightSensor.setIntegTime(711);
+    Timer time;
+    
+    while(time < 45){
+
+        for (int q = 0; q < 4; q++) {
+            switch(q) {
+                case 0: led600 = 1; led405 = 0; ledWhite = 0;
+                pc.printf("Orange LED\r\n");
+                break;
+                case 1: led600 = 0; led405 = 1; ledWhite = 0;
+                pc.printf("Purple LED\r\n");
+                break;
+                case 2: led600 = 0; led405 = 0; ledWhite = 1;
+                pc.printf("White LED\r\n");
+                break;
+                case 3: led600 = 0; led405 = 0; ledWhite = 0;
+                pc.printf("LEDs Off\r\n");
+                break;
+                default: led600 = 1; led405 = 1; ledWhite = 1;
+            }
+            wait(dt);
+            lightSensor.collectData();
+            for (int i = 1; i <19; i++) {
+                fprintf(fp,"%d \t", lightSensor.readData(i));
+                pc.printf("%d \t", lightSensor.readData(i));
+            }
+            fprintf(fp,"\r\n");
+            pc.printf("\r\n");
+            wait(dt);
+        }
+    }
+        // Close the file and unmount the file system so the SD card is happy
+    fclose(fp);
+    fs.unmount();
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Mar 21 15:10:34 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/3a7713b1edbc
\ No newline at end of file