Final program for the test of the RGB sensor

Dependencies:   ISL29125 SDFileSystem mbed

Committer:
Jeriah
Date:
Fri Mar 11 23:43:27 2016 +0000
Revision:
0:547856de255b
Child:
1:e0fc716e2394
wrote the RGBSensor.h file for RGB_test

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Jeriah 0:547856de255b 1
Jeriah 0:547856de255b 2 #include "SDFileSystem.h"
Jeriah 0:547856de255b 3 #include "mbed.h"
Jeriah 0:547856de255b 4 Serial pc(USBTX, USBRX);
Jeriah 0:547856de255b 5 FILE *fp;
Jeriah 0:547856de255b 6
Jeriah 0:547856de255b 7 void createDataFile() {
Jeriah 0:547856de255b 8 fp = fopen("/fs/dataLog.txt", "a");// open file and prepare to write
Jeriah 0:547856de255b 9 if (fp == NULL) {
Jeriah 0:547856de255b 10 pc.printf("Failed to open the file.\n\r");
Jeriah 0:547856de255b 11 }
Jeriah 0:547856de255b 12 fprintf(fp, "Time (s)\t temperature (c)\t UV (mW/cm2)\t red (mW/cm2)\t green (mW/cm2)\t blue (mW/cm2)");
Jeriah 0:547856de255b 13 }
Jeriah 0:547856de255b 14
Jeriah 0:547856de255b 15 void createDataFile_testRGB() {
Jeriah 0:547856de255b 16 fp = fopen("/fs/dataLog.txt", "a");// open file and prepare to write
Jeriah 0:547856de255b 17 if (fp == NULL) {
Jeriah 0:547856de255b 18 pc.printf("Failed to open the file.\n\r");
Jeriah 0:547856de255b 19 }
Jeriah 0:547856de255b 20 fprint(fp, "Time (s)\t red (mW/cm2)\t green (mW/cm2)\t blue (mW/cm2)");
Jeriah 0:547856de255b 21 }
Jeriah 0:547856de255b 22 void writeData(uint16_t time, uint16_t temp, uint16_t uv, uint16_t red, uint16_t green, uint16_t blue)
Jeriah 0:547856de255b 23 {
Jeriah 0:547856de255b 24 fp = fopen("/fs/dataLog.txt", "w"); //open file and prepare to write
Jeriah 0:547856de255b 25 if (fp == NULL) {
Jeriah 0:547856de255b 26 pc.printf("Failed to open the file.\n\r");
Jeriah 0:547856de255b 27 }
Jeriah 0:547856de255b 28 if(time < .6) {//if it is the first time being called then output data title
Jeriah 0:547856de255b 29 fprint(fp, "Time (s)\t temperature (c)\t UV (mW/cm2)\t red (mW/cm2)\t green (mW/cm2)\t blue (mW/cm2)");
Jeriah 0:547856de255b 30 }
Jeriah 0:547856de255b 31 //output values for each
Jeriah 0:547856de255b 32 fprintf(fp, "%.2f \t %.2f\n\r", time, temp, uv, red, green, blue);
Jeriah 0:547856de255b 33 }
Jeriah 0:547856de255b 34
Jeriah 0:547856de255b 35 void writeData_testRGB(float time, uint16_t red, uint16_t green, uint16_t blue) {
Jeriah 0:547856de255b 36
Jeriah 0:547856de255b 37 //output values for each
Jeriah 0:547856de255b 38 fprintf(fp, "%.2f \t %.2f\n\r", time, temp, uv, red, green, blue);
Jeriah 0:547856de255b 39 }
Jeriah 0:547856de255b 40 bool mountFailure(){
Jeriah 0:547856de255b 41 if (fs.mount !=0) return false;//if mount has been accomplished return false
Jeriah 0:547856de255b 42 //remember to change if statment's true to a correct mount failure input else return true;
Jeriah 0:547856de255b 43 //if mount has failed return true
Jeriah 0:547856de255b 44 }
Jeriah 0:547856de255b 45
Jeriah 0:547856de255b 46 void closeDataFile() {
Jeriah 0:547856de255b 47 fclose(fp);
Jeriah 0:547856de255b 48 sd.unmount();
Jeriah 0:547856de255b 49 }