![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
bjorken?
IOT_A4.cpp@0:1f0c0e4be56d, 2016-11-02 (annotated)
- Committer:
- co657_jnp8
- Date:
- Wed Nov 02 16:30:35 2016 +0000
- Revision:
- 0:1f0c0e4be56d
Initial commit;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
co657_jnp8 | 0:1f0c0e4be56d | 1 | /* |
co657_jnp8 | 0:1f0c0e4be56d | 2 | * (C) The University of Kent and Simon Cooksey 2015. |
co657_jnp8 | 0:1f0c0e4be56d | 3 | */ |
co657_jnp8 | 0:1f0c0e4be56d | 4 | |
co657_jnp8 | 0:1f0c0e4be56d | 5 | #include "mbed.h" |
co657_jnp8 | 0:1f0c0e4be56d | 6 | |
co657_jnp8 | 0:1f0c0e4be56d | 7 | #include "dht22.h" |
co657_jnp8 | 0:1f0c0e4be56d | 8 | |
co657_jnp8 | 0:1f0c0e4be56d | 9 | Serial host(USBTX, USBRX); |
co657_jnp8 | 0:1f0c0e4be56d | 10 | DHT22 dht22(PTB18); |
co657_jnp8 | 0:1f0c0e4be56d | 11 | |
co657_jnp8 | 0:1f0c0e4be56d | 12 | |
co657_jnp8 | 0:1f0c0e4be56d | 13 | int main() |
co657_jnp8 | 0:1f0c0e4be56d | 14 | { |
co657_jnp8 | 0:1f0c0e4be56d | 15 | host.baud(38400); |
co657_jnp8 | 0:1f0c0e4be56d | 16 | DHT22_data_t dht22_data; |
co657_jnp8 | 0:1f0c0e4be56d | 17 | host.printf("\r\n\r\nhello world\r\n"); |
co657_jnp8 | 0:1f0c0e4be56d | 18 | while (true) { |
co657_jnp8 | 0:1f0c0e4be56d | 19 | dht22.read(&dht22_data); |
co657_jnp8 | 0:1f0c0e4be56d | 20 | |
co657_jnp8 | 0:1f0c0e4be56d | 21 | float temperature = dht22_data.temp / 10.0f; |
co657_jnp8 | 0:1f0c0e4be56d | 22 | float humidity = dht22_data.humidity / 10.0f; |
co657_jnp8 | 0:1f0c0e4be56d | 23 | |
co657_jnp8 | 0:1f0c0e4be56d | 24 | int check = (dht22_data.humidity/10) + (dht22_data.humidity%10) + (dht22_data.temp/10) + (dht22_data.temp%10); |
co657_jnp8 | 0:1f0c0e4be56d | 25 | |
co657_jnp8 | 0:1f0c0e4be56d | 26 | //host.lock (); |
co657_jnp8 | 0:1f0c0e4be56d | 27 | // host.printf("Temperature: %2.2f Humidity: %2.2f%%\r\n", temperature, humidity);//, dht22_data.checksum, 0xff & check); |
co657_jnp8 | 0:1f0c0e4be56d | 28 | host.printf("Temperature: %d (%2.2f) Humidity: %d (%2.2f)\r\n", dht22_data.temp, temperature, dht22_data.humidity, humidity);//, dht22_data.checksum, 0xff & check); |
co657_jnp8 | 0:1f0c0e4be56d | 29 | //host.unlock (); |
co657_jnp8 | 0:1f0c0e4be56d | 30 | |
co657_jnp8 | 0:1f0c0e4be56d | 31 | // host.printf("0x%04X\t\t0x%04X\t\t0x%02X\r\n", 0xFFFF & dht22_data.temp, 0xFFFF & dht22_data.humidity, 0xFF & dht22_data.checksum); |
co657_jnp8 | 0:1f0c0e4be56d | 32 | |
co657_jnp8 | 0:1f0c0e4be56d | 33 | wait_ms(1000); |
co657_jnp8 | 0:1f0c0e4be56d | 34 | } |
co657_jnp8 | 0:1f0c0e4be56d | 35 | } |