Bert

Dependencies:   mbed SDFileSystem AS7265x

Committer:
nthompson22
Date:
Thu Mar 21 15:10:34 2019 +0000
Revision:
0:3fa980238917
Recording data with BRT printing it to the computer and recording it to an SD card

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nthompson22 0:3fa980238917 1 #include <mbed.h>
nthompson22 0:3fa980238917 2 #include "AS7265xfunctions.h"
nthompson22 0:3fa980238917 3 #include "SDFileSystem.h"
nthompson22 0:3fa980238917 4 I2C i2c(p9, p10);
nthompson22 0:3fa980238917 5 AS7265x lightSensor(i2c, 0x92);
nthompson22 0:3fa980238917 6 SDFileSystem fs(p5, p6, p7, p8, "fs");
nthompson22 0:3fa980238917 7 Serial pc(USBTX,USBRX);
nthompson22 0:3fa980238917 8 DigitalOut led600(p18);
nthompson22 0:3fa980238917 9 DigitalOut led405(p19);
nthompson22 0:3fa980238917 10 DigitalOut ledWhite(p20);
nthompson22 0:3fa980238917 11 AnalogIn uvSensor(p17);
nthompson22 0:3fa980238917 12
nthompson22 0:3fa980238917 13 int main() {
nthompson22 0:3fa980238917 14 // Mount the filesystem
nthompson22 0:3fa980238917 15 bool mountFailure = fs.mount();
nthompson22 0:3fa980238917 16 if (mountFailure != 0) {
nthompson22 0:3fa980238917 17 pc.printf("Failed to mount the SD card.\r\n");
nthompson22 0:3fa980238917 18 return -1; // ends program with error status
nthompson22 0:3fa980238917 19 }
nthompson22 0:3fa980238917 20 FILE* fp = fopen("/fs/log.txt","w");
nthompson22 0:3fa980238917 21 if (fp == NULL) {
nthompson22 0:3fa980238917 22 pc.printf("Failed to open the file.\r\n");
nthompson22 0:3fa980238917 23 fs.unmount();
nthompson22 0:3fa980238917 24 return -1;
nthompson22 0:3fa980238917 25 }
nthompson22 0:3fa980238917 26 // Write a header row
nthompson22 0:3fa980238917 27 fprintf(fp, "Time (s) \t Light Reading\r\n");
nthompson22 0:3fa980238917 28
nthompson22 0:3fa980238917 29 float dt=2;
nthompson22 0:3fa980238917 30 lightSensor.setBank(2);
nthompson22 0:3fa980238917 31 lightSensor.setGain(3);
nthompson22 0:3fa980238917 32 lightSensor.setAllLeds(0);
nthompson22 0:3fa980238917 33 lightSensor.setIntegTime(711);
nthompson22 0:3fa980238917 34 Timer time;
nthompson22 0:3fa980238917 35
nthompson22 0:3fa980238917 36 while(time < 45){
nthompson22 0:3fa980238917 37
nthompson22 0:3fa980238917 38 for (int q = 0; q < 4; q++) {
nthompson22 0:3fa980238917 39 switch(q) {
nthompson22 0:3fa980238917 40 case 0: led600 = 1; led405 = 0; ledWhite = 0;
nthompson22 0:3fa980238917 41 pc.printf("Orange LED\r\n");
nthompson22 0:3fa980238917 42 break;
nthompson22 0:3fa980238917 43 case 1: led600 = 0; led405 = 1; ledWhite = 0;
nthompson22 0:3fa980238917 44 pc.printf("Purple LED\r\n");
nthompson22 0:3fa980238917 45 break;
nthompson22 0:3fa980238917 46 case 2: led600 = 0; led405 = 0; ledWhite = 1;
nthompson22 0:3fa980238917 47 pc.printf("White LED\r\n");
nthompson22 0:3fa980238917 48 break;
nthompson22 0:3fa980238917 49 case 3: led600 = 0; led405 = 0; ledWhite = 0;
nthompson22 0:3fa980238917 50 pc.printf("LEDs Off\r\n");
nthompson22 0:3fa980238917 51 break;
nthompson22 0:3fa980238917 52 default: led600 = 1; led405 = 1; ledWhite = 1;
nthompson22 0:3fa980238917 53 }
nthompson22 0:3fa980238917 54 wait(dt);
nthompson22 0:3fa980238917 55 lightSensor.collectData();
nthompson22 0:3fa980238917 56 for (int i = 1; i <19; i++) {
nthompson22 0:3fa980238917 57 fprintf(fp,"%d \t", lightSensor.readData(i));
nthompson22 0:3fa980238917 58 pc.printf("%d \t", lightSensor.readData(i));
nthompson22 0:3fa980238917 59 }
nthompson22 0:3fa980238917 60 fprintf(fp,"\r\n");
nthompson22 0:3fa980238917 61 pc.printf("\r\n");
nthompson22 0:3fa980238917 62 wait(dt);
nthompson22 0:3fa980238917 63 }
nthompson22 0:3fa980238917 64 }
nthompson22 0:3fa980238917 65 // Close the file and unmount the file system so the SD card is happy
nthompson22 0:3fa980238917 66 fclose(fp);
nthompson22 0:3fa980238917 67 fs.unmount();
nthompson22 0:3fa980238917 68 }