Rev Author Line No. Line
1998 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, 2,3,4,5);
10  
11 // DS18S20 Temperature chip
12 OneWire ds(1); // 1-Wire
13 byte addr[8]; // Addres
14  
15 void setup()
16 {
17 pinMode(48, OUTPUT); // Wiring LED
18 pinMode(0, OUTPUT); // LED
19 digitalWrite(48, LOW); // Wiring LED
20  
21 // set the speed at 60 rpm:
22 myStepper.setSpeed(8);
23 // initialize the serial port:
24 Serial.begin(9600);
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, read analog ins:
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(2, LOW);
63 digitalWrite(3, LOW);
64 digitalWrite(4, LOW);
65 digitalWrite(5, 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(2, LOW);
77 digitalWrite(3, LOW);
78 digitalWrite(4, LOW);
79 digitalWrite(5, LOW);
80 delay(500);
81 sense=1;
82 }
83  
84 ds.reset();
85 ds.select(addr);
86 ds.write(0x44,1); // start conversion, with parasite power on at the end
87  
88 delay(1000); // maybe 750ms is enough, maybe not
89 // we might do a ds.depower() here, but the reset will take care of it.
90  
91 present = ds.reset();
92 ds.select(addr);
93 ds.write(0xBE); // Read Scratchpad
94  
95 Serial.print("P=");
96 Serial.print(present,HEX);
97 Serial.print(" ");
98 for ( i = 0; i < 9; i++) // we need 9 bytes
99 {
100 data[i] = ds.read();
101 Serial.print(data[i], HEX);
102 Serial.print(" ");
103 }
104 Serial.print(" CRC=");
105 Serial.print( OneWire::crc8( data, 8), HEX);
106 Serial.println();
107 }
108 }
109  
110  
111