VL6180x library
Fork of VL6180x_lib by
Revision 1:35a996054c44, committed 2016-02-17
- Comitter:
- j_j205
- Date:
- Wed Feb 17 16:47:44 2016 +0000
- Parent:
- 0:84fb42fedc5b
- Commit message:
- 2/17/16 JJ
Changed in this revision
VL6180x.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 84fb42fedc5b -r 35a996054c44 VL6180x.h --- a/VL6180x.h Tue Jul 07 20:36:43 2015 +0000 +++ b/VL6180x.h Wed Feb 17 16:47:44 2016 +0000 @@ -31,6 +31,98 @@ * * Distributed as-is; no warranty is given. */ +/** +* VL6180x tof/als sensor example +* +* @code +#include "mbed.h" +#include <VL6180x.h> + +const float GAIN_1 = 1.01; // Actual ALS Gain of 1.01 +const float GAIN_1_25 = 1.28; // Actual ALS Gain of 1.28 +const float GAIN_1_67 = 1.72; // Actual ALS Gain of 1.72 +const float GAIN_2_5 = 2.6; // Actual ALS Gain of 2.60 +const float GAIN_5 = 5.21; // Actual ALS Gain of 5.21 +const float GAIN_10 = 10.32; // Actual ALS Gain of 10.32 +const float GAIN_20 = 20; // Actual ALS Gain of 20 +const float GAIN_40 = 40; // Actual ALS Gain of 40 + + +#define VL6180X_ADDRESS 0x29 + +VL6180xIdentification identification; +// mbed uses 8bit addresses shift address by 1 bit left +VL6180x sensor(D14, D15, VL6180X_ADDRESS<<1); + +void printIdentification(struct VL6180xIdentification *temp){ + printf("Model ID = "); + printf("%d\n",temp->idModel); + + printf("Model Rev = "); + printf("%d",temp->idModelRevMajor); + printf("."); + printf("%d\n",temp->idModelRevMinor); + + printf("Module Rev = "); + printf("%d",temp->idModuleRevMajor); + printf("."); + printf("%d\n",temp->idModuleRevMinor); + + printf("Manufacture Date = "); + printf("%d",((temp->idDate >> 3) & 0x001F)); + printf("/"); + printf("%d",((temp->idDate >> 8) & 0x000F)); + printf("/1"); + printf("%d\n",((temp->idDate >> 12) & 0x000F)); + printf(" Phase: "); + printf("%d\n",(temp->idDate & 0x0007)); + + printf("Manufacture Time (s)= "); + printf("%d\n",(temp->idTime * 2)); + printf("\n\n"); +} +int main() { + + wait_ms(100); // delay .1s + + sensor.getIdentification(&identification); // Retrieve manufacture info from device memory + printIdentification(&identification); // Helper function to print all the Module information + + if(sensor.VL6180xInit() != 0){ + printf("FAILED TO INITALIZE\n"); //Initialize device and check for errors + }; + + sensor.VL6180xDefautSettings(); //Load default settings to get started. + + wait_ms(1000); // delay 1s + + + + while(1) { + //Get Ambient Light level and report in LUX + printf("Ambient Light Level (Lux) = "); + + //Input GAIN for light levels, + // GAIN_20 // Actual ALS Gain of 20 + // GAIN_10 // Actual ALS Gain of 10.32 + // GAIN_5 // Actual ALS Gain of 5.21 + // GAIN_2_5 // Actual ALS Gain of 2.60 + // GAIN_1_67 // Actual ALS Gain of 1.72 + // GAIN_1_25 // Actual ALS Gain of 1.28 + // GAIN_1 // Actual ALS Gain of 1.01 + // GAIN_40 // Actual ALS Gain of 40 + + printf("%f\n",sensor.getAmbientLight(GAIN_1) ); + + //Get Distance and report in mm + printf("Distance measured (mm) = "); + printf("%d\n", sensor.getDistance() ); + + wait_ms(500); + } +} +* @endcode +*/ #include "mbed.h" #ifndef VL6180x_h #define VL6180x_h @@ -135,98 +227,7 @@ uint16_t idDate; uint16_t idTime; }; -/** -* VL6180x tof/als sensor example -* -* @code -#include "mbed.h" -#include <VL6180x.h> -const float GAIN_1 = 1.01; // Actual ALS Gain of 1.01 -const float GAIN_1_25 = 1.28; // Actual ALS Gain of 1.28 -const float GAIN_1_67 = 1.72; // Actual ALS Gain of 1.72 -const float GAIN_2_5 = 2.6; // Actual ALS Gain of 2.60 -const float GAIN_5 = 5.21; // Actual ALS Gain of 5.21 -const float GAIN_10 = 10.32; // Actual ALS Gain of 10.32 -const float GAIN_20 = 20; // Actual ALS Gain of 20 -const float GAIN_40 = 40; // Actual ALS Gain of 40 - - -#define VL6180X_ADDRESS 0x29 - -VL6180xIdentification identification; -// mbed uses 8bit addresses shift address by 1 bit left -VL6180x sensor(D14, D15, VL6180X_ADDRESS<<1); - -void printIdentification(struct VL6180xIdentification *temp){ - printf("Model ID = "); - printf("%d\n",temp->idModel); - - printf("Model Rev = "); - printf("%d",temp->idModelRevMajor); - printf("."); - printf("%d\n",temp->idModelRevMinor); - - printf("Module Rev = "); - printf("%d",temp->idModuleRevMajor); - printf("."); - printf("%d\n",temp->idModuleRevMinor); - - printf("Manufacture Date = "); - printf("%d",((temp->idDate >> 3) & 0x001F)); - printf("/"); - printf("%d",((temp->idDate >> 8) & 0x000F)); - printf("/1"); - printf("%d\n",((temp->idDate >> 12) & 0x000F)); - printf(" Phase: "); - printf("%d\n",(temp->idDate & 0x0007)); - - printf("Manufacture Time (s)= "); - printf("%d\n",(temp->idTime * 2)); - printf("\n\n"); -} -int main() { - - wait_ms(100); // delay .1s - - sensor.getIdentification(&identification); // Retrieve manufacture info from device memory - printIdentification(&identification); // Helper function to print all the Module information - - if(sensor.VL6180xInit() != 0){ - printf("FAILED TO INITALIZE\n"); //Initialize device and check for errors - }; - - sensor.VL6180xDefautSettings(); //Load default settings to get started. - - wait_ms(1000); // delay 1s - - - - while(1) { - //Get Ambient Light level and report in LUX - printf("Ambient Light Level (Lux) = "); - - //Input GAIN for light levels, - // GAIN_20 // Actual ALS Gain of 20 - // GAIN_10 // Actual ALS Gain of 10.32 - // GAIN_5 // Actual ALS Gain of 5.21 - // GAIN_2_5 // Actual ALS Gain of 2.60 - // GAIN_1_67 // Actual ALS Gain of 1.72 - // GAIN_1_25 // Actual ALS Gain of 1.28 - // GAIN_1 // Actual ALS Gain of 1.01 - // GAIN_40 // Actual ALS Gain of 40 - - printf("%f\n",sensor.getAmbientLight(GAIN_1) ); - - //Get Distance and report in mm - printf("Distance measured (mm) = "); - printf("%d\n", sensor.getDistance() ); - - wait_ms(500); - } -} -* @endcode -*/ class VL6180x { public: