Rev 2030 Rev 2033
Line 1... Line 1...
1 #include <OneWire.h> 1 #include <OneWire.h>
2 #include <Stepper.h> 2 #include <Stepper.h>
3 #include <Wire.h> 3 #include <Wire.h>
4   4  
5 #define address 0x44 // A0 = L (I2C address) 5 #define light0 0x44 // A0 = L (I2C light0)
-   6 #define light1 0x45 // A0 = H (I2C light0)
6   7  
7 const int steps = 200; //3200; // change this to fit the number of steps 8 const int steps = 200; //3200; // change this to fit the number of steps
8   -  
-   9 const int sspeed = 100; // stepper motor speed
9   10  
10 // initialize the stepper library on pins 11 // initialize the stepper library on pins
11 Stepper myStepper(steps, 9,10,11,12); 12 Stepper myStepper(steps, 9,10,11,12);
12   13  
13 // DS18S20 Temperature chip 14 // DS18S20 Temperature chip
14 OneWire ds(1); // 1-Wire 15 OneWire ds(5); // 1-Wire
15 byte addr[8]; // Addres 16 byte addr[8]; // Addres
16   17  
17 void setup() 18 void setup()
18 { 19 {
19 pinMode(13, OUTPUT); // LED 20 pinMode(13, OUTPUT); // LED
20 digitalWrite(13, LOW); // LED ON 21 digitalWrite(13, LOW); // LED ON
21   22  
22 // initialize the serial port: 23 // initialize the serial port:
23 Serial.begin(9600); 24 Serial.begin(9600);
24   -  
25 // set the speed -  
26 myStepper.setSpeed(8); -  
27 25
28 Wire.begin(); // join i2c bus (address optional for master) 26 Wire.begin(); // join i2c bus (light0 optional for master)
29   27  
30 // search for DS 28 // search for DS
31 if ( !ds.search(addr)) 29 if ( !ds.search(addr))
32 { 30 {
33 ds.reset_search(); 31 ds.reset_search();
Line 67... Line 65...
67 if(sense) 65 if(sense)
68 { 66 {
69 digitalWrite(13, LOW); // blik 67 digitalWrite(13, LOW); // blik
70 // step one revolution in one direction: 68 // step one revolution in one direction:
71 Serial.println("clockwise"); 69 Serial.println("clockwise");
-   70 myStepper.setSpeed(sspeed/2);
-   71 myStepper.step(30);
-   72 myStepper.setSpeed(sspeed);
72 myStepper.step(steps); 73 myStepper.step(steps-50);
-   74 myStepper.setSpeed(sspeed/2);
-   75 myStepper.step(20);
73 delay(50); 76 delay(50);
74 digitalWrite(9, LOW); 77 digitalWrite(9, LOW);
75 digitalWrite(10, LOW); 78 digitalWrite(10, LOW);
76 digitalWrite(11, LOW); 79 digitalWrite(11, LOW);
77 digitalWrite(12, LOW); 80 digitalWrite(12, LOW);
Line 81... Line 84...
81 else 84 else
82 { 85 {
83 digitalWrite(13, HIGH); // blik 86 digitalWrite(13, HIGH); // blik
84 // step one revolution in the other direction: 87 // step one revolution in the other direction:
85 Serial.println("counterclockwise"); 88 Serial.println("counterclockwise");
-   89 myStepper.setSpeed(sspeed/2);
-   90 myStepper.step(-30);
-   91 myStepper.setSpeed(sspeed);
86 myStepper.step(-steps); 92 myStepper.step(-(steps-50));
-   93 myStepper.setSpeed(sspeed/2);
-   94 myStepper.step(-20);
87 delay(50); 95 delay(50);
88 digitalWrite(9, LOW); 96 digitalWrite(9, LOW);
89 digitalWrite(10, LOW); 97 digitalWrite(10, LOW);
90 digitalWrite(11, LOW); 98 digitalWrite(11, LOW);
91 digitalWrite(12, LOW); 99 digitalWrite(12, LOW);
Line 95... Line 103...
95 103
96 // 1-Wire bus 104 // 1-Wire bus
97 ds.reset(); 105 ds.reset();
98 ds.select(addr); 106 ds.select(addr);
99 ds.write(0x44,1); // start conversion 107 ds.write(0x44,1); // start conversion
-   108  
100 delay(1000); // maybe 750ms is enough, maybe not 109 // Delay for measurement, maybe 750ms is enough, maybe not
-   110 digitalWrite(13, HIGH); // set the LED on
-   111 delay(500);
-   112 digitalWrite(13, LOW); // set the LED off
-   113 delay(500);
-   114  
101 present = ds.reset(); 115 present = ds.reset();
102 ds.select(addr); 116 ds.select(addr);
103 ds.write(0xBE); // Read Scratchpad 117 ds.write(0xBE); // Read Scratchpad
104   118  
105 Serial.print("P="); 119 Serial.print("P=");
Line 114... Line 128...
114 Serial.print(" CRC="); 128 Serial.print(" CRC=");
115 Serial.print( OneWire::crc8( data, 8), HEX); 129 Serial.print( OneWire::crc8( data, 8), HEX);
116 Serial.println(); 130 Serial.println();
117   131  
118 Serial.print("Light0: COMMAND="); 132 Serial.print("Light0: COMMAND=");
119   -  
120 // Setup device 133 // Setup device
121 Wire.beginTransmission(address); 134 Wire.beginTransmission(light0);
122 Wire.send(0x00); // sends address 135 Wire.send(0x00); // sends light0
123 Wire.send(0b11000001); // setup (eye light sensing; measurement range 2 [4000 lx]) 136 Wire.send(0b11000001); // setup (eye light sensing; measurement range 2 [4000 lx])
124 Wire.endTransmission(); // stop transmitting 137 Wire.endTransmission(); // stop transmitting
125   138  
126 // Delay for measurement 139 // Delay for measurement
127 digitalWrite(13, HIGH); // set the LED on 140 digitalWrite(13, HIGH); // set the LED on
128 delay(500); 141 delay(55);
129 digitalWrite(13, LOW); // set the LED off 142 digitalWrite(13, LOW); // set the LED off
130 delay(500); 143 delay(55);
131   -  
132   144  
133 // Connect to device and set register address 145 // Connect to device and set register light0
134 Wire.beginTransmission(address); 146 Wire.beginTransmission(light0);
135 Wire.send(0x00); // sends address 147 Wire.send(0x00); // sends light0
136 Wire.endTransmission(); // stop transmitting 148 Wire.endTransmission(); // stop transmitting
137 // Connect to device and request one byte 149 // Connect to device and request one byte
138 Wire.beginTransmission(address); 150 Wire.beginTransmission(light0);
139 Wire.requestFrom(address, 1); 151 Wire.requestFrom(light0, 1);
140 dd = Wire.receive(); 152 dd = Wire.receive();
141 Wire.endTransmission(); // stop transmitting 153 Wire.endTransmission(); // stop transmitting
142 Serial.print(dd, HEX); 154 Serial.print(dd, HEX);
143   155  
144 Serial.print(" LSB="); 156 Serial.print(" LSB=");
145 // Connect to device and set register address 157 // Connect to device and set register light0
146 Wire.beginTransmission(address); 158 Wire.beginTransmission(light0);
147 Wire.send(0x01); // sends address 159 Wire.send(0x01); // sends light0
148 Wire.endTransmission(); // stop transmitting 160 Wire.endTransmission(); // stop transmitting
149 // Connect to device and request one byte 161 // Connect to device and request one byte
150 Wire.beginTransmission(address); 162 Wire.beginTransmission(light0);
151 Wire.requestFrom(address, 1); 163 Wire.requestFrom(light0, 1);
152 dd = Wire.receive(); 164 dd = Wire.receive();
153 Wire.endTransmission(); // stop transmitting 165 Wire.endTransmission(); // stop transmitting
154 Serial.print(dd, HEX); 166 Serial.print(dd, HEX);
155   167  
156 Serial.print(" MSB="); 168 Serial.print(" MSB=");
157 // Connect to device and set register address 169 // Connect to device and set register light0
158 Wire.beginTransmission(address); 170 Wire.beginTransmission(light0);
159 Wire.send(0x02); // sends address 171 Wire.send(0x02); // sends light0
160 Wire.endTransmission(); // stop transmitting 172 Wire.endTransmission(); // stop transmitting
161 // Connect to device and request one byte 173 // Connect to device and request one byte
-   174 Wire.beginTransmission(light0);
-   175 Wire.requestFrom(light0, 1);
-   176 dd = Wire.receive();
-   177 Wire.endTransmission(); // stop transmitting
-   178 Serial.println(dd, HEX);
-   179  
-   180 Serial.print("Light1: COMMAND=");
-   181 // Setup device
-   182 Wire.beginTransmission(light1);
-   183 Wire.send(0x00); // sends light0
-   184 Wire.send(0b11000001); // setup (eye light sensing; measurement range 2 [4000 lx])
-   185 Wire.endTransmission(); // stop transmitting
-   186  
-   187 // Delay for measurement
-   188 digitalWrite(13, HIGH); // set the LED on
-   189 delay(55);
-   190 digitalWrite(13, LOW); // set the LED off
-   191 delay(55);
-   192  
-   193 // Connect to device and set register light0
-   194 Wire.beginTransmission(light1);
-   195 Wire.send(0x00); // sends light0
-   196 Wire.endTransmission(); // stop transmitting
-   197 // Connect to device and request one byte
-   198 Wire.beginTransmission(light1);
-   199 Wire.requestFrom(light1, 1);
-   200 dd = Wire.receive();
-   201 Wire.endTransmission(); // stop transmitting
-   202 Serial.print(dd, HEX);
-   203  
-   204 Serial.print(" LSB=");
-   205 // Connect to device and set register light0
-   206 Wire.beginTransmission(light1);
-   207 Wire.send(0x01); // sends light0
-   208 Wire.endTransmission(); // stop transmitting
-   209 // Connect to device and request one byte
162 Wire.beginTransmission(address); 210 Wire.beginTransmission(light1);
163 Wire.requestFrom(address, 1); 211 Wire.requestFrom(light1, 1);
164 dd = Wire.receive(); 212 dd = Wire.receive();
165 Wire.endTransmission(); // stop transmitting 213 Wire.endTransmission(); // stop transmitting
166 Serial.print(dd, HEX); 214 Serial.print(dd, HEX);
167   215  
168 Serial.print("\n"); 216 Serial.print(" MSB=");
-   217 // Connect to device and set register light0
-   218 Wire.beginTransmission(light1);
-   219 Wire.send(0x02); // sends light0
-   220 Wire.endTransmission(); // stop transmitting
-   221 // Connect to device and request one byte
-   222 Wire.beginTransmission(light1);
-   223 Wire.requestFrom(light1, 1);
-   224 dd = Wire.receive();
-   225 Wire.endTransmission(); // stop transmitting
-   226 Serial.println(dd, HEX);
169   227  
-   228 Serial.print("X=");
-   229 Serial.print(analogRead(A0), HEX);
-   230 Serial.print(" Y=");
-   231 Serial.print(analogRead(A1), HEX);
-   232 Serial.print(" Z=");
-   233 Serial.println(analogRead(A2), HEX);
170 } 234 }
171   235  
172   236  
173   237