Updated
Dependencies: mbed Nucleo_Sensor_Shield
main.cpp
- Committer:
- ongjiajun
- Date:
- 2019-02-15
- Revision:
- 4:1c3a109a6f6f
- Parent:
- 3:53d2d440a695
File content as of revision 4:1c3a109a6f6f:
#include "mbed.h" #include "x_cube_mems.h" DigitalOut led(LED1); Serial pc(USBTX, USBRX); Ticker blinky; Ticker update; volatile float TEMPERATURE_C; volatile float TEMPERATURE_K; volatile float HUMIDITY; volatile float PRESSURE; bool measurements_update = false; void blinky_handler(){ led = !led; } void sensors_handler(){ measurements_update = true; } int main() { static X_CUBE_MEMS *Sensors = X_CUBE_MEMS::Instance(); blinky.attach(&blinky_handler, 0.5); update.attach(&sensors_handler, 3); while(1) { if(measurements_update == true){ /* Read the environmental sensors */ Sensors->hts221.GetTemperature((float*)&TEMPERATURE_C); Sensors->hts221.GetHumidity((float*)&HUMIDITY); TEMPERATURE_K = (TEMPERATURE_C * 273.15F); //Convert the temperature from Celcius to Kelvin pc.printf("Temperature:\t %.2f C / %.2f K\r\n", TEMPERATURE_C, TEMPERATURE_K); pc.printf("Pressure:\t%.2f%%\n", HUMIDITY); pc.printf("\r\n"); measurements_update = false; } __wfi(); } }