Adafruit TSL2591 sensor

Dependencies:   mbed

Revision:
1:308cc5302475
Parent:
0:815555c72774
Child:
2:dd10c541a3dc
--- a/TSL2591.cpp	Sun Mar 13 03:10:20 2016 +0000
+++ b/TSL2591.cpp	Sun Mar 13 19:08:41 2016 +0000
@@ -19,8 +19,8 @@
         _i2c.read(_addr<<1, read, 1, 0);
         if(read[0] == TSL2591_ID) {
             _init = true;
-            setGain(TSL2591_GAIN_HIGH);
-            setIntegration(TSL2591_INTT_100MS);
+            setGain(TSL2591_GAIN_MED);
+            setTime(TSL2591_INTT_100MS);
             disable();
             return true;
         }
@@ -49,7 +49,7 @@
     disable();
 }
 
-void TSL2591::setIntegration(tsl2591IntegrationTime_t integ)
+void TSL2591::setTime(tsl2591IntegrationTime_t integ)
 {
     enable();
     _integ = integ;
@@ -61,18 +61,18 @@
 void TSL2591::getALS(void)
 {
     enable();
-    for(uint8_t t=0; t<=_integ; t++) {
-        wait(.12);
+    for(uint8_t t=0; t<=_integ+1; t++) {
+        wait(0.12);
     }
-    char write1[] = {(TSL2591_CMD_BIT|TSL2591_REG_CHAN1_H)};
+    char write1[] = {(TSL2591_CMD_BIT|TSL2591_REG_CHAN1_L)};
     _i2c.write(_addr<<1, write1, 1, 0);
     char read1[2];
     _i2c.read(_addr<<1, read1, 2, 0);
-    char write2[] = {(TSL2591_CMD_BIT|TSL2591_REG_CHAN0_H)};
+    char write2[] = {(TSL2591_CMD_BIT|TSL2591_REG_CHAN0_L)};
     _i2c.write(_addr<<1, write2, 1, 0);
     char read2[2];
     _i2c.read(_addr<<1, read2, 2, 0);
-    printf("%d\n",(((read1[0]<<8)|read1[1])<<16)|((read2[0]<<8)|read2[1]));
+    printf("%d \t %d\n",(((read1[0]<<8)|read1[1])),((read2[0]<<8)|read2[1]));
     disable();
 }