An example to use an AM2303 (a.k.a. DHT22) humidity sensor
Dependencies: AM2303 TextLCD mbed
Revision 0:a1cd181526fc, committed 2014-10-13
- Comitter:
- s_inoue_mbed
- Date:
- Mon Oct 13 14:24:24 2014 +0000
- Commit message:
- An example program to use an AM2303 humidity sensor.
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/AM2303.lib Mon Oct 13 14:24:24 2014 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/s_inoue_mbed/code/AM2303/#1ad0612823e9
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TextLCD.lib Mon Oct 13 14:24:24 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/simon/code/TextLCD/#308d188a2d3a
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Mon Oct 13 14:24:24 2014 +0000
@@ -0,0 +1,62 @@
+/* Copyright (c) 2014 Shigenori Inoue, MIT License
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute,
+ * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies or
+ * substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
+ * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "mbed.h"
+#include "TextLCD.h"
+#include "AM2303.h"
+
+/* LEDs for debugging */
+BusOut leds(LED4, LED3, LED2, LED1);
+
+/* LCD module */
+TextLCD lcd(p25, p24, p12, p13, p14, p23);
+
+/* Humidity sensor */
+AM2303 h(p18);
+
+/* The main function */
+int main()
+{
+ /* Variables */
+ int state;
+
+ /* Show splash screen */
+ lcd.cls();
+ lcd.locate(0, 0);
+ lcd.printf("AM2303 Humidity");
+
+ /* Infinate loop */
+ while(true) {
+ /* Wait for measurement */
+ wait(2.0);
+
+ /* Read the measured results */
+ state = h.readData();
+
+ /* Show the data, otherwise error */
+ lcd.locate(0, 1);
+ if (state != AM2303::OK) {
+ lcd.printf("<Error: %d>", state);
+ } else {
+ lcd.printf("T:%2.1fC, H:%2.1f%%", h.readTemperature(), h.readHumidity());
+ }
+
+ /* Blink LED for Debug */
+ leds = leds + 1;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Mon Oct 13 14:24:24 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/552587b429a1 \ No newline at end of file
Shigenori Inoue