Rev Author Line No. Line
2030 kakl 1 #include <OneWire.h>
2 #include <Stepper.h>
3  
4 const int stepsPerRevolution = 3200; // change this to fit the number of steps per revolution
5 // for your motor
6 byte sense=0;
7  
8 // initialize the stepper library on pins
9 Stepper myStepper(stepsPerRevolution, 9,10,11,12);
10  
11 // DS18S20 Temperature chip
12 OneWire ds(1); // 1-Wire
13 byte addr[8]; // Addres
14  
15 void setup()
16 {
17 pinMode(13, OUTPUT); // LED
18 digitalWrite(13, LOW); // LED ON
19  
20 // initialize the serial port:
21 Serial.begin(9600);
22  
23 // set the speed
24 myStepper.setSpeed(8);
25  
26 // search for DS
27 if ( !ds.search(addr))
28 {
29 ds.reset_search();
30 delay(250);
31 return;
32 }
33  
34 if ( OneWire::crc8( addr, 7) != addr[7])
35 {
36 Serial.print("CRC is not valid!\n");
37 return;
38 }
39  
40 }
41  
42 void loop()
43 {
44 byte i;
45 byte present = 0;
46 byte data[12];
47 byte inByte;
48  
49 // if we get a valid byte
50 //!!! if (Serial.available() > 0)
51 {
52 // get incoming byte:
53 //!!! inByte = Serial.read();
54  
55 if(sense)
56 {
57 digitalWrite(0, LOW); // blik
58 // step one revolution in one direction:
59 Serial.println("clockwise");
60 myStepper.step(stepsPerRevolution);
61 delay(50);
62 digitalWrite(9, LOW);
63 digitalWrite(10, LOW);
64 digitalWrite(11, LOW);
65 digitalWrite(12, LOW);
66 delay(500);
67 sense=0;
68 }
69 else
70 {
71 digitalWrite(0, HIGH); // blik
72 // step one revolution in the other direction:
73 Serial.println("counterclockwise");
74 myStepper.step(-stepsPerRevolution);
75 delay(50);
76 digitalWrite(9, LOW);
77 digitalWrite(10, LOW);
78 digitalWrite(11, LOW);
79 digitalWrite(12, LOW);
80 delay(500);
81 sense=1;
82 }
83  
84 // 1-Wire bus
85 ds.reset();
86 ds.select(addr);
87 ds.write(0x44,1); // start conversion
88 delay(1000); // maybe 750ms is enough, maybe not
89 present = ds.reset();
90 ds.select(addr);
91 ds.write(0xBE); // Read Scratchpad
92  
93 Serial.print("P=");
94 Serial.print(present,HEX);
95 Serial.print(" ");
96 for ( i = 0; i < 9; i++) // we need 9 bytes
97 {
98 data[i] = ds.read();
99 Serial.print(data[i], HEX);
100 Serial.print(" ");
101 }
102 Serial.print(" CRC=");
103 Serial.print( OneWire::crc8( data, 8), HEX);
104 Serial.println();
105 }
106 }
107  
108  
109