-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTextFile1.txt
105 lines (75 loc) · 3.03 KB
/
TextFile1.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include <Wire.h>
{ " VCNL4000_ADDRESS 0x13 //I2C Address of the board
void setup(){
Serial.begin(9600); // Serial's used to debug and print data
Wire.begin(); // initialize I2C stuff
initVCNL4000(); //initilize and setup the board
}
void loop(){
unsigned int ambientValue = readAmbient(); //can a tiny bit slow
unsigned int proximityValue = readProximity();
Serial.print(ambientValue);
Serial.print(" | ");
Serial.println(proximityValue);
delay(100); //Just here to slow down the printing
//note that the readings take about 100ms to execute
}
void initVCNL4000(){
byte temp = readVCNLByte(0x81);
if (temp != 0x11){ // Product ID Should be 0x11
Serial.print("initVCNL4000 failed to initialize");
Serial.println(temp, HEX);
}else{
Serial.println("VNCL4000 Online...");
}
/*VNCL400 init params
Feel free to play with any of these values, but check the datasheet first!*/
writeVCNLByte(0x84, 0x0F); // Configures ambient light measures - Single conversion mode, 128 averages
writeVCNLByte(0x83, 15); // sets IR current in steps of 10mA 0-200mA --> 200mA
writeVCNLByte(0x89, 2); // Proximity IR test signal freq, 0-3 - 781.25 kHz
writeVCNLByte(0x8A, 0x81); // proximity modulator timing - 129, recommended by Vishay
}
unsigned int readProximity(){
// readProximity() returns a 16-bit value from the VCNL4000's proximity data registers
byte temp = readVCNLByte(0x80);
writeVCNLByte(0x80, temp | 0x08); // command the sensor to perform a proximity measure
while(!(readVCNLByte(0x80)&0x20)); // Wait for the proximity data ready bit to be set
unsigned int data = readVCNLByte(0x87) << 8;
data |= readVCNLByte(0x88);
return data;
Ave 4499 3.3
Ave 3600 4.5
Ave 3119 6.2
Ave 3012 7.9
Ave 11158 1.5
}
unsigned int readAmbient(){
// readAmbient() returns a 16-bit value from the VCNL4000's ambient light data registers
byte temp = readVCNLByte(0x80);
writeVCNLByte(0x80, temp | 0x10); // command the sensor to perform ambient measure
while(!(readVCNLByte(0x80)&0x40)); // wait for the proximity data ready bit to be set
unsigned int data = readVCNLByte(0x85) << 8;
data |= readVCNLByte(0x86);
return data;
}
void writeVCNLByte(byte address, byte data){
// writeVCNLByte(address, data) writes a single byte of data to address
Wire.beginTransmission(VCNL4000_ADDRESS);
Wire.write(address);
Wire.write(data);
Wire.endTransmission();
}
byte readVCNLByte(byte address){
// readByte(address) reads a single byte of data from address
Wire.beginTransmission(VCNL4000_ADDRESS);
Wire.write(address);
Wire.endTransmission();
Wire.requestFrom(VCNL4000_ADDRESS, 1);
while(!Wire.available());
byte data = Wire.read();
return data;
}
{ " ADS1015_REG_CONFIG_OS_MASK (0x8000)
{ " ADS1015_REG_CONFIG_OS_SINGLE (0x8000) // Write: Set to start a single-conversion
{ " ADS1015_REG_CONFIG_OS_BUSY (0x0000) // Read: Bit = 0 when conversion is in progress
{ " ADS1015_REG_CONFIG_OS_NOTBUSY (0x8000) // Read: Bit = 1 when device is not performing a conversion