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

Files at this revision

API Documentation at this revision

Comitter:
batman52
Date:
Tue Dec 03 19:05:40 2019 +0000
Parent:
79:0431b9fd3dc0
Commit message:
example of light sensor for NXP Rapid IoT prototyping kit

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-tsl2572.lib Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Sat Nov 23 18:03:20 2019 +0000
+++ b/main.cpp	Tue Dec 03 19:05:40 2019 +0000
@@ -1,32 +1,23 @@
 #include "mbed.h"
-
-DigitalOut rgb_red(LED_RED, 1);       //     LED1 = LED_RED,  1 --> OFF, 0 --> ON
-DigitalOut rgb_blue(LED_BLUE, 1);     //     LED3 = LED_BLUE, 1 --> OFF, 0 --> ON
-DigitalOut rgb_green(PTE7,1);         //                      1 --> OFF, 0 --> ON
-
-void rgb_sel(int8_t idx) {
+#include "TSL2572Sensor.h"
 
-switch(idx) {
-                case 0:
-                    rgb_red = 0; rgb_blue=1; rgb_green = 1;
-                    break;
-                case 1:
-                    rgb_red = 1; rgb_blue=0; rgb_green = 1;
-                    break;
-                case 2:
-                    rgb_red = 1; rgb_blue=1; rgb_green = 0;
-                    break;
-            }
-    
-}
+static TSL2572Sensor tsl2572(I2C_SDA, I2C_SCL);
 
 // main() runs in its own thread in the OS
 int main() {
-    int idx;
-    while (true) {
-        for(idx=0;idx<3;idx++) {
-            rgb_sel(idx);
-            wait(0.5);
-        }        
+    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);   
     }
 }
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-tsl2572.lib	Tue Dec 03 19:05:40 2019 +0000
@@ -0,0 +1,1 @@
+https://github.com/janjongboom/mbed-tsl2572/#05cc610ea7988201100fdf1e77f062c5cc387361