Light sensor example for NXP Rapid IoT prototyping kit. Read more at https://www.hackster.io/marcomerli/riotwear-mbed-2b2011.

main.cpp

Committer:
batman52
Date:
2019-12-03
Revision:
80:a8e5911d59f5
Parent:
79:0431b9fd3dc0

File content as of revision 80:a8e5911d59f5:

#include "mbed.h"
#include "TSL2572Sensor.h"

static TSL2572Sensor tsl2572(I2C_SDA, I2C_SCL);

// main() runs in its own thread in the OS
int main() {
    uint8_t id;
    float lux;
    
    // make sure to check the return values (should be 0)
    tsl2572.init();
    tsl2572.enable();
    
    while (true) {           
        tsl2572.read_id(&id);
        printf("TSL2572 light intensity ID = 0x%X\r\n", id);

        tsl2572.read_ambient_light(&lux);
        printf("TSL2572: [lght] %.2f lux\r\n", lux);  
        wait(0.5);   
    }
}