![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
DHT11 sensor test for Stage 1 Engineering at the University of York
Dependencies: DHT11 UoY-serial
main.cpp@2:789cc1bc1adc, 2021-09-16 (annotated)
- Committer:
- ajp109
- Date:
- Thu Sep 16 15:37:20 2021 +0000
- Revision:
- 2:789cc1bc1adc
- Parent:
- 1:acb591685a28
Initial commit of DHT11-test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ajp109 | 0:77209603a6fe | 1 | #include "mbed.h" |
ajp109 | 2:789cc1bc1adc | 2 | #include "UoY-serial.h" |
ajp109 | 2:789cc1bc1adc | 3 | #include "DHT11.h" |
ajp109 | 0:77209603a6fe | 4 | |
ajp109 | 2:789cc1bc1adc | 5 | // D2 is the data pin name on the Nucleo board |
ajp109 | 2:789cc1bc1adc | 6 | DHT11 sensor(D2); |
ajp109 | 1:acb591685a28 | 7 | |
ajp109 | 0:77209603a6fe | 8 | int main() |
ajp109 | 0:77209603a6fe | 9 | { |
ajp109 | 2:789cc1bc1adc | 10 | while(true) { |
ajp109 | 2:789cc1bc1adc | 11 | // Print temperature and humidity |
ajp109 | 2:789cc1bc1adc | 12 | printf("Temp: %d\n", sensor.readTemperature()); |
ajp109 | 2:789cc1bc1adc | 13 | printf(" RH: %d%%\n", sensor.readHumidity()); |
ajp109 | 2:789cc1bc1adc | 14 | |
ajp109 | 2:789cc1bc1adc | 15 | // Wait 2 seconds before doing it again |
ajp109 | 2:789cc1bc1adc | 16 | thread_sleep_for(2000); |
ajp109 | 1:acb591685a28 | 17 | } |
ajp109 | 0:77209603a6fe | 18 | } |
ajp109 | 2:789cc1bc1adc | 19 |