SOFT253 Coursework Weather Reader
Fork of Soft253-WeatherReader by
main.cpp@1:8585a8d417dc, 2017-04-21 (annotated)
- Committer:
- Jdumpleton3
- Date:
- Fri Apr 21 17:33:38 2017 +0000
- Revision:
- 1:8585a8d417dc
- Parent:
- 0:b490b8486404
- Child:
- 2:27b92722246b
Get fake data working in putty. Requires PuTTy be correctly setup to list to the COM port.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Jdumpleton3 | 0:b490b8486404 | 1 | #include "mbed.h" |
Jdumpleton3 | 0:b490b8486404 | 2 | #include "rtos.h" |
Jdumpleton3 | 0:b490b8486404 | 3 | #include "hts221.h" |
Jdumpleton3 | 0:b490b8486404 | 4 | #include "LPS25H.h" |
Jdumpleton3 | 1:8585a8d417dc | 5 | #include "DataGenerator.h" |
Jdumpleton3 | 0:b490b8486404 | 6 | |
Jdumpleton3 | 0:b490b8486404 | 7 | |
Jdumpleton3 | 0:b490b8486404 | 8 | DigitalOut myled(LED1); |
Jdumpleton3 | 0:b490b8486404 | 9 | I2C i2c2(I2C_SDA, I2C_SCL); |
Jdumpleton3 | 0:b490b8486404 | 10 | |
Jdumpleton3 | 0:b490b8486404 | 11 | float tempCelsius = 25.50; |
Jdumpleton3 | 0:b490b8486404 | 12 | float humi = 55; |
Jdumpleton3 | 0:b490b8486404 | 13 | int humiMax = 100; |
Jdumpleton3 | 0:b490b8486404 | 14 | char cmd=0; |
Jdumpleton3 | 0:b490b8486404 | 15 | uint32_t seconds = 0, minutes=0, hours=0; |
Jdumpleton3 | 0:b490b8486404 | 16 | |
Jdumpleton3 | 1:8585a8d417dc | 17 | //LPS25H barometer(i2c2, LPS25H_V_CHIP_ADDR); |
Jdumpleton3 | 1:8585a8d417dc | 18 | //HTS221 humidity(I2C_SDA, I2C_SCL); |
Jdumpleton3 | 0:b490b8486404 | 19 | |
Jdumpleton3 | 1:8585a8d417dc | 20 | /* Test Data generator */ |
Jdumpleton3 | 1:8585a8d417dc | 21 | DataGenerator dataGen; |
Jdumpleton3 | 0:b490b8486404 | 22 | |
Jdumpleton3 | 1:8585a8d417dc | 23 | int main(){ |
Jdumpleton3 | 1:8585a8d417dc | 24 | //Humidity sensor setup. |
Jdumpleton3 | 1:8585a8d417dc | 25 | //humidity.init(); |
Jdumpleton3 | 1:8585a8d417dc | 26 | //humidity.calib(); |
Jdumpleton3 | 1:8585a8d417dc | 27 | |
Jdumpleton3 | 1:8585a8d417dc | 28 | printf("SOFT253 simple Temperature Humidity and Pressure Sensor Monitor\n\r"); |
Jdumpleton3 | 1:8585a8d417dc | 29 | printf("Using the X-NUCLEO-IKS01A1 shield and MBED Libraries\n\r"); |
Jdumpleton3 | 1:8585a8d417dc | 30 | |
Jdumpleton3 | 0:b490b8486404 | 31 | //printf("%#x\n\r",barometer.read_id()); |
Jdumpleton3 | 0:b490b8486404 | 32 | |
Jdumpleton3 | 1:8585a8d417dc | 33 | while(1) |
Jdumpleton3 | 0:b490b8486404 | 34 | { |
Jdumpleton3 | 1:8585a8d417dc | 35 | /*Original temperature reader from nucleo. */ |
Jdumpleton3 | 1:8585a8d417dc | 36 | //humidity.ReadTempHumi(&tempCelsius, &humi); |
Jdumpleton3 | 1:8585a8d417dc | 37 | |
Jdumpleton3 | 1:8585a8d417dc | 38 | dataGen.ReadTempHumi(&tempCelsius, &humi); |
Jdumpleton3 | 1:8585a8d417dc | 39 | |
Jdumpleton3 | 0:b490b8486404 | 40 | printf("%4.2fC %3.1f%%", tempCelsius, humi); |
Jdumpleton3 | 1:8585a8d417dc | 41 | |
Jdumpleton3 | 1:8585a8d417dc | 42 | /*Original line of code working with the nucleo barometer. */ |
Jdumpleton3 | 1:8585a8d417dc | 43 | //barometer.get(); |
Jdumpleton3 | 1:8585a8d417dc | 44 | //printf(" %6.1f %4.1f\r\n", barometer.pressure(), barometer.temperature()); |
Jdumpleton3 | 1:8585a8d417dc | 45 | |
Jdumpleton3 | 1:8585a8d417dc | 46 | printf(" %6.1f %4.1f\r\n", dataGen.pressure(), dataGen.temperature()); |
Jdumpleton3 | 1:8585a8d417dc | 47 | |
Jdumpleton3 | 1:8585a8d417dc | 48 | /* Flicker the LED. */ |
Jdumpleton3 | 0:b490b8486404 | 49 | myled = 1; // LED is ON |
Jdumpleton3 | 0:b490b8486404 | 50 | Thread::wait(200); // 200 ms NB 'Thread::wait(int d);' !!! d is in milliseconds! |
Jdumpleton3 | 0:b490b8486404 | 51 | myled = 0; // LED is OFF |
Jdumpleton3 | 0:b490b8486404 | 52 | Thread::wait(100); // 100 ms |
Jdumpleton3 | 1:8585a8d417dc | 53 | } |
Jdumpleton3 | 0:b490b8486404 | 54 | } |
Jdumpleton3 | 0:b490b8486404 | 55 | |
Jdumpleton3 | 0:b490b8486404 | 56 | |
Jdumpleton3 | 0:b490b8486404 | 57 | |
Jdumpleton3 | 0:b490b8486404 | 58 | /*#include "mbed.h" |
Jdumpleton3 | 0:b490b8486404 | 59 | |
Jdumpleton3 | 0:b490b8486404 | 60 | DigitalOut led1(LED1); |
Jdumpleton3 | 0:b490b8486404 | 61 | |
Jdumpleton3 | 0:b490b8486404 | 62 | // main() runs in its own thread in the OS |
Jdumpleton3 | 0:b490b8486404 | 63 | int main() { |
Jdumpleton3 | 0:b490b8486404 | 64 | while (true) { |
Jdumpleton3 | 0:b490b8486404 | 65 | led1 = !led1; |
Jdumpleton3 | 0:b490b8486404 | 66 | wait(0.5); |
Jdumpleton3 | 0:b490b8486404 | 67 | } |
Jdumpleton3 | 0:b490b8486404 | 68 | } |
Jdumpleton3 | 0:b490b8486404 | 69 | */ |