Rev 2033 Rev 2034
Line 22... Line 22...
22   22  
23 // initialize the serial port: 23 // initialize the serial port:
24 Serial.begin(9600); 24 Serial.begin(9600);
25 25
26 Wire.begin(); // join i2c bus (light0 optional for master) 26 Wire.begin(); // join i2c bus (light0 optional for master)
27   -  
28 // search for DS -  
29 if ( !ds.search(addr)) -  
30 { -  
31 ds.reset_search(); -  
32 delay(250); -  
33 return; -  
34 } -  
35   -  
36 if ( OneWire::crc8( addr, 7) != addr[7]) -  
37 { -  
38 Serial.print("CRC is not valid!\n"); -  
39 return; -  
40 } -  
41   -  
42 } 27 }
43   28  
44   29  
45 byte sense=0; 30 byte sense=0;
46   31  
Line 60... Line 45...
60 Serial.print("Prijat znak: "); 45 Serial.print("Prijat znak: ");
61 Serial.print( inByte, HEX); 46 Serial.print( inByte, HEX);
62 Serial.println(); 47 Serial.println();
63 } 48 }
64 49
-   50 //--------------------------------------------------------- Motor
65 if(sense) 51 if(sense)
66 { 52 {
67 digitalWrite(13, LOW); // blik 53 digitalWrite(13, LOW); // blik
68 // step one revolution in one direction: 54 // step one revolution in one direction:
69 Serial.println("clockwise"); 55 Serial.println("clockwise");
Line 99... Line 85...
99 digitalWrite(12, LOW); 85 digitalWrite(12, LOW);
100 delay(500); 86 delay(500);
101 sense=1; 87 sense=1;
102 } 88 }
103 89
-   90 //--------------------------------------------------------- 1-Wire bus
-   91  
104 // 1-Wire bus 92 // search for DS
-   93 if ( !ds.search(addr))
-   94 {
-   95 ds.reset_search();
-   96 delay(250);
-   97 return;
-   98 }
-   99  
-   100 if ( OneWire::crc8( addr, 7) != addr[7])
-   101 {
-   102 Serial.print("CRC is not valid!\n");
-   103 return;
-   104 }
-   105
105 ds.reset(); 106 ds.reset();
106 ds.select(addr); 107 ds.select(addr);
107 ds.write(0x44,1); // start conversion 108 ds.write(0x44,1); // start conversion
108   109  
109 // Delay for measurement, maybe 750ms is enough, maybe not 110 // Delay for measurement, maybe 750ms is enough, maybe not
Line 224... Line 225...
224 dd = Wire.receive(); 225 dd = Wire.receive();
225 Wire.endTransmission(); // stop transmitting 226 Wire.endTransmission(); // stop transmitting
226 Serial.println(dd, HEX); 227 Serial.println(dd, HEX);
227   228  
228 Serial.print("X="); 229 Serial.print("X=");
229 Serial.print(analogRead(A0), HEX); 230 Serial.print(analogRead(A0)-512, DEC);
230 Serial.print(" Y="); 231 Serial.print(" Y=");
231 Serial.print(analogRead(A1), HEX); 232 Serial.print(analogRead(A1)-512, DEC);
232 Serial.print(" Z="); 233 Serial.print(" Z=");
233 Serial.println(analogRead(A2), HEX); 234 Serial.println(analogRead(A2)-512, DEC);
234 } 235 }
235   236  
236   237  
237   238