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