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.
Dependencies: LM19_Driver2 PDV_Driver2 SDFileSystem mbed
main.cpp
00001 #include "mbed.h" 00002 #include "SDFileSystem.h" 00003 #include "LM19_Driver.h" 00004 #include "PDV_Driver.h" 00005 00006 00007 00008 00009 //Lucy Damon- assignment 6- SD card 00010 00011 00012 00013 00014 Serial pc(USBTX, USBRX); 00015 SDFileSystem sd(p5, p6, p7, p8, "sd"); 00016 LM19 t_sensor(p19); 00017 PDV photocell(p20); 00018 00019 Timer print; 00020 00021 Timer log_timer; 00022 00023 00024 00025 int main() 00026 00027 { 00028 00029 int t; 00030 00031 pc.printf("Start Log File\n"); //starrting file 00032 00033 mkdir("/sd/mydir", 0777); 00034 00035 FILE *fp = fopen("/sd/mydir/thm_ptc.txt", "w"); 00036 00037 00038 00039 pc.printf("file_opened \n"); //yay open the file 00040 00041 00042 if(fp == NULL) { 00043 00044 error("Could not open file for write\n"); //booo bad file didnt open 00045 00046 } 00047 00048 fprintf(fp,"Start Log File\n"); 00049 00050 while(1) { //its going to repeat strings 00051 00052 print.start(); 00053 00054 log_timer.start(); 00055 00056 if(log_timer.read()<31) { 00057 if(print.read()>1) { 00058 00059 //temp code gained from LM19 driver 00060 00061 t=log_timer.read_ms(); 00062 pc.printf("$TEMP,1,2,%i,%.3f,%.3f;%\r\n", 00063 00064 t, 00065 00066 t_sensor.volt(), 00067 00068 t_sensor.temp()); 00069 00070 fprintf(fp, "Time = %i, temp=%f, volts=%f\r\n", 00071 t, 00072 00073 t_sensor.volt(), 00074 00075 t_sensor.temp()); 00076 00077 //photocell code from PDV driver 00078 00079 pc.printf("$PDV,1,2,%i,%.3f,%.3f;%\r\n", 00080 00081 t, 00082 00083 photocell.volt(), 00084 00085 photocell.resistance()); 00086 00087 fprintf(fp, "Time = %i, volts=%f, resistance=%f\r\n", 00088 00089 t, 00090 00091 photocell.volt(), 00092 photocell.resistance()); 00093 00094 print.reset(); //reset strings 00095 } 00096 00097 //stuff to print when strings are done/ reached capacity 00098 00099 } else { 00100 fprintf(fp, "Log = Full"); 00101 00102 fclose(fp); 00103 00104 pc.printf("Log = Successful \n"); 00105 00106 wait(1); 00107 00108 } 00109 00110 } 00111 00112 }
Generated on Fri Dec 2 2022 00:24:37 by
1.7.2