1 | /**************************************************************************/
|
---|
2 | /*!
|
---|
3 | @file Adafruit_VCNL4000.h
|
---|
4 | @author K. Townsend (Adafruit Industries)
|
---|
5 | @license BSD (see license.txt)
|
---|
6 |
|
---|
7 | This is a library for the Adafruit VCNL4000 Temp Sensor breakout board
|
---|
8 | ----> http://www.adafruit.com/products/1782
|
---|
9 |
|
---|
10 | Adafruit invests time and resources providing this open source code,
|
---|
11 | please support Adafruit and open-source hardware by purchasing
|
---|
12 | products from Adafruit!
|
---|
13 |
|
---|
14 | @section HISTORY
|
---|
15 |
|
---|
16 | v1.0 - First release
|
---|
17 | */
|
---|
18 | /**************************************************************************/
|
---|
19 |
|
---|
20 | #if ARDUINO >= 100
|
---|
21 | #include "Arduino.h"
|
---|
22 | #else
|
---|
23 | #include "WProgram.h"
|
---|
24 | #endif
|
---|
25 |
|
---|
26 | #ifdef __AVR_ATtiny85__
|
---|
27 | #include "TinyWireM.h"
|
---|
28 | #define Wire TinyWireM
|
---|
29 | #else
|
---|
30 | #include <Wire.h>
|
---|
31 | #endif
|
---|
32 |
|
---|
33 | // the i2c address
|
---|
34 | #define VCNL4000_I2CADDR_DEFAULT 0x13
|
---|
35 |
|
---|
36 | // commands and constants
|
---|
37 | #define VCNL4000_COMMAND 0x80
|
---|
38 | #define VCNL4000_PRODUCTID 0x81
|
---|
39 | #define VCNL4000_IRLED 0x83
|
---|
40 | #define VCNL4000_AMBIENTPARAMETER 0x84
|
---|
41 | #define VCNL4000_AMBIENTDATA 0x85
|
---|
42 | #define VCNL4000_AMBIENTDATA 0x85
|
---|
43 | #define VCNL4000_PROXIMITYDATA 0x87
|
---|
44 | #define VCNL4000_SIGNALFREQ 0x89
|
---|
45 | #define VCNL4000_PROXINITYADJUST 0x8A
|
---|
46 |
|
---|
47 | typedef enum
|
---|
48 | {
|
---|
49 | VCNL4000_3M125 = 0,
|
---|
50 | VCNL4000_1M5625 = 1,
|
---|
51 | VCNL4000_781K25 = 2,
|
---|
52 | VCNL4000_390K625 = 3,
|
---|
53 | } vcnl4000_freq;
|
---|
54 |
|
---|
55 | #define VCNL4000_MEASUREAMBIENT 0x10
|
---|
56 | #define VCNL4000_MEASUREPROXIMITY 0x08
|
---|
57 | #define VCNL4000_AMBIENTREADY 0x40
|
---|
58 | #define VCNL4000_PROXIMITYREADY 0x20
|
---|
59 |
|
---|
60 | class Adafruit_VCNL4000 {
|
---|
61 | public:
|
---|
62 | Adafruit_VCNL4000();
|
---|
63 | boolean begin(uint8_t a = VCNL4000_I2CADDR_DEFAULT);
|
---|
64 |
|
---|
65 | uint8_t getLEDcurrent(void);
|
---|
66 | void setLEDcurrent(uint8_t c);
|
---|
67 |
|
---|
68 | void setFrequency(vcnl4000_freq f);
|
---|
69 | uint16_t readProximity(void);
|
---|
70 | uint16_t readAmbient(void);
|
---|
71 |
|
---|
72 | private:
|
---|
73 |
|
---|
74 | void write8(uint8_t address, uint8_t data);
|
---|
75 | uint16_t read16(uint8_t address);
|
---|
76 | uint8_t read8(uint8_t address);
|
---|
77 |
|
---|
78 | uint8_t _i2caddr;
|
---|
79 | };
|
---|