Temperature and humidity example for NXP rapid IoT prototyping kit. Read more at https://www.hackster.io/marcomerli/riotwear-mbed-2b2011 .
Dependencies: AMS_ENS210_temp_humid_sensor
main.cpp
- Committer:
- batman52
- Date:
- 2019-12-03
- Revision:
- 80:c455b645d802
- Parent:
- 79:0431b9fd3dc0
File content as of revision 80:c455b645d802:
#include "mbed.h" #include "AMS_ENS210.h" #define WAIT() wait(0.2) AMS_ENS210 temphumid(I2C_SDA, I2C_SCL); void read_temperature(void) { temphumid.init(); WAIT(); temphumid.start(true); WAIT(); while(!temphumid.temp_has_data()); // printf("Wait for temperature read!\n\r"); temphumid.stop(true); WAIT(); printf("Temp: %d [C]\r\n", ((temphumid.temp_read() >> 6)-273) ); } void read_humidity(void) { temphumid.init(); WAIT(); temphumid.start(false,true); WAIT(); while(!temphumid.humid_has_data()); temphumid.stop(false,true); WAIT(); printf("Humidity: %d [%]\r\n", ( temphumid.humid_read() >> 9) ); } // main() runs in its own thread in the OS int main() { while (true) { read_temperature(); WAIT(); read_humidity(); WAIT(); } }