Line 6... |
Line 6... |
6 |
|
6 |
|
7 |
void setup() |
7 |
void setup() |
8 |
{ |
8 |
{ |
9 |
Wire.begin(); // join i2c bus (address optional for master) |
9 |
Wire.begin(); // join i2c bus (address optional for master) |
10 |
pinMode(3, OUTPUT); // LED pro blikani, aby bylo videt, ze to neco dela |
10 |
pinMode(3, OUTPUT); // LED pro blikani, aby bylo videt, ze to neco dela |
- |
|
11 |
pinMode(5, OUTPUT); // LED pro blikani, aby bylo videt, ze to neco dela |
11 |
Serial.begin(9600); // Zmerena intenzita osvetleni se bude vypisovat na seriovou linku |
12 |
Serial.begin(9600); // Zmerena intenzita osvetleni se bude vypisovat na seriovou linku |
12 |
} |
13 |
} |
13 |
|
14 |
|
14 |
int data = 0; |
15 |
int data = 0; |
15 |
|
16 |
|
Line 18... |
Line 19... |
18 |
int lux=0; |
19 |
int lux=0; |
19 |
|
20 |
|
20 |
Serial.print("lux="); |
21 |
Serial.print("lux="); |
21 |
|
22 |
|
22 |
// Setup device |
23 |
// Setup device |
- |
|
24 |
digitalWrite(5, HIGH); |
- |
|
25 |
|
23 |
Wire.beginTransmission(address); |
26 |
Wire.beginTransmission(address); |
24 |
Wire.send(0x00); // sends address |
27 |
Wire.send(0x00); // sends address |
25 |
Wire.send(0b11000000); // setup (eye light sensing; measurement range 2 [4000 lx]) |
28 |
Wire.send(0b11000000); // setup (eye light sensing; one time measurement; measurement range 1) |
26 |
Wire.endTransmission(); // stop transmitting |
29 |
Wire.endTransmission(); // stop transmitting |
27 |
|
30 |
|
28 |
// Delay for measurement |
31 |
// Delay for measurement |
- |
|
32 |
{ |
- |
|
33 |
long n; |
- |
|
34 |
for(n=0;n<66000;n++) |
- |
|
35 |
{ |
29 |
digitalWrite(3, HIGH); // set the LED on |
36 |
digitalWrite(5, LOW); // set the LED off |
30 |
delay(500); |
37 |
// delay(500); |
31 |
digitalWrite(3, LOW); // set the LED off |
38 |
digitalWrite(5, HIGH); // set the LED on |
- |
|
39 |
delayMicroseconds(100); |
32 |
delay(500); |
40 |
// delay(500); |
- |
|
41 |
} |
- |
|
42 |
} |
33 |
|
43 |
|
34 |
|
44 |
|
35 |
// Connect to device and set register address |
45 |
// Connect to device and set register address |
36 |
Wire.beginTransmission(address); |
46 |
Wire.beginTransmission(address); |
37 |
Wire.send(0x00); // sends address |
47 |
Wire.send(0x00); // sends address |
Line 67... |
Line 77... |
67 |
data = Wire.receive(); |
77 |
data = Wire.receive(); |
68 |
Wire.endTransmission(); // stop transmitting |
78 |
Wire.endTransmission(); // stop transmitting |
69 |
// Serial.print(data, HEX); |
79 |
// Serial.print(data, HEX); |
70 |
lux+=data*256; |
80 |
lux+=data*256; |
71 |
|
81 |
|
- |
|
82 |
/* |
72 |
Serial.print((unsigned)lux, DEC); |
83 |
Serial.print((unsigned)lux, DEC); |
73 |
|
84 |
|
74 |
Serial.print(" luxIR="); |
85 |
Serial.print(" luxIR="); |
75 |
|
86 |
|
76 |
// Setup device |
87 |
// Setup device |
Line 120... |
Line 131... |
120 |
Wire.requestFrom(address, 1); |
131 |
Wire.requestFrom(address, 1); |
121 |
data = Wire.receive(); |
132 |
data = Wire.receive(); |
122 |
Wire.endTransmission(); // stop transmitting |
133 |
Wire.endTransmission(); // stop transmitting |
123 |
// Serial.print(data, HEX); |
134 |
// Serial.print(data, HEX); |
124 |
lux+=data*256; |
135 |
lux+=data*256; |
125 |
|
136 |
*/ |
126 |
Serial.println((unsigned)lux, DEC); |
137 |
Serial.println((unsigned)lux, DEC); |
127 |
|
138 |
|
128 |
} |
139 |
} |
129 |
|
140 |
|
130 |
|
141 |
|