Rev Author Line No. Line
2202 kaklik 1 // I2C Light Sensor
2  
3 #include <Wire.h>
4  
5 #define address 0x44 // A0 = L
6  
7  
8 void setup()
9 {
10 Wire.begin(); // join i2c bus (address optional for master)
11 // I2C pins PD4, PD5
12 //
13 pinMode(3, OUTPUT); // LED pro blikani, aby bylo videt, ze to neco dela
14 pinMode(5, OUTPUT); // LED pro blikani, aby bylo videt, ze to neco dela
15 Serial.begin(9600); // Zmerena intenzita osvetleni se bude vypisovat na seriovou linku
16 }
17  
18 int data = 0;
19  
20 void loop()
21 {
22 int lux=0;
23  
24 /* Serial.print("lux=");
25  
26 // Setup device
27 digitalWrite(5, HIGH);
28  
29 Wire.beginTransmission(address);
30 Wire.send(0x00); // sends address
31 Wire.send(0b11000000); // setup (eye light sensing; one time measurement; measurement range 1)
32 Wire.endTransmission(); // stop transmitting
33  
34 // Delay for measurement
35  
36 digitalWrite(5, LOW); // set the LED off
37 delay(500);
38 digitalWrite(5, HIGH); // set the LED on
39 delay(500);
40  
41 // Connect to device and set register address
42 Wire.beginTransmission(address);
43 Wire.send(0x00); // sends address
44 Wire.endTransmission(); // stop transmitting
45 // Connect to device and request one byte
46 Wire.beginTransmission(address);
47 Wire.requestFrom(address, 1);
48 data = Wire.receive();
49 Wire.endTransmission(); // stop transmitting
50 // Serial.print(data, HEX);
51  
52 // Serial.print(" LSB=");
53 // Connect to device and set register address
54 Wire.beginTransmission(address);
55 Wire.send(0x01); // sends address
56 Wire.endTransmission(); // stop transmitting
57 // Connect to device and request one byte
58 Wire.beginTransmission(address);
59 Wire.requestFrom(address, 1);
60 data = Wire.receive();
61 Wire.endTransmission(); // stop transmitting
62 // Serial.print(data, HEX);
63 lux=data;
64  
65 // Serial.print(" MSB=");
66 // Connect to device and set register address
67 Wire.beginTransmission(address);
68 Wire.send(0x02); // sends address
69 Wire.endTransmission(); // stop transmitting
70 // Connect to device and request one byte
71 Wire.beginTransmission(address);
72 Wire.requestFrom(address, 1);
73 data = Wire.receive();
74 Wire.endTransmission(); // stop transmitting
75 // Serial.print(data, HEX);
76 lux+=data*256;
77 */
78  
79 Serial.print((unsigned)lux, DEC);
80  
81 Serial.print(" luxIR=");
82  
83 // Setup device
84 Wire.beginTransmission(address);
85 Wire.send(0x00); // sends address
86 Wire.send(0b11100000); // setup (eye light sensing; measurement range 2 [4000 lx])
87 Wire.endTransmission(); // stop transmitting
88  
89 // Delay for measurement
90 digitalWrite(3, HIGH); // set the LED on
91 delay(500);
92 digitalWrite(3, LOW); // set the LED off
93 delay(500);
94  
95  
96 // Connect to device and set register address
97 Wire.beginTransmission(address);
98 Wire.send(0x00); // sends address
99 Wire.endTransmission(); // stop transmitting
100 // Connect to device and request one byte
101 Wire.beginTransmission(address);
102 Wire.requestFrom(address, 1);
103 data = Wire.receive();
104 Wire.endTransmission(); // stop transmitting
105 // Serial.print(data, HEX);
106  
107 // Serial.print(" LSB=");
108 // Connect to device and set register address
109 Wire.beginTransmission(address);
110 Wire.send(0x01); // sends address
111 Wire.endTransmission(); // stop transmitting
112 // Connect to device and request one byte
113 Wire.beginTransmission(address);
114 Wire.requestFrom(address, 1);
115 data = Wire.receive();
116 Wire.endTransmission(); // stop transmitting
117 // Serial.print(data, HEX);
118 lux=data;
119  
120 // Serial.print(" MSB=");
121 // Connect to device and set register address
122 Wire.beginTransmission(address);
123 Wire.send(0x02); // sends address
124 Wire.endTransmission(); // stop transmitting
125 // Connect to device and request one byte
126 Wire.beginTransmission(address);
127 Wire.requestFrom(address, 1);
128 data = Wire.receive();
129 Wire.endTransmission(); // stop transmitting
130 // Serial.print(data, HEX);
131 lux+=data*256;
132 Serial.println((unsigned)lux, DEC);
133 }
134