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: mbed SDFileSystem
main.cpp
00001 #include "mbed.h" 00002 #include "max6675.h" 00003 #include "max6675_2.h" 00004 #include "max6675_3.h" 00005 #include "max6675_4.h" 00006 #include "SDFileSystem.h" 00007 #include <time.h> 00008 #include <stdio.h> 00009 00010 DigitalOut led_1(LED1); 00011 DigitalOut led_2(LED2); 00012 DigitalOut led_3(LED3); 00013 DigitalOut led_4(LED4); 00014 SPI spi(p11,p12,p13); 00015 max6675 max(spi,p18); 00016 SPI spi_2(p11,p12,p13); 00017 max6675_2 max_2(spi_2,p21); 00018 SPI spi_3(p11,p12,p13); 00019 max6675_3 max_3(spi_3,p22); 00020 SPI spi_4(p11,p12,p13); 00021 max6675_4 max_4(spi_4,p23); 00022 AnalogIn LM61(p15); 00023 SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board 00024 Serial pc(USBTX,USBRX); 00025 DigitalIn swi_1(p24); //p5~p30のどれでも良い 00026 DigitalIn swi_2(p25); //p5~p30のどれでも良い 00027 00028 void led() 00029 { 00030 led_1 = 1; 00031 led_2 = 1; 00032 led_3 = 1; 00033 led_4 = 1; 00034 wait(.2); 00035 00036 led_1 = 0; 00037 led_2 = 0; 00038 led_3 = 0; 00039 led_4 = 0; 00040 wait(.2); 00041 00042 led_1 = 1; 00043 led_2 = 1; 00044 led_3 = 1; 00045 led_4 = 1; 00046 wait(.2); 00047 00048 led_1 = 0; 00049 led_2 = 0; 00050 led_3 = 0; 00051 led_4 = 0; 00052 wait(.2); 00053 } 00054 00055 00056 int main() { 00057 int r = 5; //平均する値の個数 00058 double w_h = .25; //加熱waitの時間 00059 double w_c = .25; //冷却waitの時間 00060 clock_t start_h; 00061 clock_t start_c; 00062 float tempC, sum, sum_2, sum_3, sum_4, ave, ave_2, ave_3, ave_4; 00063 int i, j, k, l; //平均化処理に使用 00064 swi_1.mode(PullUp); 00065 swi_2.mode(PullUp); 00066 00067 mkdir("/sd/mydir", 0777); 00068 printf("test start!\n"); 00069 FILE *fp = fopen("/sd/mydir/test_heating.csv", "a"); 00070 if(fp == NULL) 00071 { error("Could not open file for write\n"); 00072 } 00073 00074 fprintf(fp, "t,T_1,T_2,T_3,T_4,tempC\n"); 00075 fclose(fp); 00076 /*FILE *fp =*/ fopen("/sd/mydir/test_cooling.csv", "a"); 00077 if(fp == NULL) 00078 { error("Could not open file for write\n"); 00079 } 00080 00081 fprintf(fp, "t,T_1,T_2,T_3,T_4,tempC\n"); 00082 fclose(fp); 00083 00084 00085 if( swi_1 == 1 && swi_2 == 0 ) //スイッチをマイコンのUSBと逆方向に倒したとき 00086 { 00087 printf("\n\n\nheating start\n\n\n"); 00088 00089 led(); 00090 00091 while (1) 00092 { 00093 start_h = clock(); 00094 printf("%f\n", (double)start_h/CLOCKS_PER_SEC); 00095 00096 max.select(); 00097 max_2.deselect_2(); 00098 max_3.deselect_3(); 00099 max_4.deselect_4(); 00100 00101 //平均化処理 00102 00103 sum = 0; 00104 ave = 0; 00105 i = 0; 00106 for( i = 0; i < r; i++) 00107 { 00108 float temp = max.read_temp(); 00109 sum += temp; 00110 } 00111 00112 ave = sum / r; 00113 printf("\n\rT: %f",ave ); 00114 00115 00116 00117 max.deselect(); 00118 max_2.select_2(); 00119 max_3.deselect_3(); 00120 max_4.deselect_4(); 00121 00122 //平均化処理 00123 sum_2 = 0; 00124 ave_2 = 0; 00125 j = 0; 00126 for( j = 0; j < r; j++) 00127 { 00128 float temp_2 = max_2.read_temp_2(); 00129 sum_2 += temp_2; 00130 } 00131 00132 ave_2 = sum_2 / r; 00133 printf("\n\rT: %f",ave_2 ); 00134 00135 00136 00137 max.deselect(); 00138 max_2.deselect_2(); 00139 max_3.select_3(); 00140 max_4.deselect_4(); 00141 00142 //平均化処理 00143 sum_3 = 0; 00144 ave_3 = 0; 00145 k = 0; 00146 for( k = 0; k < r; k++) 00147 { 00148 float temp_3 = max_3.read_temp_3(); 00149 sum_3 += temp_3; 00150 } 00151 00152 ave_3 = sum_3 / r; 00153 printf("\n\rT: %f",ave_3 ); 00154 00155 00156 00157 max.deselect(); 00158 max_2.deselect_2(); 00159 max_3.deselect_3(); 00160 max_4.select_4(); 00161 00162 //平均化処理 00163 sum_4 = 0; 00164 ave_4 =0; 00165 l = 0; 00166 for( l = 0; l < r; l++) 00167 { 00168 float temp_4 = max_4.read_temp_4(); 00169 sum_4 += temp_4; 00170 } 00171 00172 ave_4 = sum_4 / r; 00173 printf("\n\rT: %f",ave_4 ); 00174 00175 //conversion to degrees C - from sensor output voltage per LM61 data sheet 00176 tempC = ((LM61*3.3)-0.600)*100.0; 00177 00178 printf("\nC: %5.2F \n\n\n\r", tempC); 00179 00180 /*FILE *fp =*/ fopen("/sd/mydir/test_heating.csv", "a"); 00181 if(fp == NULL) 00182 { error("Could not open file for write\n"); 00183 } 00184 00185 fprintf(fp, "%f,%f,%f,%f,%f,%f\n",(double)start_h/CLOCKS_PER_SEC, ave, ave_2, ave_3,ave_4, tempC); 00186 fclose(fp); 00187 wait(w_h); 00188 }//while_h 00189 00190 }//if_h 00191 00192 00193 if( swi_1 == 0 && swi_2 == 1 ) //スイッチをマイコンのUSBの方向に倒したとき 00194 { 00195 printf("\n\n\ncolling start\n\n\n"); 00196 00197 led(); 00198 00199 while (1) 00200 { 00201 start_c = clock(); 00202 printf("%f\n", (double)start_c/CLOCKS_PER_SEC); 00203 // double sum_time = start_h/CLOCKS_PER_SEC + start_c/CLOCKS_PER_SEC; 00204 // printf("%f\n", sum_time); 00205 00206 00207 00208 max.select(); 00209 max_2.deselect_2(); 00210 max_3.deselect_3(); 00211 max_4.deselect_4(); 00212 00213 //平均化処理 00214 00215 sum = 0; 00216 ave = 0; 00217 i = 0; 00218 for( i = 0; i < r; i++) 00219 { 00220 float temp = max.read_temp(); 00221 sum += temp; 00222 } 00223 00224 ave = sum / r; 00225 printf("\n\rT: %f",ave ); 00226 00227 00228 00229 00230 max.deselect(); 00231 max_2.select_2(); 00232 max_3.deselect_3(); 00233 max_4.deselect_4(); 00234 00235 //平均化処理 00236 sum_2 = 0; 00237 ave_2 = 0; 00238 j = 0; 00239 for( j = 0; j < r; j++) 00240 { 00241 float temp_2 = max_2.read_temp_2(); 00242 sum_2 += temp_2; 00243 } 00244 00245 ave_2 = sum_2 / r; 00246 printf("\n\rT: %f",ave_2 ); 00247 00248 00249 00250 max.deselect(); 00251 max_2.deselect_2(); 00252 max_3.select_3(); 00253 max_4.deselect_4(); 00254 00255 //平均化処理 00256 sum_3 = 0; 00257 ave_3 = 0; 00258 k = 0; 00259 for( k = 0; k < r; k++) 00260 { 00261 float temp_3 = max_3.read_temp_3(); 00262 sum_3 += temp_3; 00263 } 00264 00265 ave_3 = sum_3 / r; 00266 printf("\n\rT: %f",ave_3 ); 00267 00268 00269 00270 max.deselect(); 00271 max_2.deselect_2(); 00272 max_3.deselect_3(); 00273 max_4.select_4(); 00274 00275 //平均化処理 00276 sum_4 = 0; 00277 ave_4 = 0; 00278 l = 0; 00279 for( l = 0; l < r; l++) 00280 { 00281 float temp_4 = max_4.read_temp_4(); 00282 sum_4 += temp_4; 00283 } 00284 00285 ave_4 = sum_4 / r; 00286 printf("\n\rT: %f",ave_4 ); 00287 00288 //conversion to degrees C - from sensor output voltage per LM61 data sheet 00289 tempC = ((LM61*3.3)-0.600)*100.0; 00290 00291 printf("\nC: %5.2F \n\n\n\r", tempC); 00292 00293 /*FILE *fp = */fopen("/sd/mydir/test_cooling.csv", "a"); 00294 if(fp == NULL) 00295 { error("Could not open file for write\n"); 00296 } 00297 00298 fprintf(fp, "%f,%f,%f,%f,%f,%f\n",(double)start_c/CLOCKS_PER_SEC, ave, ave_2, ave_3,ave_4, tempC); 00299 fclose(fp); 00300 wait(w_c); 00301 }//while_c 00302 00303 }//if_c 00304 00305 00306 if( swi_1 == 1 && swi_2 == 1 ) // スイッチを倒さない時(真ん中の時) 00307 { 00308 led(); 00309 printf("\n\n\nsotp\n\n\n"); 00310 } 00311 00312 } //main() 00313
Generated on Sat Jul 16 2022 20:46:36 by
1.7.2