Weather Alert System
Fork of WeatherMeters by
main.cpp@3:7db4d6319754, 2013-04-29 (annotated)
- Committer:
- yongqiangwang
- Date:
- Mon Apr 29 23:39:45 2013 +0000
- Revision:
- 3:7db4d6319754
Weather Alert System
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yongqiangwang | 3:7db4d6319754 | 1 | #include "mbed.h" |
yongqiangwang | 3:7db4d6319754 | 2 | #include "SCP1000.h" |
yongqiangwang | 3:7db4d6319754 | 3 | #include "SHTx/sht15.hpp" |
yongqiangwang | 3:7db4d6319754 | 4 | #include "WeatherMeters.h" |
yongqiangwang | 3:7db4d6319754 | 5 | |
yongqiangwang | 3:7db4d6319754 | 6 | Serial Xbee1(p13, p14); |
yongqiangwang | 3:7db4d6319754 | 7 | DigitalOut rst1(p16); |
yongqiangwang | 3:7db4d6319754 | 8 | |
yongqiangwang | 3:7db4d6319754 | 9 | SCP1000 scp1000(p5,p6,p7,p17); |
yongqiangwang | 3:7db4d6319754 | 10 | |
yongqiangwang | 3:7db4d6319754 | 11 | SHTx::SHT15 sensor(p28, p27); |
yongqiangwang | 3:7db4d6319754 | 12 | |
yongqiangwang | 3:7db4d6319754 | 13 | AnalogIn ain(p20); |
yongqiangwang | 3:7db4d6319754 | 14 | DigitalOut busy(LED1); |
yongqiangwang | 3:7db4d6319754 | 15 | |
yongqiangwang | 3:7db4d6319754 | 16 | Serial pc(USBTX, USBRX); |
yongqiangwang | 3:7db4d6319754 | 17 | |
yongqiangwang | 3:7db4d6319754 | 18 | WeatherMeters station(p8, p15, p10, Weather_auto); |
yongqiangwang | 3:7db4d6319754 | 19 | |
yongqiangwang | 3:7db4d6319754 | 20 | float w_speed = 0.0; |
yongqiangwang | 3:7db4d6319754 | 21 | float w_direction = 0.0; |
yongqiangwang | 3:7db4d6319754 | 22 | float w_raingauge = 0.0; |
yongqiangwang | 3:7db4d6319754 | 23 | |
yongqiangwang | 3:7db4d6319754 | 24 | char a = 'T'; |
yongqiangwang | 3:7db4d6319754 | 25 | char data[15]; |
yongqiangwang | 3:7db4d6319754 | 26 | |
yongqiangwang | 3:7db4d6319754 | 27 | void xbeesend(float x) |
yongqiangwang | 3:7db4d6319754 | 28 | { |
yongqiangwang | 3:7db4d6319754 | 29 | sprintf(data, "%5.1f", x); |
yongqiangwang | 3:7db4d6319754 | 30 | |
yongqiangwang | 3:7db4d6319754 | 31 | int i = 0; |
yongqiangwang | 3:7db4d6319754 | 32 | while (data[i] != NULL) |
yongqiangwang | 3:7db4d6319754 | 33 | { |
yongqiangwang | 3:7db4d6319754 | 34 | Xbee1.putc(data[i]); |
yongqiangwang | 3:7db4d6319754 | 35 | i++; |
yongqiangwang | 3:7db4d6319754 | 36 | } |
yongqiangwang | 3:7db4d6319754 | 37 | |
yongqiangwang | 3:7db4d6319754 | 38 | Xbee1.putc (' '); |
yongqiangwang | 3:7db4d6319754 | 39 | } |
yongqiangwang | 3:7db4d6319754 | 40 | |
yongqiangwang | 3:7db4d6319754 | 41 | int main() { |
yongqiangwang | 3:7db4d6319754 | 42 | |
yongqiangwang | 3:7db4d6319754 | 43 | rst1 = 0; //Set reset pin to 0 |
yongqiangwang | 3:7db4d6319754 | 44 | wait_ms(1); |
yongqiangwang | 3:7db4d6319754 | 45 | rst1 = 1; //Set reset pin to 1 |
yongqiangwang | 3:7db4d6319754 | 46 | wait_ms(1); |
yongqiangwang | 3:7db4d6319754 | 47 | |
yongqiangwang | 3:7db4d6319754 | 48 | while(1) { |
yongqiangwang | 3:7db4d6319754 | 49 | |
yongqiangwang | 3:7db4d6319754 | 50 | w_speed = station.get_windspeed(); |
yongqiangwang | 3:7db4d6319754 | 51 | w_direction = station.get_windvane(); |
yongqiangwang | 3:7db4d6319754 | 52 | w_raingauge = station.get_raingauge(); |
yongqiangwang | 3:7db4d6319754 | 53 | |
yongqiangwang | 3:7db4d6319754 | 54 | pc.printf("Wind speed: %4.1f m/s\r\n", w_speed); |
yongqiangwang | 3:7db4d6319754 | 55 | Xbee1.putc ('S'); |
yongqiangwang | 3:7db4d6319754 | 56 | xbeesend (w_speed); |
yongqiangwang | 3:7db4d6319754 | 57 | |
yongqiangwang | 3:7db4d6319754 | 58 | pc.printf("Wind direction: %4.0f\r\n", w_direction); |
yongqiangwang | 3:7db4d6319754 | 59 | xbeesend (w_direction); |
yongqiangwang | 3:7db4d6319754 | 60 | |
yongqiangwang | 3:7db4d6319754 | 61 | pc.printf("Rain Gauge: %4.1f\r\n\n", w_raingauge); |
yongqiangwang | 3:7db4d6319754 | 62 | xbeesend (w_raingauge); |
yongqiangwang | 3:7db4d6319754 | 63 | |
yongqiangwang | 3:7db4d6319754 | 64 | |
yongqiangwang | 3:7db4d6319754 | 65 | busy = true; |
yongqiangwang | 3:7db4d6319754 | 66 | sensor.update(); |
yongqiangwang | 3:7db4d6319754 | 67 | busy = false; |
yongqiangwang | 3:7db4d6319754 | 68 | |
yongqiangwang | 3:7db4d6319754 | 69 | sensor.setOTPReload(false); |
yongqiangwang | 3:7db4d6319754 | 70 | sensor.setResolution(true); |
yongqiangwang | 3:7db4d6319754 | 71 | |
yongqiangwang | 3:7db4d6319754 | 72 | sensor.setScale(false); |
yongqiangwang | 3:7db4d6319754 | 73 | pc.printf("Temperature [ %3.1f C ]\r\n", sensor.getTemperature()); |
yongqiangwang | 3:7db4d6319754 | 74 | |
yongqiangwang | 3:7db4d6319754 | 75 | xbeesend (sensor.getTemperature()); |
yongqiangwang | 3:7db4d6319754 | 76 | |
yongqiangwang | 3:7db4d6319754 | 77 | pc.printf("Humdity [ %3.1f %% ]\r\n\n", sensor.getHumidity()); |
yongqiangwang | 3:7db4d6319754 | 78 | xbeesend (sensor.getHumidity()); |
yongqiangwang | 3:7db4d6319754 | 79 | |
yongqiangwang | 3:7db4d6319754 | 80 | pc.printf("The pressure is %d Pa \r\n\n", scp1000.readPressure()); |
yongqiangwang | 3:7db4d6319754 | 81 | xbeesend (scp1000.readPressure()); |
yongqiangwang | 3:7db4d6319754 | 82 | |
yongqiangwang | 3:7db4d6319754 | 83 | pc.printf("Sun light intensity is %3.1f %%\r\n\n", ain * 100); |
yongqiangwang | 3:7db4d6319754 | 84 | xbeesend (ain * 100); |
yongqiangwang | 3:7db4d6319754 | 85 | |
yongqiangwang | 3:7db4d6319754 | 86 | Xbee1.putc ('@'); |
yongqiangwang | 3:7db4d6319754 | 87 | |
yongqiangwang | 3:7db4d6319754 | 88 | wait(5); |
yongqiangwang | 3:7db4d6319754 | 89 | } |
yongqiangwang | 3:7db4d6319754 | 90 | } |
yongqiangwang | 3:7db4d6319754 | 91 |