123

Dependencies:   mbed HTS221 LPS25HB

Committer:
Simon_mbed
Date:
Mon Apr 06 08:54:17 2020 +0000
Revision:
0:2365a00ff7b6
13

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Simon_mbed 0:2365a00ff7b6 1 #include "mbed.h"
Simon_mbed 0:2365a00ff7b6 2 #include "HTS221Sensor.h"
Simon_mbed 0:2365a00ff7b6 3
Simon_mbed 0:2365a00ff7b6 4 Serial pc(SERIAL_TX, SERIAL_RX);
Simon_mbed 0:2365a00ff7b6 5
Simon_mbed 0:2365a00ff7b6 6
Simon_mbed 0:2365a00ff7b6 7 DigitalOut myled(LED1);
Simon_mbed 0:2365a00ff7b6 8 DigitalOut led(LED1);
Simon_mbed 0:2365a00ff7b6 9
Simon_mbed 0:2365a00ff7b6 10 DevI2C devi2c(I2C_SDA, I2C_SCL);
Simon_mbed 0:2365a00ff7b6 11
Simon_mbed 0:2365a00ff7b6 12 HTS221Sensor hts221(&devi2c);
Simon_mbed 0:2365a00ff7b6 13
Simon_mbed 0:2365a00ff7b6 14
Simon_mbed 0:2365a00ff7b6 15 int main()
Simon_mbed 0:2365a00ff7b6 16 {
Simon_mbed 0:2365a00ff7b6 17 float hum = 0;
Simon_mbed 0:2365a00ff7b6 18 float temp = 0;
Simon_mbed 0:2365a00ff7b6 19 pc.baud(9600);
Simon_mbed 0:2365a00ff7b6 20 pc.printf("Hello World !\n");
Simon_mbed 0:2365a00ff7b6 21
Simon_mbed 0:2365a00ff7b6 22
Simon_mbed 0:2365a00ff7b6 23
Simon_mbed 0:2365a00ff7b6 24 HTS221_Init_st init_st;
Simon_mbed 0:2365a00ff7b6 25 init_st.avg_h = HTS221_AVGH_4;
Simon_mbed 0:2365a00ff7b6 26 init_st.avg_t = HTS221_AVGT_4;
Simon_mbed 0:2365a00ff7b6 27 init_st.odr = HTS221_ODR_1HZ;
Simon_mbed 0:2365a00ff7b6 28 init_st.bdu_status = HTS221_ENABLE;
Simon_mbed 0:2365a00ff7b6 29 init_st.heater_status = HTS221_ENABLE;
Simon_mbed 0:2365a00ff7b6 30 init_st.irq_level = HTS221_HIGH_LVL;
Simon_mbed 0:2365a00ff7b6 31 init_st.irq_output_type = HTS221_PUSHPULL;
Simon_mbed 0:2365a00ff7b6 32 init_st.irq_enable = HTS221_DISABLE;
Simon_mbed 0:2365a00ff7b6 33
Simon_mbed 0:2365a00ff7b6 34 int ret = hts221.init(&init_st);
Simon_mbed 0:2365a00ff7b6 35
Simon_mbed 0:2365a00ff7b6 36 if(ret ==0) {
Simon_mbed 0:2365a00ff7b6 37 pc.printf("init succesed!");
Simon_mbed 0:2365a00ff7b6 38 }
Simon_mbed 0:2365a00ff7b6 39
Simon_mbed 0:2365a00ff7b6 40
Simon_mbed 0:2365a00ff7b6 41 hts221.enable();
Simon_mbed 0:2365a00ff7b6 42 while(1) {
Simon_mbed 0:2365a00ff7b6 43
Simon_mbed 0:2365a00ff7b6 44 hts221.get_humidity(&hum);
Simon_mbed 0:2365a00ff7b6 45 hts221.get_temperature(&temp);
Simon_mbed 0:2365a00ff7b6 46
Simon_mbed 0:2365a00ff7b6 47 pc.printf("hum:%f temp:%f\r\n",hum,temp);
Simon_mbed 0:2365a00ff7b6 48 wait(1);
Simon_mbed 0:2365a00ff7b6 49 }
Simon_mbed 0:2365a00ff7b6 50
Simon_mbed 0:2365a00ff7b6 51 }