![](/media/cache/profiles/acab0116c354964a558e65bdd07ff047.jpg.50x50_q85.jpg)
test
Dependencies: CheckRTC LPS25H hts221
Fork of ELEC350-extended-referral2 by
main.cpp@33:cffe0ae69aa6, 2017-03-29 (annotated)
- Committer:
- martinsimpson
- Date:
- Wed Mar 29 11:34:00 2017 +0000
- Revision:
- 33:cffe0ae69aa6
- Parent:
- 32:260a288be58f
- Child:
- 34:62aae7d507e2
New library added for hts221
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Jonathan Austin |
0:2757d7abb7d9 | 1 | #include "mbed.h" |
martinsimpson | 32:260a288be58f | 2 | #include "rtos.h" |
martinsimpson | 32:260a288be58f | 3 | #include "hts221.h" |
martinsimpson | 32:260a288be58f | 4 | #include "LPS25H.h" |
martinsimpson | 32:260a288be58f | 5 | |
martinsimpson | 32:260a288be58f | 6 | |
martinsimpson | 32:260a288be58f | 7 | DigitalOut myled(LED1); |
martinsimpson | 32:260a288be58f | 8 | I2C i2c2(I2C_SDA, I2C_SCL); |
martinsimpson | 32:260a288be58f | 9 | |
martinsimpson | 32:260a288be58f | 10 | float tempCelsius = 25.50; |
martinsimpson | 32:260a288be58f | 11 | float humi = 55; |
martinsimpson | 32:260a288be58f | 12 | int humiMax = 100; |
martinsimpson | 32:260a288be58f | 13 | char cmd=0; |
martinsimpson | 32:260a288be58f | 14 | uint32_t seconds = 0, minutes=0, hours=0; |
martinsimpson | 32:260a288be58f | 15 | |
martinsimpson | 32:260a288be58f | 16 | LPS25H barometer(i2c2, LPS25H_V_CHIP_ADDR); |
martinsimpson | 33:cffe0ae69aa6 | 17 | HTS221 humidity(I2C_SDA, I2C_SCL); |
martinsimpson | 32:260a288be58f | 18 | |
martinsimpson | 32:260a288be58f | 19 | |
martinsimpson | 32:260a288be58f | 20 | int main() |
martinsimpson | 32:260a288be58f | 21 | { |
martinsimpson | 33:cffe0ae69aa6 | 22 | humidity.init(); |
martinsimpson | 33:cffe0ae69aa6 | 23 | humidity.calib(); |
martinsimpson | 32:260a288be58f | 24 | printf("SOFT253 simple Temperature Humidity and Pressure Sensor Monitor\n\r"); |
martinsimpson | 32:260a288be58f | 25 | printf("Using the X-NUCLEO-IKS01A1 shield and MBED Libraries\n\r"); |
martinsimpson | 32:260a288be58f | 26 | //printf("%#x\n\r",barometer.read_id()); |
martinsimpson | 32:260a288be58f | 27 | |
martinsimpson | 32:260a288be58f | 28 | while(1) |
martinsimpson | 32:260a288be58f | 29 | { |
martinsimpson | 32:260a288be58f | 30 | cmd=NULL; |
martinsimpson | 32:260a288be58f | 31 | while(cmd==NULL){cmd=getchar();} |
martinsimpson | 32:260a288be58f | 32 | if(cmd=='?'){ |
martinsimpson | 32:260a288be58f | 33 | printf("SOFT253 simple Temperature Humidity and Pressure Sensor Monitor\n\r"); |
martinsimpson | 32:260a288be58f | 34 | printf("Using the X-NUCLEO-IKS01A1 shield and MBED Libraries\n\r"); |
martinsimpson | 32:260a288be58f | 35 | } |
martinsimpson | 32:260a288be58f | 36 | if(cmd=='A'){ |
martinsimpson | 33:cffe0ae69aa6 | 37 | humidity.ReadTempHumi(&tempCelsius, &humi); |
martinsimpson | 32:260a288be58f | 38 | printf("%4.2fC %3.1f%%", tempCelsius, humi); |
martinsimpson | 32:260a288be58f | 39 | barometer.get(); |
martinsimpson | 32:260a288be58f | 40 | printf(" %6.1f %4.1f\r\n", barometer.pressure(), barometer.temperature()); |
martinsimpson | 32:260a288be58f | 41 | myled = 1; // LED is ON |
martinsimpson | 32:260a288be58f | 42 | Thread::wait(200); // 200 ms NB 'Thread::wait(int d);' !!! d is in milliseconds! |
martinsimpson | 32:260a288be58f | 43 | myled = 0; // LED is OFF |
martinsimpson | 32:260a288be58f | 44 | Thread::wait(100); // 100 ms |
martinsimpson | 32:260a288be58f | 45 | } |
martinsimpson | 32:260a288be58f | 46 | } |
martinsimpson | 32:260a288be58f | 47 | } |
martinsimpson | 32:260a288be58f | 48 | |
martinsimpson | 32:260a288be58f | 49 | |
martinsimpson | 32:260a288be58f | 50 | |
martinsimpson | 32:260a288be58f | 51 | /*#include "mbed.h" |
Jonathan Austin |
0:2757d7abb7d9 | 52 | |
Jonathan Austin |
0:2757d7abb7d9 | 53 | DigitalOut led1(LED1); |
Jonathan Austin |
0:2757d7abb7d9 | 54 | |
Jonathan Austin |
1:846c97078558 | 55 | // main() runs in its own thread in the OS |
Jonathan Austin |
0:2757d7abb7d9 | 56 | int main() { |
Jonathan Austin |
0:2757d7abb7d9 | 57 | while (true) { |
Jonathan Austin |
0:2757d7abb7d9 | 58 | led1 = !led1; |
mbed_official | 22:af9dcf379926 | 59 | wait(0.5); |
Jonathan Austin |
0:2757d7abb7d9 | 60 | } |
Jonathan Austin |
0:2757d7abb7d9 | 61 | } |
martinsimpson | 32:260a288be58f | 62 | */ |