Rohm ml8511 hello world application

Dependencies:   mbed

Fork of BD1020HFV_Hello by Rohm

main.cpp

Committer:
MikkoZ
Date:
2016-09-13
Revision:
2:a4e87cfd1e0a
Parent:
1:ba7e525074f9
Child:
3:42bb7dfeffb2

File content as of revision 2:a4e87cfd1e0a:

#include "mbed.h"

Serial pc(USBTX, USBRX);
AnalogIn sensorout(A0);
DigitalOut enablesensor(A1);

int main() {
    pc.printf("\n\r");
    pc.printf("ML8511 UV sensor test program.\n\r");
    pc.printf("Reported UV intensity values are rough approximates.\n\r");
    pc.printf("Please refer to specification page 4 for UV intensity characteristics.\n\r");
    enablesensor = 1;
    wait_ms(1);
    
    while(1) {
        float uvraw, uv;
        #define MIN (0.300)
        #define MAX (0.900)
        #define UVONMAX 15
        uvraw = sensorout;
        uv = ( (UVONMAX/(MAX-MIN)) * (uvraw - MIN) );
        pc.printf("UV Intensity %2.2fmW/cm^2 (raw[%2.3f])\r\n", uv, uvraw);
        wait(0.4);
    }
}