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

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "TSL2572Sensor.h"
00003 
00004 static TSL2572Sensor tsl2572(I2C_SDA, I2C_SCL);
00005 
00006 // main() runs in its own thread in the OS
00007 int main() {
00008     uint8_t id;
00009     float lux;
00010     
00011     // make sure to check the return values (should be 0)
00012     tsl2572.init();
00013     tsl2572.enable();
00014     
00015     while (true) {           
00016         tsl2572.read_id(&id);
00017         printf("TSL2572 light intensity ID = 0x%X\r\n", id);
00018 
00019         tsl2572.read_ambient_light(&lux);
00020         printf("TSL2572: [lght] %.2f lux\r\n", lux);  
00021         wait(0.5);   
00022     }
00023 }