UPDATED

Dependencies:   mbed Nucleo_Sensor_Shield

Committer:
PurpleSkyMK
Date:
Fri Feb 15 06:36:00 2019 +0000
Revision:
4:5fb25b7e78ba
Parent:
3:53d2d440a695
UPDATED

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kennethwfk 0:fc777b6c55d6 1
kennethwfk 0:fc777b6c55d6 2
kennethwfk 0:fc777b6c55d6 3 #include "mbed.h"
kennethwfk 0:fc777b6c55d6 4 #include "x_cube_mems.h"
kennethwfk 0:fc777b6c55d6 5
kennethwfk 0:fc777b6c55d6 6 DigitalOut led(LED1);
kennethwfk 0:fc777b6c55d6 7
kennethwfk 0:fc777b6c55d6 8 Serial pc(USBTX, USBRX);
kennethwfk 0:fc777b6c55d6 9
kennethwfk 0:fc777b6c55d6 10 Ticker blinky;
kennethwfk 0:fc777b6c55d6 11 Ticker update;
kennethwfk 0:fc777b6c55d6 12
kennethwfk 0:fc777b6c55d6 13 volatile float TEMPERATURE_C;
PurpleSkyMK 4:5fb25b7e78ba 14 volatile float TEMPERATURE_F;
PurpleSkyMK 4:5fb25b7e78ba 15 volatile float TEMPERATURE_K;
PurpleSkyMK 4:5fb25b7e78ba 16 volatile float HUMIDITY;
PurpleSkyMK 4:5fb25b7e78ba 17 volatile float PRESSURE;
selvakumararm 3:53d2d440a695 18
PurpleSkyMK 4:5fb25b7e78ba 19
PurpleSkyMK 4:5fb25b7e78ba 20
selvakumararm 3:53d2d440a695 21
kennethwfk 0:fc777b6c55d6 22
kennethwfk 0:fc777b6c55d6 23 bool measurements_update = false;
kennethwfk 0:fc777b6c55d6 24
kennethwfk 0:fc777b6c55d6 25 void blinky_handler(){
kennethwfk 0:fc777b6c55d6 26 led = !led;
kennethwfk 0:fc777b6c55d6 27 }
kennethwfk 0:fc777b6c55d6 28
kennethwfk 0:fc777b6c55d6 29 void sensors_handler(){
kennethwfk 0:fc777b6c55d6 30 measurements_update = true;
kennethwfk 0:fc777b6c55d6 31 }
kennethwfk 0:fc777b6c55d6 32
kennethwfk 0:fc777b6c55d6 33 int main() {
kennethwfk 0:fc777b6c55d6 34
selvakumararm 2:28f8cd15fca4 35
kennethwfk 0:fc777b6c55d6 36 static X_CUBE_MEMS *Sensors = X_CUBE_MEMS::Instance();
kennethwfk 0:fc777b6c55d6 37
selvakumararm 2:28f8cd15fca4 38
kennethwfk 0:fc777b6c55d6 39 blinky.attach(&blinky_handler, 0.5);
kennethwfk 0:fc777b6c55d6 40 update.attach(&sensors_handler, 3);
kennethwfk 0:fc777b6c55d6 41
kennethwfk 0:fc777b6c55d6 42 while(1) {
kennethwfk 0:fc777b6c55d6 43
kennethwfk 0:fc777b6c55d6 44 if(measurements_update == true){
kennethwfk 0:fc777b6c55d6 45 /* Read the environmental sensors */
kennethwfk 0:fc777b6c55d6 46
PurpleSkyMK 4:5fb25b7e78ba 47 Sensors->hts221.GetTemperature((float*)&TEMPERATURE_C);
PurpleSkyMK 4:5fb25b7e78ba 48 Sensors->hts221.GetHumidity((float*)&HUMIDITY);
PurpleSkyMK 4:5fb25b7e78ba 49 Sensors->lps25h.GetPressure((float*)&PRESSURE);
PurpleSkyMK 4:5fb25b7e78ba 50
PurpleSkyMK 4:5fb25b7e78ba 51
PurpleSkyMK 4:5fb25b7e78ba 52
selvakumararm 2:28f8cd15fca4 53
selvakumararm 2:28f8cd15fca4 54
kennethwfk 0:fc777b6c55d6 55 pc.printf("Temperature:\t %.2f C / %.2f F / %.2f K\r\n", TEMPERATURE_C, TEMPERATURE_F, TEMPERATURE_K);
selvakumararm 3:53d2d440a695 56
selvakumararm 2:28f8cd15fca4 57
kennethwfk 0:fc777b6c55d6 58
kennethwfk 0:fc777b6c55d6 59 pc.printf("\r\n");
kennethwfk 0:fc777b6c55d6 60
kennethwfk 0:fc777b6c55d6 61 measurements_update = false;
kennethwfk 0:fc777b6c55d6 62 }
kennethwfk 0:fc777b6c55d6 63 __wfi();
kennethwfk 0:fc777b6c55d6 64 }
kennethwfk 0:fc777b6c55d6 65 }