![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
UV index meter
See http://developer.mbed.org/users/yasuyuki/notebook/UVindex/
main.cpp@0:cdf856d3c0b7, 2014-10-08 (annotated)
- Committer:
- yasuyuki
- Date:
- Wed Oct 08 02:40:33 2014 +0000
- Revision:
- 0:cdf856d3c0b7
first release
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yasuyuki | 0:cdf856d3c0b7 | 1 | //********************** |
yasuyuki | 0:cdf856d3c0b7 | 2 | // UV index meter for mbed with ML8511 |
yasuyuki | 0:cdf856d3c0b7 | 3 | // |
yasuyuki | 0:cdf856d3c0b7 | 4 | // UV index |
yasuyuki | 0:cdf856d3c0b7 | 5 | // Extreme 11+ |
yasuyuki | 0:cdf856d3c0b7 | 6 | // Very High 8-10 |
yasuyuki | 0:cdf856d3c0b7 | 7 | // High 6-7 |
yasuyuki | 0:cdf856d3c0b7 | 8 | // Moderate 3-5 |
yasuyuki | 0:cdf856d3c0b7 | 9 | // Low 0-2 |
yasuyuki | 0:cdf856d3c0b7 | 10 | // |
yasuyuki | 0:cdf856d3c0b7 | 11 | // LPC1768 flash=512KB, ADC=12bits |
yasuyuki | 0:cdf856d3c0b7 | 12 | // LPC11U35 flash=64KB, ADC=10bits |
yasuyuki | 0:cdf856d3c0b7 | 13 | // Nucleo ADC=12bits |
yasuyuki | 0:cdf856d3c0b7 | 14 | // |
yasuyuki | 0:cdf856d3c0b7 | 15 | // (C)Copyright 2014 All rights reserved by Y.Onodera |
yasuyuki | 0:cdf856d3c0b7 | 16 | // http://einstlab.web.fc2.com |
yasuyuki | 0:cdf856d3c0b7 | 17 | //********************** |
yasuyuki | 0:cdf856d3c0b7 | 18 | #include "mbed.h" |
yasuyuki | 0:cdf856d3c0b7 | 19 | #include "AQM0802.h" |
yasuyuki | 0:cdf856d3c0b7 | 20 | |
yasuyuki | 0:cdf856d3c0b7 | 21 | //#pragma O0 |
yasuyuki | 0:cdf856d3c0b7 | 22 | //#pragma O1 |
yasuyuki | 0:cdf856d3c0b7 | 23 | //#pragma O2 // default |
yasuyuki | 0:cdf856d3c0b7 | 24 | //#pragma O3 |
yasuyuki | 0:cdf856d3c0b7 | 25 | //#pragma Otime |
yasuyuki | 0:cdf856d3c0b7 | 26 | //#pragma Ospace |
yasuyuki | 0:cdf856d3c0b7 | 27 | |
yasuyuki | 0:cdf856d3c0b7 | 28 | |
yasuyuki | 0:cdf856d3c0b7 | 29 | #if defined(TARGET_LPC1768) |
yasuyuki | 0:cdf856d3c0b7 | 30 | I2C i2c(p28,p27); |
yasuyuki | 0:cdf856d3c0b7 | 31 | AnalogIn ain(p15); |
yasuyuki | 0:cdf856d3c0b7 | 32 | #endif |
yasuyuki | 0:cdf856d3c0b7 | 33 | // for TG-LPC11U35-501 |
yasuyuki | 0:cdf856d3c0b7 | 34 | #if defined(TARGET_LPC11U35_501) |
yasuyuki | 0:cdf856d3c0b7 | 35 | I2C i2c(P0_5,P0_4); |
yasuyuki | 0:cdf856d3c0b7 | 36 | AnalogIn ain(P0_11); |
yasuyuki | 0:cdf856d3c0b7 | 37 | #endif |
yasuyuki | 0:cdf856d3c0b7 | 38 | // for Nucleo |
yasuyuki | 0:cdf856d3c0b7 | 39 | #if defined(TARGET_NUCLEO_F401RE) |
yasuyuki | 0:cdf856d3c0b7 | 40 | I2C i2c(D14,D15); |
yasuyuki | 0:cdf856d3c0b7 | 41 | AnalogIn ain(PA_0); |
yasuyuki | 0:cdf856d3c0b7 | 42 | #endif |
yasuyuki | 0:cdf856d3c0b7 | 43 | |
yasuyuki | 0:cdf856d3c0b7 | 44 | AQM0802 lcd(i2c); |
yasuyuki | 0:cdf856d3c0b7 | 45 | |
yasuyuki | 0:cdf856d3c0b7 | 46 | int main() { |
yasuyuki | 0:cdf856d3c0b7 | 47 | |
yasuyuki | 0:cdf856d3c0b7 | 48 | char msg[10]; |
yasuyuki | 0:cdf856d3c0b7 | 49 | float UV; |
yasuyuki | 0:cdf856d3c0b7 | 50 | |
yasuyuki | 0:cdf856d3c0b7 | 51 | sprintf(msg, "UV index"); |
yasuyuki | 0:cdf856d3c0b7 | 52 | lcd.locate(0,0); |
yasuyuki | 0:cdf856d3c0b7 | 53 | lcd.print(msg); |
yasuyuki | 0:cdf856d3c0b7 | 54 | |
yasuyuki | 0:cdf856d3c0b7 | 55 | while(1) { |
yasuyuki | 0:cdf856d3c0b7 | 56 | |
yasuyuki | 0:cdf856d3c0b7 | 57 | // UV index |
yasuyuki | 0:cdf856d3c0b7 | 58 | // 1V=0 |
yasuyuki | 0:cdf856d3c0b7 | 59 | // 2V=10 |
yasuyuki | 0:cdf856d3c0b7 | 60 | UV = (ain.read()*3.3-1.0)/(2.0-1.0)*10.0; |
yasuyuki | 0:cdf856d3c0b7 | 61 | |
yasuyuki | 0:cdf856d3c0b7 | 62 | sprintf(msg,"%4.1f",UV); |
yasuyuki | 0:cdf856d3c0b7 | 63 | lcd.locate(0,1); |
yasuyuki | 0:cdf856d3c0b7 | 64 | lcd.print(msg); |
yasuyuki | 0:cdf856d3c0b7 | 65 | wait(1); |
yasuyuki | 0:cdf856d3c0b7 | 66 | } |
yasuyuki | 0:cdf856d3c0b7 | 67 | |
yasuyuki | 0:cdf856d3c0b7 | 68 | } |
yasuyuki | 0:cdf856d3c0b7 | 69 |