OS 5.4 30th March 2017

Dependencies:   LPS25H hts221

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "rtos.h"
00003 #include "hts221.h"
00004 #include "LPS25H.h"
00005 
00006 
00007 DigitalOut myled(LED1);
00008 I2C i2c2(I2C_SDA, I2C_SCL);
00009 
00010 float tempCelsius = 25.50;
00011 float humi = 55;
00012 int humiMax = 100; 
00013 char cmd=0;
00014 uint32_t seconds = 0, minutes=0, hours=0; 
00015 
00016 LPS25H barometer(i2c2, LPS25H_V_CHIP_ADDR);
00017 HTS221 humidity(I2C_SDA, I2C_SCL);
00018 
00019 
00020 int main()
00021   {
00022   humidity.init();
00023   humidity.calib();
00024   printf("SOFT253 simple Temperature Humidity and Pressure Sensor Monitor\n\r");
00025   printf("Using the X-NUCLEO-IKS01A1 shield and MBED Libraries\n\r");
00026     //printf("%#x\n\r",barometer.read_id());
00027     
00028   while(1) 
00029     {
00030       cmd=NULL;
00031       while(cmd==NULL){cmd=getchar();}
00032       if(cmd=='?'){
00033         printf("SOFT253 simple Temperature Humidity and Pressure Sensor Monitor\n\r");
00034         printf("Using the X-NUCLEO-IKS01A1 shield and MBED Libraries\n\r");
00035       }
00036       if(cmd=='A'){
00037         humidity.ReadTempHumi(&tempCelsius, &humi);
00038         printf("%4.2fC %3.1f%%", tempCelsius, humi);
00039         barometer.get();
00040         printf(" %6.1f %4.1f\r\n", barometer.pressure(), barometer.temperature());
00041         myled = 1; // LED is ON
00042         Thread::wait(200); // 200 ms NB 'Thread::wait(int d);' !!! d is in milliseconds! 
00043         myled = 0; // LED is OFF
00044         Thread::wait(100); // 100 ms
00045       }
00046     }
00047   }
00048   
00049 
00050 
00051 /*#include "mbed.h"
00052 
00053 DigitalOut led1(LED1);
00054 
00055 // main() runs in its own thread in the OS
00056 int main() {
00057     while (true) {
00058         led1 = !led1;
00059         wait(0.5);
00060     }
00061 }
00062 */