Final program for the test of the RGB sensor

Dependencies:   ISL29125 SDFileSystem mbed

Committer:
Jeriah
Date:
Sat Mar 12 00:01:03 2016 +0000
Revision:
1:e0fc716e2394
Parent:
0:547856de255b
Child:
2:04c2f253ec87
Final edition of RGB_test program

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 1:e0fc716e2394 6 SDFileSystem fs(PTE3,PTE1,PTE2,PTE4,"fs");//SDFileSystem object
Jeriah 0:547856de255b 7
Jeriah 0:547856de255b 8 void createDataFile() {
Jeriah 0:547856de255b 9 fp = fopen("/fs/dataLog.txt", "a");// open file and prepare to write
Jeriah 0:547856de255b 10 if (fp == NULL) {
Jeriah 0:547856de255b 11 pc.printf("Failed to open the file.\n\r");
Jeriah 0:547856de255b 12 }
Jeriah 0:547856de255b 13 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 14 }
Jeriah 0:547856de255b 15
Jeriah 0:547856de255b 16 void createDataFile_testRGB() {
Jeriah 0:547856de255b 17 fp = fopen("/fs/dataLog.txt", "a");// open file and prepare to write
Jeriah 0:547856de255b 18 if (fp == NULL) {
Jeriah 0:547856de255b 19 pc.printf("Failed to open the file.\n\r");
Jeriah 0:547856de255b 20 }
Jeriah 1:e0fc716e2394 21 fprintf(fp, "Time (s)\t red (mW/cm2)\t green (mW/cm2)\t blue (mW/cm2)");
Jeriah 0:547856de255b 22 }
Jeriah 1:e0fc716e2394 23 void writeData(float time, float temp, float uv, uint16_t red, uint16_t green, uint16_t blue)
Jeriah 0:547856de255b 24 {
Jeriah 1:e0fc716e2394 25 fprintf(fp, "%.2f \t %.2f \t %.2f \t %d \t %d \t %d\n\r", time, temp, uv, red, green, blue);
Jeriah 0:547856de255b 26 }
Jeriah 0:547856de255b 27
Jeriah 0:547856de255b 28 void writeData_testRGB(float time, uint16_t red, uint16_t green, uint16_t blue) {
Jeriah 0:547856de255b 29
Jeriah 0:547856de255b 30 //output values for each
Jeriah 1:e0fc716e2394 31 fprintf(fp, "%.2f \t %d \t %d \t %d\n\r", time, red, green, blue);
Jeriah 0:547856de255b 32 }
Jeriah 1:e0fc716e2394 33
Jeriah 0:547856de255b 34 bool mountFailure(){
Jeriah 1:e0fc716e2394 35 if (fs.mount() !=0)
Jeriah 1:e0fc716e2394 36 return false;//if mount has been accomplished return false
Jeriah 1:e0fc716e2394 37 else
Jeriah 1:e0fc716e2394 38 return true;
Jeriah 0:547856de255b 39 }
Jeriah 0:547856de255b 40
Jeriah 0:547856de255b 41 void closeDataFile() {
Jeriah 0:547856de255b 42 fclose(fp);
Jeriah 1:e0fc716e2394 43 fs.unmount();
Jeriah 0:547856de255b 44 }