![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
AM2321 sample
Dependencies: AM2321 AQM0802 mbed
See http://developer.mbed.org/users/yasuyuki/notebook/AM2321/
main.cpp@1:6b82bfcbd184, 2015-07-10 (annotated)
- Committer:
- yasuyuki
- Date:
- Fri Jul 10 15:09:55 2015 +0000
- Revision:
- 1:6b82bfcbd184
- Parent:
- 0:45db9d35cbce
minus
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yasuyuki | 0:45db9d35cbce | 1 | //********************** |
yasuyuki | 0:45db9d35cbce | 2 | // Hygrometer and Thermometer for mbed |
yasuyuki | 0:45db9d35cbce | 3 | // |
yasuyuki | 0:45db9d35cbce | 4 | // LPC1768 flash=512KB, ADC=12bits |
yasuyuki | 0:45db9d35cbce | 5 | // LPC11U35 flash=64KB, ADC=10bits |
yasuyuki | 0:45db9d35cbce | 6 | // Nucleo ADC=12bits |
yasuyuki | 0:45db9d35cbce | 7 | // |
yasuyuki | 0:45db9d35cbce | 8 | // (C)Copyright 2014 All rights reserved by Y.Onodera |
yasuyuki | 0:45db9d35cbce | 9 | // http://einstlab.web.fc2.com |
yasuyuki | 0:45db9d35cbce | 10 | //********************** |
yasuyuki | 0:45db9d35cbce | 11 | #include "mbed.h" |
yasuyuki | 0:45db9d35cbce | 12 | #include "AQM0802.h" |
yasuyuki | 0:45db9d35cbce | 13 | #include "AM2321.h" |
yasuyuki | 0:45db9d35cbce | 14 | |
yasuyuki | 0:45db9d35cbce | 15 | #if defined(TARGET_LPC1768) |
yasuyuki | 0:45db9d35cbce | 16 | I2C i2c(p28,p27); |
yasuyuki | 0:45db9d35cbce | 17 | #endif |
yasuyuki | 0:45db9d35cbce | 18 | // for TG-LPC11U35-501 |
yasuyuki | 0:45db9d35cbce | 19 | #if defined(TARGET_LPC11U35_501) |
yasuyuki | 0:45db9d35cbce | 20 | I2C i2c(P0_5,P0_4); |
yasuyuki | 0:45db9d35cbce | 21 | #endif |
yasuyuki | 0:45db9d35cbce | 22 | // for Nucleo |
yasuyuki | 0:45db9d35cbce | 23 | #if defined(TARGET_NUCLEO_F401RE) |
yasuyuki | 0:45db9d35cbce | 24 | I2C i2c(D14,D15); |
yasuyuki | 0:45db9d35cbce | 25 | #endif |
yasuyuki | 0:45db9d35cbce | 26 | |
yasuyuki | 0:45db9d35cbce | 27 | AQM0802 lcd(i2c); |
yasuyuki | 0:45db9d35cbce | 28 | AM2321 am2321(i2c); |
yasuyuki | 0:45db9d35cbce | 29 | |
yasuyuki | 0:45db9d35cbce | 30 | int main() { |
yasuyuki | 0:45db9d35cbce | 31 | |
yasuyuki | 0:45db9d35cbce | 32 | char msg[10]; |
yasuyuki | 0:45db9d35cbce | 33 | int h; |
yasuyuki | 0:45db9d35cbce | 34 | int t; |
yasuyuki | 0:45db9d35cbce | 35 | |
yasuyuki | 0:45db9d35cbce | 36 | while(1) { |
yasuyuki | 0:45db9d35cbce | 37 | |
yasuyuki | 0:45db9d35cbce | 38 | h = am2321.humidity(); |
yasuyuki | 1:6b82bfcbd184 | 39 | sprintf(msg,"%4.1f%% ",h/10.0); |
yasuyuki | 0:45db9d35cbce | 40 | lcd.locate(0,0); |
yasuyuki | 0:45db9d35cbce | 41 | lcd.print(msg); |
yasuyuki | 0:45db9d35cbce | 42 | |
yasuyuki | 0:45db9d35cbce | 43 | t = am2321.temperature(); |
yasuyuki | 1:6b82bfcbd184 | 44 | sprintf(msg,"%4.1fC ",t/10.0); |
yasuyuki | 0:45db9d35cbce | 45 | lcd.locate(0,1); |
yasuyuki | 0:45db9d35cbce | 46 | lcd.print(msg); |
yasuyuki | 0:45db9d35cbce | 47 | |
yasuyuki | 0:45db9d35cbce | 48 | wait(1); |
yasuyuki | 0:45db9d35cbce | 49 | } |
yasuyuki | 0:45db9d35cbce | 50 | |
yasuyuki | 0:45db9d35cbce | 51 | } |