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 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 light1) |
7 |
|
7 |
|
8 |
#define LAMP1 13 // Callibration Lamp 1 |
8 |
#define LAMP1 13 // Callibration Lamp 1 |
9 |
#define LAMP2 6 // Callibration Lamp 2 |
9 |
#define LAMP2 6 // Callibration Lamp 2 |
10 |
#define FW1 7 // FilterWheel 1 |
10 |
#define FW1 7 // FilterWheel 1 |
11 |
#define FW2 8 // FilterWheel 1 |
11 |
#define FW2 8 // FilterWheel 1 |
Line 20... |
Line 20... |
20 |
#define M3 11 |
20 |
#define M3 11 |
21 |
#define M4 12 |
21 |
#define M4 12 |
22 |
Stepper myStepper(steps, M1,M2,M3,M4); |
22 |
Stepper myStepper(steps, M1,M2,M3,M4); |
23 |
|
23 |
|
24 |
// DS18S20 Temperature chip |
24 |
// DS18S20 Temperature chip |
25 |
OneWire ds(5); // 1-Wire |
25 |
OneWire ds(5); // 1-Wire pin |
- |
|
26 |
|
26 |
byte addr[8]; // Addres |
27 |
byte addr[8]; // 1-Wire Address |
27 |
boolean sense; |
28 |
boolean sense; // Sense of revolution |
28 |
|
29 |
|
29 |
void setup() |
30 |
void setup() |
30 |
{ |
31 |
{ |
31 |
sense=true; |
32 |
sense=true; |
32 |
|
33 |
|
Line 37... |
Line 38... |
37 |
pinMode(FW3, OUTPUT); |
38 |
pinMode(FW3, OUTPUT); |
38 |
|
39 |
|
39 |
// initialize the serial port: |
40 |
// initialize the serial port: |
40 |
Serial.begin(9600); |
41 |
Serial.begin(9600); |
41 |
|
42 |
|
42 |
Wire.begin(); // join i2c bus (light0 optional for master) |
43 |
Wire.begin(); // join i2c bus |
43 |
} |
44 |
} |
44 |
|
45 |
|
45 |
|
46 |
|
46 |
void loop() |
47 |
void loop() |
47 |
{ |
48 |
{ |
48 |
byte i,n; |
49 |
byte i,n; // for fors |
49 |
byte present = 0; |
50 |
byte present = 0; // for 1-Wire |
50 |
byte data[12]; |
51 |
byte data[12]; // data from temperature |
51 |
byte inByte; |
52 |
byte inByte; // RS232 data |
52 |
int dd=0; |
53 |
int dd=0; // data from light |
53 |
|
54 |
|
54 |
digitalWrite(LAMP1, HIGH); // All outputs OFF |
55 |
digitalWrite(LAMP1, HIGH); // All outputs OFF |
55 |
digitalWrite(LAMP2, HIGH); |
56 |
digitalWrite(LAMP2, HIGH); |
56 |
digitalWrite(FW1, HIGH); |
57 |
digitalWrite(FW1, HIGH); |
57 |
digitalWrite(FW2, HIGH); |
58 |
digitalWrite(FW2, HIGH); |
Line 63... |
Line 64... |
63 |
// if we get a valid byte |
64 |
// if we get a valid byte |
64 |
if (Serial.available() > 0) |
65 |
if (Serial.available() > 0) |
65 |
{ |
66 |
{ |
66 |
// get incoming byte: |
67 |
// get incoming byte: |
67 |
inByte = Serial.read(); |
68 |
inByte = Serial.read(); |
68 |
Serial.print("Prijat znak: "); |
69 |
Serial.print("Incoming char: "); |
69 |
Serial.print( inByte, HEX); |
70 |
Serial.print( inByte, HEX); |
70 |
Serial.println(); |
71 |
Serial.println(); |
71 |
} |
72 |
} |
72 |
|
73 |
|
73 |
//--------------------------------------------------------- Motor |
74 |
//--------------------------------------------------------- Motor |
74 |
if (sense) |
75 |
if (sense) |
75 |
{ |
76 |
{ |
76 |
// step one revolution in one direction: |
77 |
// one revolution in one direction |
77 |
Serial.println("clockwise"); |
78 |
Serial.println("clockwise"); |
78 |
myStepper.setSpeed(sspeed/2); |
79 |
myStepper.setSpeed(sspeed/2); |
79 |
myStepper.step(30); |
80 |
myStepper.step(30); |
80 |
myStepper.setSpeed(sspeed); |
81 |
myStepper.setSpeed(sspeed); |
81 |
myStepper.step(steps-50); |
82 |
myStepper.step(steps-50); |
Line 87... |
Line 88... |
87 |
digitalWrite(M3, LOW); |
88 |
digitalWrite(M3, LOW); |
88 |
digitalWrite(M4, LOW); |
89 |
digitalWrite(M4, LOW); |
89 |
} |
90 |
} |
90 |
else |
91 |
else |
91 |
{ |
92 |
{ |
92 |
// step one revolution in the other direction: |
93 |
// one revolution in the other direction: |
93 |
Serial.println("counterclockwise"); |
94 |
Serial.println("counterclockwise"); |
94 |
myStepper.setSpeed(sspeed/2); |
95 |
myStepper.setSpeed(sspeed/2); |
95 |
myStepper.step(-30); |
96 |
myStepper.step(-30); |
96 |
myStepper.setSpeed(sspeed); |
97 |
myStepper.setSpeed(sspeed); |
97 |
myStepper.step(-(steps-50)); |
98 |
myStepper.step(-(steps-50)); |
Line 108... |
Line 109... |
108 |
|
109 |
|
109 |
//--------------------------------------------------------- 1-Wire bus |
110 |
//--------------------------------------------------------- 1-Wire bus |
110 |
ds.reset_search(); |
111 |
ds.reset_search(); |
111 |
for(n=0;n<2;n++) |
112 |
for(n=0;n<2;n++) |
112 |
{ |
113 |
{ |
113 |
if ( !ds.search(addr)) |
114 |
if ( !ds.search(addr)) // search for next thermometer |
114 |
{ |
115 |
{ |
115 |
continue; |
116 |
continue; |
116 |
} |
117 |
} |
117 |
|
118 |
|
118 |
Serial.print("R="); |
119 |
Serial.print("R="); |
Line 153... |
Line 154... |
153 |
|
154 |
|
154 |
//------------------------------------------------------- Light 0 |
155 |
//------------------------------------------------------- Light 0 |
155 |
Serial.print("Light0: COMMAND="); |
156 |
Serial.print("Light0: COMMAND="); |
156 |
// Setup device |
157 |
// Setup device |
157 |
Wire.beginTransmission(light0); |
158 |
Wire.beginTransmission(light0); |
158 |
Wire.send(0x00); // sends light0 |
159 |
Wire.send(0x00); // command register |
159 |
Wire.send(0b11000001); // setup (eye light sensing; measurement range 2 [4000 lx]) |
160 |
Wire.send(0b11000001); // setup (eye light sensing; measurement range 2 [4000 lx]) |
160 |
Wire.endTransmission(); // stop transmitting |
161 |
Wire.endTransmission(); // stop transmitting |
161 |
|
162 |
|
162 |
// Delay for measurement, maybe 100ms is enough, maybe not |
163 |
// Delay for measurement, maybe 100ms is enough, maybe not |
163 |
delay(110); |
164 |
delay(110); |
Line 200... |
Line 201... |
200 |
|
201 |
|
201 |
//------------------------------------------------------- Light 1 |
202 |
//------------------------------------------------------- Light 1 |
202 |
Serial.print("Light1: COMMAND="); |
203 |
Serial.print("Light1: COMMAND="); |
203 |
// Setup device |
204 |
// Setup device |
204 |
Wire.beginTransmission(light1); |
205 |
Wire.beginTransmission(light1); |
205 |
Wire.send(0x00); // sends light0 |
206 |
Wire.send(0x00); // command register |
206 |
Wire.send(0b11000001); // setup (eye light sensing; measurement range 2 [4000 lx]) |
207 |
Wire.send(0b11000001); // setup (eye light sensing; measurement range 2 [4000 lx]) |
207 |
Wire.endTransmission(); // stop transmitting |
208 |
Wire.endTransmission(); // stop transmitting |
208 |
|
209 |
|
209 |
// Delay for measurement, maybe 100ms is enough, maybe not |
210 |
// Delay for measurement, maybe 100ms is enough, maybe not |
210 |
delay(110); |
211 |
delay(110); |