Simon Yang / Mbed 2 deprecated GB9662

Dependencies:   mbed HTS221 LPS25HB

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "HTS221Sensor.h"
00003 
00004 Serial pc(SERIAL_TX, SERIAL_RX);
00005 
00006 
00007 DigitalOut myled(LED1);
00008 DigitalOut led(LED1);
00009 
00010 DevI2C devi2c(I2C_SDA, I2C_SCL);
00011 
00012 HTS221Sensor hts221(&devi2c);
00013 
00014 
00015 int main()
00016 {
00017     float hum = 0;
00018     float temp = 0;
00019     pc.baud(9600);
00020     pc.printf("Hello World !\n");
00021 
00022 
00023 
00024     HTS221_Init_st init_st;
00025     init_st.avg_h = HTS221_AVGH_4;
00026     init_st.avg_t = HTS221_AVGT_4;
00027     init_st.odr = HTS221_ODR_1HZ;
00028     init_st.bdu_status = HTS221_ENABLE;
00029     init_st.heater_status = HTS221_ENABLE;
00030     init_st.irq_level = HTS221_HIGH_LVL;
00031     init_st.irq_output_type = HTS221_PUSHPULL;
00032     init_st.irq_enable = HTS221_DISABLE;
00033 
00034     int ret =  hts221.init(&init_st);
00035 
00036     if(ret ==0) {
00037         pc.printf("init succesed!");
00038     }
00039 
00040 
00041     hts221.enable();
00042     while(1) {
00043 
00044         hts221.get_humidity(&hum);
00045         hts221.get_temperature(&temp);
00046         
00047         pc.printf("hum:%f temp:%f\r\n",hum,temp);
00048         wait(1);
00049     }
00050 
00051 }