Mr.Y's program!

Dependencies:   HDC1000 LPS25H TSL2561_I2C mbed

Committer:
tukumotann
Date:
Thu Oct 08 13:08:35 2015 +0000
Revision:
0:b80c6c476e55
GR kidyouksndoku;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tukumotann 0:b80c6c476e55 1 #include "mbed.h"
tukumotann 0:b80c6c476e55 2 #include "HDC1000.h"
tukumotann 0:b80c6c476e55 3 #include "TSL2561_I2C.h"
tukumotann 0:b80c6c476e55 4 //#include "AQM0802.h" //lcd
tukumotann 0:b80c6c476e55 5 #include "LPS25H.h"
tukumotann 0:b80c6c476e55 6
tukumotann 0:b80c6c476e55 7 //InterruptIn button1(P1_12); //
tukumotann 0:b80c6c476e55 8 //DigitalOut led1(LED1); //
tukumotann 0:b80c6c476e55 9 //DigitalOut led2(LED2); //
tukumotann 0:b80c6c476e55 10 //DigitalOut led3(LED3); //一定以上の回転数の時に光る
tukumotann 0:b80c6c476e55 11 DigitalOut flash(LED4); //
tukumotann 0:b80c6c476e55 12 HDC1000 hdc1000(P1_1, P1_0); //I2C_0 (sda, scl)
tukumotann 0:b80c6c476e55 13 //DigitalOut myled(p5); //
tukumotann 0:b80c6c476e55 14 TSL2561_I2C lum_sensor(P1_3, P1_2); //I2C_1 (sda, scl)
tukumotann 0:b80c6c476e55 15 //DigitalOut myled(p5);
tukumotann 0:b80c6c476e55 16 LPS25H lps25h(P1_7, P1_6); //I2C_3 (sda, scl)
tukumotann 0:b80c6c476e55 17 Serial gps(P2_14, P2_15); //UART_0 (TxD, RxD)
tukumotann 0:b80c6c476e55 18 Ticker flipper;
tukumotann 0:b80c6c476e55 19 Serial pc(USBTX, USBRX); //USB_microB
tukumotann 0:b80c6c476e55 20
tukumotann 0:b80c6c476e55 21 /*
tukumotann 0:b80c6c476e55 22 int i=0;
tukumotann 0:b80c6c476e55 23 float f=0;
tukumotann 0:b80c6c476e55 24 void rise1() {
tukumotann 0:b80c6c476e55 25 led1 = !led1;
tukumotann 0:b80c6c476e55 26 }
tukumotann 0:b80c6c476e55 27 void fall1() {
tukumotann 0:b80c6c476e55 28 led1 = !led1;
tukumotann 0:b80c6c476e55 29 i = i++;
tukumotann 0:b80c6c476e55 30 }
tukumotann 0:b80c6c476e55 31 void flip() {
tukumotann 0:b80c6c476e55 32 f=i;
tukumotann 0:b80c6c476e55 33 pc.printf("%2.1f \n",f/10);
tukumotann 0:b80c6c476e55 34 if(f>3) {
tukumotann 0:b80c6c476e55 35 led3=1;
tukumotann 0:b80c6c476e55 36 }
tukumotann 0:b80c6c476e55 37 else{
tukumotann 0:b80c6c476e55 38 led3=0;
tukumotann 0:b80c6c476e55 39 }
tukumotann 0:b80c6c476e55 40 i=0;
tukumotann 0:b80c6c476e55 41 f=0;
tukumotann 0:b80c6c476e55 42 }
tukumotann 0:b80c6c476e55 43 */
tukumotann 0:b80c6c476e55 44
tukumotann 0:b80c6c476e55 45 #define T0 288.15
tukumotann 0:b80c6c476e55 46 #define dT 0.0065
tukumotann 0:b80c6c476e55 47 #define P0 101325.0
tukumotann 0:b80c6c476e55 48 #define g 9.80665
tukumotann 0:b80c6c476e55 49 #define R 287.052
tukumotann 0:b80c6c476e55 50 double GetAltitude(double p, double t){
tukumotann 0:b80c6c476e55 51 return (t+273.15)/dT*(pow((P0/p),dT*R/g)-1);
tukumotann 0:b80c6c476e55 52 }
tukumotann 0:b80c6c476e55 53
tukumotann 0:b80c6c476e55 54 int main(){
tukumotann 0:b80c6c476e55 55
tukumotann 0:b80c6c476e55 56 /*
tukumotann 0:b80c6c476e55 57 button1.rise(&rise1);
tukumotann 0:b80c6c476e55 58 button1.fall(&fall1);
tukumotann 0:b80c6c476e55 59 flipper.attach(&flip, 10);
tukumotann 0:b80c6c476e55 60 */
tukumotann 0:b80c6c476e55 61
tukumotann 0:b80c6c476e55 62 char msg[10];
tukumotann 0:b80c6c476e55 63 float h;
tukumotann 0:b80c6c476e55 64 float t;
tukumotann 0:b80c6c476e55 65 int a=0;
tukumotann 0:b80c6c476e55 66 int b=0;
tukumotann 0:b80c6c476e55 67 int c=0;
tukumotann 0:b80c6c476e55 68 int d=0;
tukumotann 0:b80c6c476e55 69 int i=0;
tukumotann 0:b80c6c476e55 70
tukumotann 0:b80c6c476e55 71 lum_sensor.enablePower();
tukumotann 0:b80c6c476e55 72 int rgb_readings[4];
tukumotann 0:b80c6c476e55 73 int e=0;
tukumotann 0:b80c6c476e55 74 int m=0;
tukumotann 0:b80c6c476e55 75 int o=0;
tukumotann 0:b80c6c476e55 76 int k=0;
tukumotann 0:b80c6c476e55 77 int j=1;
tukumotann 0:b80c6c476e55 78
tukumotann 0:b80c6c476e55 79 char msg2[10];
tukumotann 0:b80c6c476e55 80 int p, u, l;
tukumotann 0:b80c6c476e55 81 sprintf(msg2,"Barometer\r\n");
tukumotann 0:b80c6c476e55 82 pc.printf(msg2);
tukumotann 0:b80c6c476e55 83 sprintf(msg2,"Altimeter\r\n");
tukumotann 0:b80c6c476e55 84 pc.printf(msg2);
tukumotann 0:b80c6c476e55 85 //wait(1); //
tukumotann 0:b80c6c476e55 86
tukumotann 0:b80c6c476e55 87 pc.printf("gps start! \r\n");
tukumotann 0:b80c6c476e55 88
tukumotann 0:b80c6c476e55 89 while(1) {
tukumotann 0:b80c6c476e55 90
tukumotann 0:b80c6c476e55 91 flash = !flash;
tukumotann 0:b80c6c476e55 92 //wait(0.25);
tukumotann 0:b80c6c476e55 93
tukumotann 0:b80c6c476e55 94 for (i=0;i<5;i++) {
tukumotann 0:b80c6c476e55 95 h = hdc1000.humidity();
tukumotann 0:b80c6c476e55 96 h = h/0x10000*100;
tukumotann 0:b80c6c476e55 97 sprintf(msg,"%4.1f%% \r\n",h);
tukumotann 0:b80c6c476e55 98 //lcd.locate(0,0);
tukumotann 0:b80c6c476e55 99 pc.printf(msg);
tukumotann 0:b80c6c476e55 100 t = hdc1000.temperature();
tukumotann 0:b80c6c476e55 101 t = t/0x10000*165-40;
tukumotann 0:b80c6c476e55 102 sprintf(msg,"%4.1fC \r\n",t);
tukumotann 0:b80c6c476e55 103 //lcd.locate(0,1);
tukumotann 0:b80c6c476e55 104 pc.printf(msg);
tukumotann 0:b80c6c476e55 105 a=h-d;
tukumotann 0:b80c6c476e55 106 d=b/c;
tukumotann 0:b80c6c476e55 107 b+=h;
tukumotann 0:b80c6c476e55 108 c++;
tukumotann 0:b80c6c476e55 109 /*
tukumotann 0:b80c6c476e55 110 if(a>=1.5){
tukumotann 0:b80c6c476e55 111 myled=1;
tukumotann 0:b80c6c476e55 112 }
tukumotann 0:b80c6c476e55 113 else{
tukumotann 0:b80c6c476e55 114 if(a<=-1.5){
tukumotann 0:b80c6c476e55 115 myled=1;
tukumotann 0:b80c6c476e55 116 }
tukumotann 0:b80c6c476e55 117 else{
tukumotann 0:b80c6c476e55 118 myled=0;
tukumotann 0:b80c6c476e55 119 }
tukumotann 0:b80c6c476e55 120 */
tukumotann 0:b80c6c476e55 121 }
tukumotann 0:b80c6c476e55 122 //wait(1);
tukumotann 0:b80c6c476e55 123
tukumotann 0:b80c6c476e55 124 // for (j=1; j<5; j++){
tukumotann 0:b80c6c476e55 125 printf( "Luminosity: %4.2f\r\n", lum_sensor.getLux() );
tukumotann 0:b80c6c476e55 126 // wait_ms( 100 );
tukumotann 0:b80c6c476e55 127 e=lum_sensor.getLux() - k;
tukumotann 0:b80c6c476e55 128 k=m/o;
tukumotann 0:b80c6c476e55 129 m+=lum_sensor.getLux();
tukumotann 0:b80c6c476e55 130 o++;
tukumotann 0:b80c6c476e55 131 /*
tukumotann 0:b80c6c476e55 132 if(e>=1.5){
tukumotann 0:b80c6c476e55 133 myled=1;
tukumotann 0:b80c6c476e55 134 }
tukumotann 0:b80c6c476e55 135 else{
tukumotann 0:b80c6c476e55 136 if(e<=-1.5){
tukumotann 0:b80c6c476e55 137 myled=1;
tukumotann 0:b80c6c476e55 138 }
tukumotann 0:b80c6c476e55 139 else{
tukumotann 0:b80c6c476e55 140 myled=0;
tukumotann 0:b80c6c476e55 141 }
tukumotann 0:b80c6c476e55 142 }
tukumotann 0:b80c6c476e55 143 */
tukumotann 0:b80c6c476e55 144 // }
tukumotann 0:b80c6c476e55 145
tukumotann 0:b80c6c476e55 146 p = (double)lps25h.pressure()/40.96;
tukumotann 0:b80c6c476e55 147 u = 42.5 + (double)lps25h.temperature()/480.0;
tukumotann 0:b80c6c476e55 148 l = GetAltitude(p,u);
tukumotann 0:b80c6c476e55 149 sprintf(msg2,"%6dPa\r\n",p);
tukumotann 0:b80c6c476e55 150 // lcd.locate(0,0);
tukumotann 0:b80c6c476e55 151 pc.printf(msg2);
tukumotann 0:b80c6c476e55 152 sprintf(msg2,"%4dm%2dC\r\n", l, u);
tukumotann 0:b80c6c476e55 153 // lcd.locate(0,1);
tukumotann 0:b80c6c476e55 154 pc.printf(msg2);
tukumotann 0:b80c6c476e55 155 // wait(1);
tukumotann 0:b80c6c476e55 156
tukumotann 0:b80c6c476e55 157 pc.putc(gps.getc()); //パソコンに文字を送る
tukumotann 0:b80c6c476e55 158 }
tukumotann 0:b80c6c476e55 159 }