Sample code to get started
Fork of SOFT253_Template_Weather_OS_54-official by
main.cpp@35:af125862c33e, 2017-04-12 (annotated)
- Committer:
- noutram
- Date:
- Wed Apr 12 13:45:28 2017 +0000
- Revision:
- 35:af125862c33e
- Parent:
- 34:62aae7d507e2
- Child:
- 36:c2fd1cd2434f
Fixed by noutram
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" |
noutram | 35:af125862c33e | 3 | #include "hts221.h" |
martinsimpson | 32:260a288be58f | 4 | #include "LPS25H.h" |
martinsimpson | 32:260a288be58f | 5 | |
noutram | 35:af125862c33e | 6 | |
martinsimpson | 32:260a288be58f | 7 | DigitalOut myled(LED1); |
martinsimpson | 32:260a288be58f | 8 | I2C i2c2(I2C_SDA, I2C_SCL); |
noutram | 35:af125862c33e | 9 | |
noutram | 35:af125862c33e | 10 | float tempCelsius = 25.50; |
noutram | 35:af125862c33e | 11 | float humi = 55; |
noutram | 35:af125862c33e | 12 | int humiMax = 100; |
noutram | 35:af125862c33e | 13 | char cmd=0; |
noutram | 35:af125862c33e | 14 | uint32_t seconds = 0, minutes=0, hours=0; |
martinsimpson | 32:260a288be58f | 15 | |
noutram | 35:af125862c33e | 16 | LPS25H barometer(i2c2, LPS25H_V_CHIP_ADDR); |
noutram | 35:af125862c33e | 17 | HTS221 humidity(I2C_SDA, I2C_SCL); |
noutram | 35:af125862c33e | 18 | |
noutram | 35:af125862c33e | 19 | |
noutram | 35:af125862c33e | 20 | int main() |
noutram | 35:af125862c33e | 21 | { |
noutram | 35:af125862c33e | 22 | humidity.init(); |
noutram | 35:af125862c33e | 23 | humidity.calib(); |
noutram | 35:af125862c33e | 24 | printf("SOFT253 simple Temperature Humidity and Pressure Sensor Monitor\n\r"); |
noutram | 35:af125862c33e | 25 | printf("Using the X-NUCLEO-IKS01A1 shield and MBED Libraries\n\r"); |
noutram | 35:af125862c33e | 26 | //printf("%#x\n\r",barometer.read_id()); |
martinsimpson | 32:260a288be58f | 27 | |
noutram | 35:af125862c33e | 28 | while(1) |
noutram | 35:af125862c33e | 29 | { |
noutram | 35:af125862c33e | 30 | cmd=NULL; |
noutram | 35:af125862c33e | 31 | while(cmd==NULL){cmd=getchar();} |
noutram | 35:af125862c33e | 32 | if(cmd=='?'){ |
noutram | 35:af125862c33e | 33 | printf("SOFT253 simple Temperature Humidity and Pressure Sensor Monitor\n\r"); |
noutram | 35:af125862c33e | 34 | printf("Using the X-NUCLEO-IKS01A1 shield and MBED Libraries\n\r"); |
noutram | 35:af125862c33e | 35 | } |
noutram | 35:af125862c33e | 36 | if(cmd=='A'){ |
noutram | 35:af125862c33e | 37 | humidity.ReadTempHumi(&tempCelsius, &humi); |
noutram | 35:af125862c33e | 38 | printf("%4.2fC %3.1f%%", tempCelsius, humi); |
noutram | 35:af125862c33e | 39 | barometer.get(); |
noutram | 35:af125862c33e | 40 | printf(" %6.1f %4.1f\r\n", barometer.pressure(), barometer.temperature()); |
noutram | 35:af125862c33e | 41 | myled = 1; // LED is ON |
noutram | 35:af125862c33e | 42 | Thread::wait(200); // 200 ms NB 'Thread::wait(int d);' !!! d is in milliseconds! |
noutram | 35:af125862c33e | 43 | myled = 0; // LED is OFF |
noutram | 35:af125862c33e | 44 | Thread::wait(100); // 100 ms |
noutram | 35:af125862c33e | 45 | } |
FairyMental | 34:62aae7d507e2 | 46 | } |
noutram | 35:af125862c33e | 47 | } |
noutram | 35:af125862c33e | 48 | |
noutram | 35:af125862c33e | 49 | |
noutram | 35:af125862c33e | 50 | |
noutram | 35:af125862c33e | 51 | /*#include "mbed.h" |
noutram | 35:af125862c33e | 52 | |
noutram | 35:af125862c33e | 53 | DigitalOut led1(LED1); |
noutram | 35:af125862c33e | 54 | |
noutram | 35:af125862c33e | 55 | // main() runs in its own thread in the OS |
noutram | 35:af125862c33e | 56 | int main() { |
FairyMental | 34:62aae7d507e2 | 57 | while (true) { |
noutram | 35:af125862c33e | 58 | led1 = !led1; |
noutram | 35:af125862c33e | 59 | wait(0.5); |
noutram | 35:af125862c33e | 60 | } |
FairyMental | 34:62aae7d507e2 | 61 | } |
noutram | 35:af125862c33e | 62 | */ |