44 * Casey Kuhns @ SparkFun Electronics
55 * 10/29/2014
66 * https://github.com/sparkfun/SparkFun_ToF_Range_Finder-VL6180_Arduino_Library
7- *
7+ *
88 * The VL6180x by ST micro is a time of flight range finder that
99 * uses pulsed IR light to determine distances from object at close
1010 * range. The average range of a sensor is between 0-200mm
11- *
11+ *
1212 * Resources:
1313 * This library uses the Arduino Wire.h to complete I2C transactions.
14- *
14+ *
1515 * Development environment specifics:
1616 * IDE: Arduino 1.0.5
1717 * Hardware Platform: Arduino Pro 3.3V/8MHz
1818 * VL6180x Breakout Version: 1.0
1919 * **Updated for Arduino 1.6.4 5/2015**
2020
21- *
21+ *
2222 * This code is beerware. If you see me (or any other SparkFun employee) at the
2323 * local pub, and you've found our code helpful, please buy us a round!
24- *
24+ *
2525 * Distributed as-is; no warranty is given.
2626 ******************************************************************************/
2727
@@ -43,51 +43,53 @@ const float GAIN_40 = 40; // Actual ALS Gain of 40
4343VL6180xIdentification identification;
4444VL6180x sensor (VL6180X_ADDRESS );
4545
46- void setup () {
46+ void setup ()
47+ {
4748
48- Serial.begin (115200 ); // Start Serial at 115200bps
49- Wire.begin (); // Start I2C library
50- delay (100 ); // delay .1s
49+ Serial.begin (115200 ); // Start Serial at 115200bps
50+ Wire.begin (); // Start I2C library
51+ delay (100 ); // delay .1s
5152
5253 sensor.getIdentification (&identification); // Retrieve manufacture info from device memory
53- printIdentification (&identification); // Helper function to print all the Module information
54+ printIdentification (&identification); // Helper function to print all the Module information
5455
55- if (sensor.VL6180xInit () != 0 ){
56- Serial.println (" FAILED TO INITALIZE" ); // Initialize device and check for errors
57- };
58-
59- sensor.VL6180xDefautSettings (); // Load default settings to get started.
60-
61- delay (1000 ); // delay 1s
56+ if (sensor.VL6180xInit () != 0 )
57+ {
58+ Serial.println (" FAILED TO INITALIZE" ); // Initialize device and check for errors
59+ };
6260
61+ sensor.VL6180xDefautSettings (); // Load default settings to get started.
6362
63+ delay (1000 ); // delay 1s
6464}
6565
66- void loop () {
66+ void loop ()
67+ {
6768
68- // Get Ambient Light level and report in LUX
69+ // Get Ambient Light level and report in LUX
6970 Serial.print (" Ambient Light Level (Lux) = " );
70-
71- // Input GAIN for light levels,
72- // GAIN_20 // Actual ALS Gain of 20
73- // GAIN_10 // Actual ALS Gain of 10.32
74- // GAIN_5 // Actual ALS Gain of 5.21
75- // GAIN_2_5 // Actual ALS Gain of 2.60
76- // GAIN_1_67 // Actual ALS Gain of 1.72
77- // GAIN_1_25 // Actual ALS Gain of 1.28
78- // GAIN_1 // Actual ALS Gain of 1.01
79- // GAIN_40 // Actual ALS Gain of 40
80-
81- Serial.println ( sensor.getAmbientLight (GAIN_1 ) );
82-
83- // Get Distance and report in mm
71+
72+ // Input GAIN for light levels,
73+ // GAIN_20 // Actual ALS Gain of 20
74+ // GAIN_10 // Actual ALS Gain of 10.32
75+ // GAIN_5 // Actual ALS Gain of 5.21
76+ // GAIN_2_5 // Actual ALS Gain of 2.60
77+ // GAIN_1_67 // Actual ALS Gain of 1.72
78+ // GAIN_1_25 // Actual ALS Gain of 1.28
79+ // GAIN_1 // Actual ALS Gain of 1.01
80+ // GAIN_40 // Actual ALS Gain of 40
81+
82+ Serial.println (sensor.getAmbientLight (GAIN_1 ));
83+
84+ // Get Distance and report in mm
8485 Serial.print (" Distance measured (mm) = " );
85- Serial.println ( sensor.getDistance () );
86+ Serial.println (sensor.getDistance ());
8687
87- delay (500 );
88+ delay (500 );
8889};
8990
90- void printIdentification (struct VL6180xIdentification *temp){
91+ void printIdentification (struct VL6180xIdentification *temp)
92+ {
9193 Serial.print (" Model ID = " );
9294 Serial.println (temp->idModel );
9395
@@ -99,7 +101,7 @@ void printIdentification(struct VL6180xIdentification *temp){
99101 Serial.print (" Module Rev = " );
100102 Serial.print (temp->idModuleRevMajor );
101103 Serial.print (" ." );
102- Serial.println (temp->idModuleRevMinor );
104+ Serial.println (temp->idModuleRevMinor );
103105
104106 Serial.print (" Manufacture Date = " );
105107 Serial.print ((temp->idDate >> 3 ) & 0x001F );
@@ -115,5 +117,3 @@ void printIdentification(struct VL6180xIdentification *temp){
115117 Serial.println ();
116118 Serial.println ();
117119}
118-
119-
0 commit comments