digital light sensor using ardunio i2c pins
Dependents: LoRaWAN_singlechannel_endnode
Fork of TSL2561 by
Diff: TSL2561.cpp
- Revision:
- 2:1740d88b1edc
- Parent:
- 1:ab906ac6e90b
- Child:
- 3:0f0aa5c510e6
--- a/TSL2561.cpp Thu Jan 09 10:16:51 2014 +0000 +++ b/TSL2561.cpp Wed Jul 05 18:46:09 2017 +0000 @@ -2,14 +2,15 @@ #include "TSL2561.h" #include "mbed.h" -Serial DEBUG(USBTX, USBRX); +/*Serial DEBUG(USBTX, USBRX); #define DEBUG_PRINTX(z,x) if(z==1) DEBUG.printf(x); #define DEBUG_PRINTLNX(z,x) if(z==1) {DEBUG.printf(x); DEBUG.printf("\r\n");} #define DEBUG_PRINTXY(z,x, y) if(z==1) DEBUG.printf(x, y); #define DEBUG_PRINTLNXY(z,x, y) if(z==1) {DEBUG.printf(x, y); DEBUG.printf("\r\n");} +*/ -TSL2561::TSL2561():i2c(TSL2561_I2C_PINNAME_SDA,TSL2561_I2C_PINNAME_SCL){ +TSL2561::TSL2561():i2c(I2C_SDA, I2C_SCL){ i2c.frequency (300); _addr = TSL2561_ADDR_FLOAT; _initialized = false; @@ -17,7 +18,7 @@ _gain = TSL2561_GAIN_16X; } -TSL2561::TSL2561(uint8_t addr):i2c(TSL2561_I2C_PINNAME_SDA,TSL2561_I2C_PINNAME_SCL) { +TSL2561::TSL2561(uint8_t addr):i2c(I2C_SDA, I2C_SCL) { _addr = addr; _initialized = false; @@ -117,8 +118,9 @@ read=receivedata[0]; if (read & 0x0A ) { - DEBUG_PRINTLNXY(0,"Read 0x%x => Found TSL2561",read); + printf("Read 0x%x => Found TSL2561\r\n",read); } else { + printf("read:%x\r\n", read); return false; } _initialized = true; @@ -149,15 +151,15 @@ _t=receivedata[0]; _x=receivedata[1]; - DEBUG_PRINTLNXY(0,"_t:=0x%x",_t); - DEBUG_PRINTLNXY(0,"_x:=0x%x",_x); + /*printf("_t:=0x%x",_t); + printf("_x:=0x%x",_x); */ t=(uint16_t)_t; x=(uint16_t)_x; x <<= 8; x |= t; - DEBUG_PRINTLNXY(0,"x:= %d",x); + //printf("x:= %d\r\n",x); return x; } @@ -173,23 +175,24 @@ void TSL2561::setTiming(tsl2561IntegrationTime_t integration){ -if (!_initialized) begin(); - -else DEBUG_PRINTLNX(0,"--------------Set Timing---------"); + if (!_initialized) + begin(); + /*else + printf("--------------Set Timing---------\r\n");*/ enable(); _integration = integration; - DEBUG_PRINTLNXY(0,"Integration: 0x%x",_integration); - DEBUG_PRINTLNXY(0,"Gain: 0x%x",_gain); - DEBUG_PRINTLNXY(0,"Integration | Gain: 0x%x",_integration | _gain); + /*printf("Integration: 0x%x ",_integration); + printf("Gain: 0x%x ",_gain); + printf("Integration | Gain: 0x%x\r\n",_integration | _gain);*/ write8(TSL2561_COMMAND_BIT | TSL2561_REGISTER_TIMING, _integration | _gain); disable(); - DEBUG_PRINTLNX(0,"--------------Complete Set Timing-------------"); + //printf("--------------Complete Set Timing-------------\r\n"); //wait(1); @@ -197,22 +200,24 @@ void TSL2561::setGain(tsl2561Gain_t gain) { -if (!_initialized) begin(); -else DEBUG_PRINTLNX(0,"-------------Set Gain--------------"); + if (!_initialized) + begin(); + /*else + printf("-------------Set Gain--------------\r\n");*/ enable(); - DEBUG_PRINTLNXY(0,"Intergration: 0x%x",_integration); - DEBUG_PRINTLNXY(0,"Gain: 0x%x",_gain); - DEBUG_PRINTLNXY(0,"Intergration | Gain: 0x%x",_integration | _gain); + /*printf("Intergration: 0x%x ",_integration); + printf("Gain: 0x%x ",_gain); + printf("Intergration | Gain: 0x%x\r\n",_integration | _gain);*/ _gain = gain; write8(TSL2561_COMMAND_BIT | TSL2561_REGISTER_TIMING, _integration | _gain); //write8(TSL2561_COMMAND_BIT | TSL2561_REGISTER_TIMING, _gain); disable(); - DEBUG_PRINTLNX(0,"---------------Complete Set Gain----------------"); + //printf("---------------Complete Set Gain----------------\r\n"); //wait(1); } @@ -222,7 +227,7 @@ if (!_initialized) begin(); // Enable the device by setting the control bit to 0x03 - DEBUG_PRINTLNX(0," Power On"); + //printf("Power On\r\n"); write8(TSL2561_COMMAND_BIT | TSL2561_REGISTER_CONTROL, TSL2561_CONTROL_POWERON); } @@ -231,6 +236,6 @@ if (!_initialized) begin(); // Disable the device by setting the control bit to 0x03 - DEBUG_PRINTLNX(0," Power Off"); + //printf(" Power Off\r\n"); write8(TSL2561_COMMAND_BIT | TSL2561_REGISTER_CONTROL, TSL2561_CONTROL_POWEROFF); } \ No newline at end of file