mariozavršni
Dependencies: DHT TextLCD mbed
Fork of temperaturaivlaga by
main.cpp@0:296aeee1e970, 2016-12-22 (annotated)
- Committer:
- kgrdosic
- Date:
- Thu Dec 22 13:50:20 2016 +0000
- Revision:
- 0:296aeee1e970
zadatak
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kgrdosic | 0:296aeee1e970 | 1 | #include "mbed.h" |
kgrdosic | 0:296aeee1e970 | 2 | #include "TextLCD.h" |
kgrdosic | 0:296aeee1e970 | 3 | #include "DHT.h" |
kgrdosic | 0:296aeee1e970 | 4 | |
kgrdosic | 0:296aeee1e970 | 5 | TextLCD lcd(p19, p20, p21, p22, p23, p24, TextLCD::LCD8x2); |
kgrdosic | 0:296aeee1e970 | 6 | DHT sensor(p26, DHT11); |
kgrdosic | 0:296aeee1e970 | 7 | DigitalOut myled(p25); |
kgrdosic | 0:296aeee1e970 | 8 | AnalogIn Ain(p17); |
kgrdosic | 0:296aeee1e970 | 9 | |
kgrdosic | 0:296aeee1e970 | 10 | int err; |
kgrdosic | 0:296aeee1e970 | 11 | float c, h, alarm; |
kgrdosic | 0:296aeee1e970 | 12 | int main() |
kgrdosic | 0:296aeee1e970 | 13 | { |
kgrdosic | 0:296aeee1e970 | 14 | while (1) { |
kgrdosic | 0:296aeee1e970 | 15 | wait(2); |
kgrdosic | 0:296aeee1e970 | 16 | err = sensor.readData(); |
kgrdosic | 0:296aeee1e970 | 17 | alarm=Ain*50.0; |
kgrdosic | 0:296aeee1e970 | 18 | if (err == 0) { |
kgrdosic | 0:296aeee1e970 | 19 | c = sensor.ReadTemperature(CELCIUS); |
kgrdosic | 0:296aeee1e970 | 20 | h = sensor.ReadHumidity(); |
kgrdosic | 0:296aeee1e970 | 21 | lcd.locate(0, 0); |
kgrdosic | 0:296aeee1e970 | 22 | lcd.printf("T %3.1f ", c); |
kgrdosic | 0:296aeee1e970 | 23 | lcd.locate(1, 1); |
kgrdosic | 0:296aeee1e970 | 24 | lcd.printf("H %3.1f ", h); |
kgrdosic | 0:296aeee1e970 | 25 | if(c>alarm) { |
kgrdosic | 0:296aeee1e970 | 26 | myled=true; |
kgrdosic | 0:296aeee1e970 | 27 | } else { |
kgrdosic | 0:296aeee1e970 | 28 | myled=false; |
kgrdosic | 0:296aeee1e970 | 29 | } |
kgrdosic | 0:296aeee1e970 | 30 | wait(0.5); |
kgrdosic | 0:296aeee1e970 | 31 | } |
kgrdosic | 0:296aeee1e970 | 32 | } |
kgrdosic | 0:296aeee1e970 | 33 | } |