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
Revision 0:d68d5418c985, committed 2020-03-19
- Comitter:
- BoostNori
- Date:
- Thu Mar 19 04:45:23 2020 +0000
- Commit message:
- a
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SDFileSystem.lib Thu Mar 19 04:45:23 2020 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/SDFileSystem/#8db0d3b02cec
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Mar 19 04:45:23 2020 +0000 @@ -0,0 +1,313 @@ +#include "mbed.h" +#include "max6675.h" +#include "max6675_2.h" +#include "max6675_3.h" +#include "max6675_4.h" +#include "SDFileSystem.h" +#include <time.h> +#include <stdio.h> + +DigitalOut led_1(LED1); +DigitalOut led_2(LED2); +DigitalOut led_3(LED3); +DigitalOut led_4(LED4); +SPI spi(p11,p12,p13); +max6675 max(spi,p18); +SPI spi_2(p11,p12,p13); +max6675_2 max_2(spi_2,p21); +SPI spi_3(p11,p12,p13); +max6675_3 max_3(spi_3,p22); +SPI spi_4(p11,p12,p13); +max6675_4 max_4(spi_4,p23); +AnalogIn LM61(p15); +SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board +Serial pc(USBTX,USBRX); +DigitalIn swi_1(p24); //p5~p30のどれでも良い +DigitalIn swi_2(p25); //p5~p30のどれでも良い + +void led() +{ + led_1 = 1; + led_2 = 1; + led_3 = 1; + led_4 = 1; + wait(.2); + + led_1 = 0; + led_2 = 0; + led_3 = 0; + led_4 = 0; + wait(.2); + + led_1 = 1; + led_2 = 1; + led_3 = 1; + led_4 = 1; + wait(.2); + + led_1 = 0; + led_2 = 0; + led_3 = 0; + led_4 = 0; + wait(.2); +} + + +int main() { + int r = 5; //平均する値の個数 + double w_h = .25; //加熱waitの時間 + double w_c = .25; //冷却waitの時間 + clock_t start_h; + clock_t start_c; + float tempC, sum, sum_2, sum_3, sum_4, ave, ave_2, ave_3, ave_4; + int i, j, k, l; //平均化処理に使用 + swi_1.mode(PullUp); + swi_2.mode(PullUp); + + mkdir("/sd/mydir", 0777); + printf("test start!\n"); + FILE *fp = fopen("/sd/mydir/test_heating.csv", "a"); + if(fp == NULL) + { error("Could not open file for write\n"); + } + + fprintf(fp, "t,T_1,T_2,T_3,T_4,tempC\n"); + fclose(fp); + /*FILE *fp =*/ fopen("/sd/mydir/test_cooling.csv", "a"); + if(fp == NULL) + { error("Could not open file for write\n"); + } + + fprintf(fp, "t,T_1,T_2,T_3,T_4,tempC\n"); + fclose(fp); + + + if( swi_1 == 1 && swi_2 == 0 ) //スイッチをマイコンのUSBと逆方向に倒したとき + { + printf("\n\n\nheating start\n\n\n"); + + led(); + + while (1) + { + start_h = clock(); + printf("%f\n", (double)start_h/CLOCKS_PER_SEC); + + max.select(); + max_2.deselect_2(); + max_3.deselect_3(); + max_4.deselect_4(); + + //平均化処理 + + sum = 0; + ave = 0; + i = 0; + for( i = 0; i < r; i++) + { + float temp = max.read_temp(); + sum += temp; + } + + ave = sum / r; + printf("\n\rT: %f",ave ); + + + + max.deselect(); + max_2.select_2(); + max_3.deselect_3(); + max_4.deselect_4(); + + //平均化処理 + sum_2 = 0; + ave_2 = 0; + j = 0; + for( j = 0; j < r; j++) + { + float temp_2 = max_2.read_temp_2(); + sum_2 += temp_2; + } + + ave_2 = sum_2 / r; + printf("\n\rT: %f",ave_2 ); + + + + max.deselect(); + max_2.deselect_2(); + max_3.select_3(); + max_4.deselect_4(); + + //平均化処理 + sum_3 = 0; + ave_3 = 0; + k = 0; + for( k = 0; k < r; k++) + { + float temp_3 = max_3.read_temp_3(); + sum_3 += temp_3; + } + + ave_3 = sum_3 / r; + printf("\n\rT: %f",ave_3 ); + + + + max.deselect(); + max_2.deselect_2(); + max_3.deselect_3(); + max_4.select_4(); + + //平均化処理 + sum_4 = 0; + ave_4 =0; + l = 0; + for( l = 0; l < r; l++) + { + float temp_4 = max_4.read_temp_4(); + sum_4 += temp_4; + } + + ave_4 = sum_4 / r; + printf("\n\rT: %f",ave_4 ); + + //conversion to degrees C - from sensor output voltage per LM61 data sheet + tempC = ((LM61*3.3)-0.600)*100.0; + + printf("\nC: %5.2F \n\n\n\r", tempC); + + /*FILE *fp =*/ fopen("/sd/mydir/test_heating.csv", "a"); + if(fp == NULL) + { error("Could not open file for write\n"); + } + + fprintf(fp, "%f,%f,%f,%f,%f,%f\n",(double)start_h/CLOCKS_PER_SEC, ave, ave_2, ave_3,ave_4, tempC); + fclose(fp); + wait(w_h); + }//while_h + + }//if_h + + + if( swi_1 == 0 && swi_2 == 1 ) //スイッチをマイコンのUSBの方向に倒したとき + { + printf("\n\n\ncolling start\n\n\n"); + + led(); + + while (1) + { + start_c = clock(); + printf("%f\n", (double)start_c/CLOCKS_PER_SEC); + // double sum_time = start_h/CLOCKS_PER_SEC + start_c/CLOCKS_PER_SEC; + // printf("%f\n", sum_time); + + + + max.select(); + max_2.deselect_2(); + max_3.deselect_3(); + max_4.deselect_4(); + + //平均化処理 + + sum = 0; + ave = 0; + i = 0; + for( i = 0; i < r; i++) + { + float temp = max.read_temp(); + sum += temp; + } + + ave = sum / r; + printf("\n\rT: %f",ave ); + + + + + max.deselect(); + max_2.select_2(); + max_3.deselect_3(); + max_4.deselect_4(); + + //平均化処理 + sum_2 = 0; + ave_2 = 0; + j = 0; + for( j = 0; j < r; j++) + { + float temp_2 = max_2.read_temp_2(); + sum_2 += temp_2; + } + + ave_2 = sum_2 / r; + printf("\n\rT: %f",ave_2 ); + + + + max.deselect(); + max_2.deselect_2(); + max_3.select_3(); + max_4.deselect_4(); + + //平均化処理 + sum_3 = 0; + ave_3 = 0; + k = 0; + for( k = 0; k < r; k++) + { + float temp_3 = max_3.read_temp_3(); + sum_3 += temp_3; + } + + ave_3 = sum_3 / r; + printf("\n\rT: %f",ave_3 ); + + + + max.deselect(); + max_2.deselect_2(); + max_3.deselect_3(); + max_4.select_4(); + + //平均化処理 + sum_4 = 0; + ave_4 = 0; + l = 0; + for( l = 0; l < r; l++) + { + float temp_4 = max_4.read_temp_4(); + sum_4 += temp_4; + } + + ave_4 = sum_4 / r; + printf("\n\rT: %f",ave_4 ); + + //conversion to degrees C - from sensor output voltage per LM61 data sheet + tempC = ((LM61*3.3)-0.600)*100.0; + + printf("\nC: %5.2F \n\n\n\r", tempC); + + /*FILE *fp = */fopen("/sd/mydir/test_cooling.csv", "a"); + if(fp == NULL) + { error("Could not open file for write\n"); + } + + fprintf(fp, "%f,%f,%f,%f,%f,%f\n",(double)start_c/CLOCKS_PER_SEC, ave, ave_2, ave_3,ave_4, tempC); + fclose(fp); + wait(w_c); + }//while_c + + }//if_c + + + if( swi_1 == 1 && swi_2 == 1 ) // スイッチを倒さない時(真ん中の時) + { + led(); + printf("\n\n\nsotp\n\n\n"); + } + +} //main() +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/max6675.cpp Thu Mar 19 04:45:23 2020 +0000 @@ -0,0 +1,42 @@ + +#include <mbed.h> +#include "max6675.h" + +max6675::max6675(SPI& _spi, PinName _ncs) : spi(_spi), ncs(_ncs) { + +} + +float max6675::read_temp() { + short value = 0; + float temp = 0; + + uint8_t highByte=0; + uint8_t lowByte=0; + + select(); + wait(.25); //This delay is needed else it does'nt seem to update the temp + + highByte = spi.write(0); + lowByte = spi.write(0); + deselect(); + + + if (lowByte & (1<<2)) { + error("No Probe"); + } else { + value = (highByte << 5 | lowByte>>3); + } + + temp = (value*0.25); // Multiply the value by 0.25 to get temp in ˚C or + // * (9.0/5.0)) + 32.0; // Convert value to ˚F (ensure proper floats!) + +return temp; +} + +void max6675::select() { + ncs = 0; +} + +void max6675::deselect() { + ncs = 1; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/max6675.h Thu Mar 19 04:45:23 2020 +0000 @@ -0,0 +1,25 @@ +#ifndef MAX6675_h +#define MAX6675_h + +#include "mbed.h" + +class max6675 +{ + SPI& spi; + DigitalOut ncs; + public: + + max6675(SPI& _spi, PinName _ncs); + void select(); + void deselect(); + + float read_temp(); + private: + PinName _CS_pin; + PinName _SO_pin; + PinName _SCK_pin; + int _units; + float _error; +}; + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/max6675_2.cpp Thu Mar 19 04:45:23 2020 +0000 @@ -0,0 +1,42 @@ + +#include <mbed.h> +#include "max6675_2.h" + +max6675_2::max6675_2(SPI& _spi_2, PinName _ncs_2) : spi_2(_spi_2), ncs_2(_ncs_2) { + +} + +float max6675_2::read_temp_2() { + short value_2 = 0; + float temp_2 = 0; + + uint8_t highByte_2=0; + uint8_t lowByte_2=0; + + select_2(); + wait(.25); //This delay is needed else it does'nt seem to update the temp + + highByte_2 = spi_2.write(0); + lowByte_2 = spi_2.write(0); + deselect_2(); + + + if (lowByte_2 & (1<<2)) { + error("No Probe"); + } else { + value_2 = (highByte_2 << 5 | lowByte_2>>3); + } + + temp_2 = (value_2*0.25); // Multiply the value by 0.25 to get temp in ˚C or + // * (9.0/5.0)) + 32.0; // Convert value to ˚F (ensure proper floats!) + +return temp_2; +} + +void max6675_2::select_2() { + ncs_2 = 0; +} + +void max6675_2::deselect_2() { + ncs_2 = 1; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/max6675_2.h Thu Mar 19 04:45:23 2020 +0000 @@ -0,0 +1,25 @@ +#ifndef MAX6675_2_h +#define MAX6675_2_h + +#include "mbed.h" + +class max6675_2 +{ + SPI& spi_2; + DigitalOut ncs_2; + public: + + max6675_2(SPI& _spi_2, PinName _ncs_2); + void select_2(); + void deselect_2(); + + float read_temp_2(); + private: + PinName _CS_pin_2; + PinName _SO_pin_2; + PinName _SCK_pin_2; + int _units_2; + float _error_2; +}; + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/max6675_3.cpp Thu Mar 19 04:45:23 2020 +0000 @@ -0,0 +1,42 @@ + +#include <mbed.h> +#include "max6675_3.h" + +max6675_3::max6675_3(SPI& _spi_3, PinName _ncs_3) : spi_3(_spi_3), ncs_3(_ncs_3) { + +} + +float max6675_3::read_temp_3() { + short value_3 = 0; + float temp_3 = 0; + + uint8_t highByte_3=0; + uint8_t lowByte_3=0; + + select_3(); + wait(.25); //This delay is needed else it does'nt seem to update the temp + + highByte_3 = spi_3.write(0); + lowByte_3 = spi_3.write(0); + deselect_3(); + + + if (lowByte_3 & (1<<2)) { + error("No Probe"); + } else { + value_3 = (highByte_3 << 5 | lowByte_3>>3); + } + + temp_3 = (value_3*0.25); // Multiply the value by 0.25 to get temp in ˚C or + // * (9.0/5.0)) + 32.0; // Convert value to ˚F (ensure proper floats!) + +return temp_3; +} + +void max6675_3::select_3() { + ncs_3 = 0; +} + +void max6675_3::deselect_3() { + ncs_3 = 1; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/max6675_3.h Thu Mar 19 04:45:23 2020 +0000 @@ -0,0 +1,25 @@ +#ifndef MAX6675_3_h +#define MAX6675_3_h + +#include "mbed.h" + +class max6675_3 +{ + SPI& spi_3; + DigitalOut ncs_3; + public: + + max6675_3(SPI& _spi_3, PinName _ncs_3); + void select_3(); + void deselect_3(); + + float read_temp_3(); + private: + PinName _CS_pin_3; + PinName _SO_pin_3; + PinName _SCK_pin_3; + int _units_3; + float _error_3; +}; + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/max6675_4.cpp Thu Mar 19 04:45:23 2020 +0000 @@ -0,0 +1,42 @@ + +#include <mbed.h> +#include "max6675_4.h" + +max6675_4::max6675_4(SPI& _spi_4, PinName _ncs_4) : spi_4(_spi_4), ncs_4(_ncs_4) { + +} + +float max6675_4::read_temp_4() { + short value_4 = 0; + float temp_4 = 0; + + uint8_t highByte_4=0; + uint8_t lowByte_4=0; + + select_4(); + wait(.25); //This delay is needed else it does'nt seem to update the temp + + highByte_4 = spi_4.write(0); + lowByte_4 = spi_4.write(0); + deselect_4(); + + + if (lowByte_4 & (1<<2)) { + error("No Probe"); + } else { + value_4 = (highByte_4 << 5 | lowByte_4>>3); + } + + temp_4 = (value_4*0.25); // Multiply the value by 0.25 to get temp in ˚C or + // * (9.0/5.0)) + 32.0; // Convert value to ˚F (ensure proper floats!) + +return temp_4; +} + +void max6675_4::select_4() { + ncs_4 = 0; +} + +void max6675_4::deselect_4() { + ncs_4 = 1; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/max6675_4.h Thu Mar 19 04:45:23 2020 +0000 @@ -0,0 +1,25 @@ +#ifndef MAX6675_4_h +#define MAX6675_4_h + +#include "mbed.h" + +class max6675_4 +{ + SPI& spi_4; + DigitalOut ncs_4; + public: + + max6675_4(SPI& _spi_4, PinName _ncs_4); + void select_4(); + void deselect_4(); + + float read_temp_4(); + private: + PinName _CS_pin_4; + PinName _SO_pin_4; + PinName _SCK_pin_4; + int _units_4; + float _error_4; +}; + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Mar 19 04:45:23 2020 +0000 @@ -0,0 +1,1 @@ +https://mbed.org/users/mbed_official/code/mbed/builds/e1686b8d5b90 \ No newline at end of file