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: HDC1000 LPS25H TSL2561_I2C mbed
main.cpp
00001 #include "mbed.h" 00002 #include "HDC1000.h" 00003 #include "TSL2561_I2C.h" 00004 //#include "AQM0802.h" //lcd 00005 #include "LPS25H.h" 00006 00007 //InterruptIn button1(P1_12); // 00008 //DigitalOut led1(LED1); // 00009 //DigitalOut led2(LED2); // 00010 //DigitalOut led3(LED3); //一定以上の回転数の時に光る 00011 DigitalOut flash(LED4); // 00012 HDC1000 hdc1000(P1_1, P1_0); //I2C_0 (sda, scl) 00013 //DigitalOut myled(p5); // 00014 TSL2561_I2C lum_sensor(P1_3, P1_2); //I2C_1 (sda, scl) 00015 //DigitalOut myled(p5); 00016 LPS25H lps25h(P1_7, P1_6); //I2C_3 (sda, scl) 00017 Serial gps(P2_14, P2_15); //UART_0 (TxD, RxD) 00018 Ticker flipper; 00019 Serial pc(USBTX, USBRX); //USB_microB 00020 00021 /* 00022 int i=0; 00023 float f=0; 00024 void rise1() { 00025 led1 = !led1; 00026 } 00027 void fall1() { 00028 led1 = !led1; 00029 i = i++; 00030 } 00031 void flip() { 00032 f=i; 00033 pc.printf("%2.1f \n",f/10); 00034 if(f>3) { 00035 led3=1; 00036 } 00037 else{ 00038 led3=0; 00039 } 00040 i=0; 00041 f=0; 00042 } 00043 */ 00044 00045 #define T0 288.15 00046 #define dT 0.0065 00047 #define P0 101325.0 00048 #define g 9.80665 00049 #define R 287.052 00050 double GetAltitude(double p, double t){ 00051 return (t+273.15)/dT*(pow((P0/p),dT*R/g)-1); 00052 } 00053 00054 int main(){ 00055 00056 /* 00057 button1.rise(&rise1); 00058 button1.fall(&fall1); 00059 flipper.attach(&flip, 10); 00060 */ 00061 00062 char msg[10]; 00063 float h; 00064 float t; 00065 int a=0; 00066 int b=0; 00067 int c=0; 00068 int d=0; 00069 int i=0; 00070 00071 lum_sensor.enablePower(); 00072 int rgb_readings[4]; 00073 int e=0; 00074 int m=0; 00075 int o=0; 00076 int k=0; 00077 int j=1; 00078 00079 char msg2[10]; 00080 int p, u, l; 00081 sprintf(msg2,"Barometer\r\n"); 00082 pc.printf(msg2); 00083 sprintf(msg2,"Altimeter\r\n"); 00084 pc.printf(msg2); 00085 //wait(1); // 00086 00087 pc.printf("gps start! \r\n"); 00088 00089 while(1) { 00090 00091 flash = !flash; 00092 //wait(0.25); 00093 00094 for (i=0;i<5;i++) { 00095 h = hdc1000.humidity(); 00096 h = h/0x10000*100; 00097 sprintf(msg,"%4.1f%% \r\n",h); 00098 //lcd.locate(0,0); 00099 pc.printf(msg); 00100 t = hdc1000.temperature(); 00101 t = t/0x10000*165-40; 00102 sprintf(msg,"%4.1fC \r\n",t); 00103 //lcd.locate(0,1); 00104 pc.printf(msg); 00105 a=h-d; 00106 d=b/c; 00107 b+=h; 00108 c++; 00109 /* 00110 if(a>=1.5){ 00111 myled=1; 00112 } 00113 else{ 00114 if(a<=-1.5){ 00115 myled=1; 00116 } 00117 else{ 00118 myled=0; 00119 } 00120 */ 00121 } 00122 //wait(1); 00123 00124 // for (j=1; j<5; j++){ 00125 printf( "Luminosity: %4.2f\r\n", lum_sensor.getLux() ); 00126 // wait_ms( 100 ); 00127 e=lum_sensor.getLux() - k; 00128 k=m/o; 00129 m+=lum_sensor.getLux(); 00130 o++; 00131 /* 00132 if(e>=1.5){ 00133 myled=1; 00134 } 00135 else{ 00136 if(e<=-1.5){ 00137 myled=1; 00138 } 00139 else{ 00140 myled=0; 00141 } 00142 } 00143 */ 00144 // } 00145 00146 p = (double)lps25h.pressure()/40.96; 00147 u = 42.5 + (double)lps25h.temperature()/480.0; 00148 l = GetAltitude(p,u); 00149 sprintf(msg2,"%6dPa\r\n",p); 00150 // lcd.locate(0,0); 00151 pc.printf(msg2); 00152 sprintf(msg2,"%4dm%2dC\r\n", l, u); 00153 // lcd.locate(0,1); 00154 pc.printf(msg2); 00155 // wait(1); 00156 00157 pc.putc(gps.getc()); //パソコンに文字を送る 00158 } 00159 }
Generated on Wed Jul 13 2022 07:49:11 by
1.7.2