Rev 2034 Rev 2035
Line 3... Line 3...
3 #include <Wire.h> 3 #include <Wire.h>
4   4  
5 #define light0 0x44 // A0 = L (I2C light0) 5 #define light0 0x44 // A0 = L (I2C light0)
6 #define light1 0x45 // A0 = H (I2C light0) 6 #define light1 0x45 // A0 = H (I2C light0)
7   7  
-   8 #define LAMP1 13 // Callibration Lamp 1
-   9 #define LAMP2 6 // Callibration Lamp 2
-   10 #define FW1 7 // FilterWheel 1
-   11 #define FW2 8 // FilterWheel 1
-   12 #define FW3 3 // FilterWheel 1
-   13  
8 const int steps = 200; //3200; // change this to fit the number of steps 14 const int steps = 200; //3200; // change this to fit the number of steps
9 const int sspeed = 100; // stepper motor speed 15 const int sspeed = 100; // stepper motor speed
10   16  
11 // initialize the stepper library on pins 17 // initialize the stepper library on pins
-   18 #define M1 9
-   19 #define M2 10
-   20 #define M3 11
-   21 #define M4 12
12 Stepper myStepper(steps, 9,10,11,12); 22 Stepper myStepper(steps, M1,M2,M3,M4);
13   23  
14 // DS18S20 Temperature chip 24 // DS18S20 Temperature chip
15 OneWire ds(5); // 1-Wire 25 OneWire ds(5); // 1-Wire
16 byte addr[8]; // Addres 26 byte addr[8]; // Addres
-   27 boolean sense;
17   28  
18 void setup() 29 void setup()
19 { 30 {
-   31 sense=true;
-   32
-   33 pinMode(LAMP1, OUTPUT);
-   34 pinMode(LAMP2, OUTPUT);
20 pinMode(13, OUTPUT); // LED 35 pinMode(FW1, OUTPUT);
-   36 pinMode(FW2, OUTPUT);
21 digitalWrite(13, LOW); // LED ON 37 pinMode(FW3, OUTPUT);
22   38  
23 // initialize the serial port: 39 // initialize the serial port:
24 Serial.begin(9600); 40 Serial.begin(9600);
25 41
26 Wire.begin(); // join i2c bus (light0 optional for master) 42 Wire.begin(); // join i2c bus (light0 optional for master)
27 } -  
28   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 }
29   59  
30 byte sense=0; -  
31   60  
32 void loop() 61 void loop()
33 { 62 {
34 byte i; 63 byte i;
35 byte present = 0; 64 byte present = 0;
36 byte data[12]; 65 byte data[12];
37 byte inByte; 66 byte inByte;
38 int dd=0; 67 int dd=0;
39 68
-   69 digitalWrite(LAMP1, HIGH); // All outputs OFF
-   70 digitalWrite(LAMP2, HIGH);
-   71 digitalWrite(FW1, HIGH);
-   72 digitalWrite(FW2, HIGH);
-   73 digitalWrite(FW3, HIGH);
-   74 delay(300);
-   75 digitalWrite(LAMP1, LOW); // blik
-   76  
40 // if we get a valid byte 77 // if we get a valid byte
41 if (Serial.available() > 0) 78 if (Serial.available() > 0)
42 { 79 {
43 // get incoming byte: 80 // get incoming byte:
44 inByte = Serial.read(); 81 inByte = Serial.read();
Line 46... Line 83...
46 Serial.print( inByte, HEX); 83 Serial.print( inByte, HEX);
47 Serial.println(); 84 Serial.println();
48 } 85 }
49 86
50 //--------------------------------------------------------- Motor 87 //--------------------------------------------------------- Motor
51 if(sense) 88 if (sense)
52 { 89 {
53 digitalWrite(13, LOW); // blik -  
54 // step one revolution in one direction: 90 // step one revolution in one direction:
55 Serial.println("clockwise"); 91 Serial.println("clockwise");
56 myStepper.setSpeed(sspeed/2); 92 myStepper.setSpeed(sspeed/2);
57 myStepper.step(30); 93 myStepper.step(30);
58 myStepper.setSpeed(sspeed); 94 myStepper.setSpeed(sspeed);
59 myStepper.step(steps-50); 95 myStepper.step(steps-50);
60 myStepper.setSpeed(sspeed/2); 96 myStepper.setSpeed(sspeed/2);
61 myStepper.step(20); 97 myStepper.step(20);
62 delay(50); 98 delay(50);
63 digitalWrite(9, LOW); 99 digitalWrite(M1, LOW);
64 digitalWrite(10, LOW); 100 digitalWrite(M2, LOW);
65 digitalWrite(11, LOW); 101 digitalWrite(M3, LOW);
66 digitalWrite(12, LOW); 102 digitalWrite(M4, LOW);
67 delay(500); -  
68 sense=0; -  
69 } 103 }
70 else 104 else
71 { 105 {
72 digitalWrite(13, HIGH); // blik -  
73 // step one revolution in the other direction: 106 // step one revolution in the other direction:
74 Serial.println("counterclockwise"); 107 Serial.println("counterclockwise");
75 myStepper.setSpeed(sspeed/2); 108 myStepper.setSpeed(sspeed/2);
76 myStepper.step(-30); 109 myStepper.step(-30);
77 myStepper.setSpeed(sspeed); 110 myStepper.setSpeed(sspeed);
78 myStepper.step(-(steps-50)); 111 myStepper.step(-(steps-50));
79 myStepper.setSpeed(sspeed/2); 112 myStepper.setSpeed(sspeed/2);
80 myStepper.step(-20); 113 myStepper.step(-20);
81 delay(50); 114 delay(50);
82 digitalWrite(9, LOW); 115 digitalWrite(M1, LOW);
83 digitalWrite(10, LOW); 116 digitalWrite(M2, LOW);
84 digitalWrite(11, LOW); 117 digitalWrite(M3, LOW);
85 digitalWrite(12, LOW); 118 digitalWrite(M4, LOW);
86 delay(500); -  
87 sense=1; -  
88 } 119 }
89 120 sense=!sense;
90 //--------------------------------------------------------- 1-Wire bus 121 digitalWrite(LAMP2, LOW); // blik
91   122  
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]) 123 //--------------------------------------------------------- 1-Wire bus
101 { -  
102 Serial.print("CRC is not valid!\n"); -  
103 return; -  
104 } -  
105 124
106 ds.reset(); 125 ds.reset();
107 ds.select(addr); 126 ds.select(addr);
108 ds.write(0x44,1); // start conversion 127 ds.write(0x44,1); // start conversion
109   128  
110 // Delay for measurement, maybe 750ms is enough, maybe not 129 // Delay for measurement, maybe 750ms is enough, maybe not
111 digitalWrite(13, HIGH); // set the LED on -  
112 delay(500); 130 delay(800);
113 digitalWrite(13, LOW); // set the LED off 131 digitalWrite(FW1, LOW); // blik
114 delay(500); -  
115   132  
116 present = ds.reset(); 133 present = ds.reset();
117 ds.select(addr); 134 ds.select(addr);
118 ds.write(0xBE); // Read Scratchpad 135 ds.write(0xBE); // Read Scratchpad
119   136  
Line 135... Line 152...
135 Wire.beginTransmission(light0); 152 Wire.beginTransmission(light0);
136 Wire.send(0x00); // sends light0 153 Wire.send(0x00); // sends light0
137 Wire.send(0b11000001); // setup (eye light sensing; measurement range 2 [4000 lx]) 154 Wire.send(0b11000001); // setup (eye light sensing; measurement range 2 [4000 lx])
138 Wire.endTransmission(); // stop transmitting 155 Wire.endTransmission(); // stop transmitting
139   156  
140 // Delay for measurement 157 // Delay for measurement, maybe 100ms is enough, maybe not
141 digitalWrite(13, HIGH); // set the LED on -  
142 delay(55); 158 delay(110);
143 digitalWrite(13, LOW); // set the LED off 159 digitalWrite(FW2, LOW); // blik
144 delay(55); -  
145   160  
146 // Connect to device and set register light0 161 // Connect to device and set register light0
147 Wire.beginTransmission(light0); 162 Wire.beginTransmission(light0);
148 Wire.send(0x00); // sends light0 163 Wire.send(0x00); // sends light0
149 Wire.endTransmission(); // stop transmitting 164 Wire.endTransmission(); // stop transmitting
Line 183... Line 198...
183 Wire.beginTransmission(light1); 198 Wire.beginTransmission(light1);
184 Wire.send(0x00); // sends light0 199 Wire.send(0x00); // sends light0
185 Wire.send(0b11000001); // setup (eye light sensing; measurement range 2 [4000 lx]) 200 Wire.send(0b11000001); // setup (eye light sensing; measurement range 2 [4000 lx])
186 Wire.endTransmission(); // stop transmitting 201 Wire.endTransmission(); // stop transmitting
187   202  
188 // Delay for measurement 203 // Delay for measurement, maybe 100ms is enough, maybe not
189 digitalWrite(13, HIGH); // set the LED on -  
190 delay(55); 204 delay(110);
191 digitalWrite(13, LOW); // set the LED off 205 digitalWrite(FW3, LOW); // blik
192 delay(55); -  
193   206  
194 // Connect to device and set register light0 207 // Connect to device and set register light0
195 Wire.beginTransmission(light1); 208 Wire.beginTransmission(light1);
196 Wire.send(0x00); // sends light0 209 Wire.send(0x00); // sends light0
197 Wire.endTransmission(); // stop transmitting 210 Wire.endTransmission(); // stop transmitting
Line 224... Line 237...
224 Wire.requestFrom(light1, 1); 237 Wire.requestFrom(light1, 1);
225 dd = Wire.receive(); 238 dd = Wire.receive();
226 Wire.endTransmission(); // stop transmitting 239 Wire.endTransmission(); // stop transmitting
227 Serial.println(dd, HEX); 240 Serial.println(dd, HEX);
228   241  
-   242 // Accelerometer
229 Serial.print("X="); 243 Serial.print("X=");
230 Serial.print(analogRead(A0)-512, DEC); 244 Serial.print(analogRead(A0)-512, DEC);
231 Serial.print(" Y="); 245 Serial.print(" Y=");
232 Serial.print(analogRead(A1)-512, DEC); 246 Serial.print(analogRead(A1)-512, DEC);
233 Serial.print(" Z="); 247 Serial.print(" Z=");