Rohm ml8511 hello world application
Dependencies: mbed
Fork of BD1020HFV_Hello by
main.cpp@3:42bb7dfeffb2, 2016-09-20 (annotated)
- Committer:
- MikkoZ
- Date:
- Tue Sep 20 11:06:00 2016 +0000
- Revision:
- 3:42bb7dfeffb2
- Parent:
- 2:a4e87cfd1e0a
Refactored main program.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MACRUM | 0:ee7b9cc966d7 | 1 | #include "mbed.h" |
MACRUM | 0:ee7b9cc966d7 | 2 | |
MACRUM | 0:ee7b9cc966d7 | 3 | Serial pc(USBTX, USBRX); |
MikkoZ | 2:a4e87cfd1e0a | 4 | AnalogIn sensorout(A0); |
MikkoZ | 2:a4e87cfd1e0a | 5 | DigitalOut enablesensor(A1); |
MACRUM | 0:ee7b9cc966d7 | 6 | |
MikkoZ | 3:42bb7dfeffb2 | 7 | void ml8511_print_one_value(){ |
MikkoZ | 3:42bb7dfeffb2 | 8 | float uvraw, uv; |
MikkoZ | 3:42bb7dfeffb2 | 9 | #define MIN (0.300) |
MikkoZ | 3:42bb7dfeffb2 | 10 | #define MAX (0.900) |
MikkoZ | 3:42bb7dfeffb2 | 11 | #define UVONMAX 15 |
MikkoZ | 3:42bb7dfeffb2 | 12 | uvraw = sensorout; |
MikkoZ | 3:42bb7dfeffb2 | 13 | uv = ( (UVONMAX/(MAX-MIN)) * (uvraw - MIN) ); |
MikkoZ | 3:42bb7dfeffb2 | 14 | pc.printf("UV Intensity %2.2fmW/cm^2 (raw[%2.3f])\r\n", uv, uvraw); |
MikkoZ | 3:42bb7dfeffb2 | 15 | } |
MikkoZ | 3:42bb7dfeffb2 | 16 | |
MACRUM | 0:ee7b9cc966d7 | 17 | int main() { |
MikkoZ | 2:a4e87cfd1e0a | 18 | pc.printf("\n\r"); |
MikkoZ | 2:a4e87cfd1e0a | 19 | pc.printf("ML8511 UV sensor test program.\n\r"); |
MikkoZ | 2:a4e87cfd1e0a | 20 | pc.printf("Reported UV intensity values are rough approximates.\n\r"); |
MikkoZ | 2:a4e87cfd1e0a | 21 | pc.printf("Please refer to specification page 4 for UV intensity characteristics.\n\r"); |
MikkoZ | 2:a4e87cfd1e0a | 22 | enablesensor = 1; |
MikkoZ | 2:a4e87cfd1e0a | 23 | wait_ms(1); |
MikkoZ | 2:a4e87cfd1e0a | 24 | |
MACRUM | 0:ee7b9cc966d7 | 25 | while(1) { |
MikkoZ | 3:42bb7dfeffb2 | 26 | ml8511_print_one_value(); |
MACRUM | 0:ee7b9cc966d7 | 27 | wait(0.4); |
MACRUM | 0:ee7b9cc966d7 | 28 | } |
MACRUM | 0:ee7b9cc966d7 | 29 | } |