Line 38... |
Line 38... |
38 |
|
38 |
|
39 |
// initialize the serial port: |
39 |
// initialize the serial port: |
40 |
Serial.begin(9600); |
40 |
Serial.begin(9600); |
41 |
|
41 |
|
42 |
Wire.begin(); // join i2c bus (light0 optional for master) |
42 |
Wire.begin(); // join i2c bus (light0 optional for master) |
43 |
|
- |
|
44 |
// search for DS |
- |
|
45 |
if ( !ds.search(addr)) |
- |
|
46 |
{ |
- |
|
47 |
ds.reset_search(); |
- |
|
48 |
delay(250); |
- |
|
49 |
return; |
- |
|
50 |
} |
- |
|
51 |
|
- |
|
52 |
if ( OneWire::crc8( addr, 7) != addr[7]) |
- |
|
53 |
{ |
- |
|
54 |
Serial.print("CRC is not valid!\n"); |
- |
|
55 |
return; |
- |
|
56 |
} |
- |
|
57 |
|
- |
|
58 |
} |
43 |
} |
59 |
|
44 |
|
60 |
|
45 |
|
61 |
void loop() |
46 |
void loop() |
62 |
{ |
47 |
{ |
63 |
byte i; |
48 |
byte i,n; |
64 |
byte present = 0; |
49 |
byte present = 0; |
65 |
byte data[12]; |
50 |
byte data[12]; |
66 |
byte inByte; |
51 |
byte inByte; |
67 |
int dd=0; |
52 |
int dd=0; |
68 |
|
53 |
|
Line 72... |
Line 57... |
72 |
digitalWrite(FW2, HIGH); |
57 |
digitalWrite(FW2, HIGH); |
73 |
digitalWrite(FW3, HIGH); |
58 |
digitalWrite(FW3, HIGH); |
74 |
delay(300); |
59 |
delay(300); |
75 |
digitalWrite(LAMP1, LOW); // blik |
60 |
digitalWrite(LAMP1, LOW); // blik |
76 |
|
61 |
|
- |
|
62 |
//--------------------------------------------------------- Serial Input |
77 |
// if we get a valid byte |
63 |
// if we get a valid byte |
78 |
if (Serial.available() > 0) |
64 |
if (Serial.available() > 0) |
79 |
{ |
65 |
{ |
80 |
// get incoming byte: |
66 |
// get incoming byte: |
81 |
inByte = Serial.read(); |
67 |
inByte = Serial.read(); |
Line 118... |
Line 104... |
118 |
digitalWrite(M4, LOW); |
104 |
digitalWrite(M4, LOW); |
119 |
} |
105 |
} |
120 |
sense=!sense; |
106 |
sense=!sense; |
121 |
digitalWrite(LAMP2, LOW); // blik |
107 |
digitalWrite(LAMP2, LOW); // blik |
122 |
|
108 |
|
123 |
//--------------------------------------------------------- 1-Wire bus |
109 |
//--------------------------------------------------------- 1-Wire bus |
- |
|
110 |
ds.reset_search(); |
- |
|
111 |
for(n=0;n<2;n++) |
- |
|
112 |
{ |
- |
|
113 |
if ( !ds.search(addr)) |
- |
|
114 |
{ |
- |
|
115 |
continue; |
- |
|
116 |
} |
124 |
|
117 |
|
- |
|
118 |
Serial.print("R="); |
- |
|
119 |
for( i = 0; i < 8; i++) |
- |
|
120 |
{ |
- |
|
121 |
Serial.print(addr[i], HEX); |
- |
|
122 |
Serial.print(" "); |
- |
|
123 |
} |
- |
|
124 |
|
- |
|
125 |
if ( OneWire::crc8( addr, 7) != addr[7]) |
- |
|
126 |
{ |
- |
|
127 |
Serial.print("CRC is not valid!\n"); |
- |
|
128 |
} |
- |
|
129 |
|
125 |
ds.reset(); |
130 |
ds.reset(); |
126 |
ds.select(addr); |
131 |
ds.select(addr); |
127 |
ds.write(0x44,1); // start conversion |
132 |
ds.write(0x44,1); // start conversion, with parasite power on at the end |
128 |
|
133 |
|
129 |
// Delay for measurement, maybe 750ms is enough, maybe not |
134 |
delay(800); // maybe 750ms is enough, maybe not |
130 |
delay(800); |
- |
|
131 |
digitalWrite(FW1, LOW); // blik |
135 |
digitalWrite(FW1, LOW); // blik |
132 |
|
136 |
|
133 |
present = ds.reset(); |
137 |
present = ds.reset(); |
134 |
ds.select(addr); |
138 |
ds.select(addr); |
135 |
ds.write(0xBE); // Read Scratchpad |
139 |
ds.write(0xBE); // Read Scratchpad |
136 |
|
140 |
|
137 |
Serial.print("P="); |
141 |
Serial.print("P="); |
138 |
Serial.print(present,HEX); |
142 |
Serial.print(present,HEX); |
139 |
Serial.print(" "); |
143 |
Serial.print(" "); |
140 |
for ( i = 0; i < 9; i++) // we need 9 bytes |
144 |
for ( i = 0; i < 9; i++) { // we need 9 bytes |
141 |
{ |
- |
|
142 |
data[i] = ds.read(); |
145 |
data[i] = ds.read(); |
143 |
Serial.print(data[i], HEX); |
146 |
Serial.print(data[i], HEX); |
144 |
Serial.print(" "); |
147 |
Serial.print(" "); |
- |
|
148 |
} |
- |
|
149 |
Serial.print(" CRC="); |
- |
|
150 |
Serial.print( OneWire::crc8( data, 8), HEX); |
- |
|
151 |
Serial.println(); |
145 |
} |
152 |
} |
146 |
Serial.print(" CRC="); |
- |
|
147 |
Serial.print( OneWire::crc8( data, 8), HEX); |
- |
|
148 |
Serial.println(); |
- |
|
149 |
|
153 |
|
- |
|
154 |
//------------------------------------------------------- Light 0 |
150 |
Serial.print("Light0: COMMAND="); |
155 |
Serial.print("Light0: COMMAND="); |
151 |
// Setup device |
156 |
// Setup device |
152 |
Wire.beginTransmission(light0); |
157 |
Wire.beginTransmission(light0); |
153 |
Wire.send(0x00); // sends light0 |
158 |
Wire.send(0x00); // sends light0 |
154 |
Wire.send(0b11000001); // setup (eye light sensing; measurement range 2 [4000 lx]) |
159 |
Wire.send(0b11000001); // setup (eye light sensing; measurement range 2 [4000 lx]) |
Line 191... |
Line 196... |
191 |
Wire.requestFrom(light0, 1); |
196 |
Wire.requestFrom(light0, 1); |
192 |
dd = Wire.receive(); |
197 |
dd = Wire.receive(); |
193 |
Wire.endTransmission(); // stop transmitting |
198 |
Wire.endTransmission(); // stop transmitting |
194 |
Serial.println(dd, HEX); |
199 |
Serial.println(dd, HEX); |
195 |
|
200 |
|
- |
|
201 |
//------------------------------------------------------- Light 1 |
196 |
Serial.print("Light1: COMMAND="); |
202 |
Serial.print("Light1: COMMAND="); |
197 |
// Setup device |
203 |
// Setup device |
198 |
Wire.beginTransmission(light1); |
204 |
Wire.beginTransmission(light1); |
199 |
Wire.send(0x00); // sends light0 |
205 |
Wire.send(0x00); // sends light0 |
200 |
Wire.send(0b11000001); // setup (eye light sensing; measurement range 2 [4000 lx]) |
206 |
Wire.send(0b11000001); // setup (eye light sensing; measurement range 2 [4000 lx]) |
Line 237... |
Line 243... |
237 |
Wire.requestFrom(light1, 1); |
243 |
Wire.requestFrom(light1, 1); |
238 |
dd = Wire.receive(); |
244 |
dd = Wire.receive(); |
239 |
Wire.endTransmission(); // stop transmitting |
245 |
Wire.endTransmission(); // stop transmitting |
240 |
Serial.println(dd, HEX); |
246 |
Serial.println(dd, HEX); |
241 |
|
247 |
|
242 |
// Accelerometer |
248 |
//-------------------------------------------------- Accelerometer |
243 |
Serial.print("X="); |
249 |
Serial.print("X="); |
244 |
Serial.print(analogRead(A0)-512, DEC); |
250 |
Serial.print(analogRead(A0)-512, DEC); |
245 |
Serial.print(" Y="); |
251 |
Serial.print(" Y="); |
246 |
Serial.print(analogRead(A1)-512, DEC); |
252 |
Serial.print(analogRead(A1)-512, DEC); |
247 |
Serial.print(" Z="); |
253 |
Serial.print(" Z="); |