Line 28... |
Line 28... |
28 |
#define LIGHT_RANGE1 1 |
28 |
#define LIGHT_RANGE1 1 |
29 |
#define LIGHT_RANGE2 2 |
29 |
#define LIGHT_RANGE2 2 |
30 |
#define LIGHT_RANGE3 3 |
30 |
#define LIGHT_RANGE3 3 |
31 |
#define LIGHT_RANGE4 4 |
31 |
#define LIGHT_RANGE4 4 |
32 |
|
32 |
|
- |
|
33 |
char filename[13]; |
- |
|
34 |
int data = 0; |
- |
|
35 |
int light_sensor_setup; |
- |
|
36 |
|
33 |
void setup() |
37 |
void setup() |
34 |
{ |
38 |
{ |
- |
|
39 |
int count=0; |
- |
|
40 |
|
35 |
Wire.begin(); // join i2c bus (address optional for master) |
41 |
Wire.begin(); // join i2c bus (address optional for master) |
36 |
|
42 |
|
37 |
pinMode(3, OUTPUT); // LED pro blikani, aby bylo videt, ze to neco dela |
43 |
pinMode(3, OUTPUT); // LED pro blikani, aby bylo videt, ze to neco dela |
38 |
pinMode(5, OUTPUT); // LED pro blikani, aby bylo videt, ze to neco dela |
44 |
pinMode(5, OUTPUT); // LED pro blikani, aby bylo videt, ze to neco dela |
39 |
Serial.begin(9600); // Zmerena intenzita osvetleni se bude vypisovat na seriovou linku |
45 |
Serial.begin(9600); // Zmerena intenzita osvetleni se bude vypisovat na seriovou linku |
Line 48... |
Line 54... |
48 |
Serial.println("Card failed, or not present"); |
54 |
Serial.println("Card failed, or not present"); |
49 |
// don't do anything more: |
55 |
// don't do anything more: |
50 |
return; |
56 |
return; |
51 |
} |
57 |
} |
52 |
Serial.println("card initialized."); |
58 |
Serial.println("card initialized."); |
- |
|
59 |
Serial.print("searching for files..."); |
- |
|
60 |
|
53 |
|
61 |
do |
- |
|
62 |
{ |
- |
|
63 |
sprintf(filename,"Lux%d.txt",count); |
- |
|
64 |
count++; |
- |
|
65 |
} |
- |
|
66 |
while(SD.exists(filename)); |
- |
|
67 |
Serial.print("Using "); |
- |
|
68 |
Serial.println(filename); |
54 |
} |
69 |
} |
55 |
|
70 |
|
56 |
int data = 0; |
- |
|
57 |
int light_sensor_setup; |
- |
|
58 |
|
- |
|
59 |
void led_blink() |
71 |
void led_blink() |
60 |
{ |
72 |
{ |
61 |
digitalWrite(3, HIGH); // set the LED on |
73 |
digitalWrite(3, HIGH); // set the LED on |
62 |
delay(500); |
74 |
delay(500); |
63 |
digitalWrite(3, LOW); // set the LED off |
75 |
digitalWrite(3, LOW); // set the LED off |
64 |
delay(500); |
76 |
delay(500); |
65 |
} |
77 |
} |
66 |
|
78 |
|
67 |
|
- |
|
68 |
int set_light_sensor(int mode) |
79 |
int set_light_sensor(int mode) |
69 |
{ |
80 |
{ |
70 |
int command; |
81 |
int command; |
71 |
|
82 |
|
72 |
switch (mode) |
83 |
switch (mode) |
Line 162... |
Line 173... |
162 |
|
173 |
|
163 |
set_light_sensor(SENSE_VIS); //setup sensor for visible measuring |
174 |
set_light_sensor(SENSE_VIS); //setup sensor for visible measuring |
164 |
led_blink(); // Delay for measurement |
175 |
led_blink(); // Delay for measurement |
165 |
luxVIS=get_light_measurement(); |
176 |
luxVIS=get_light_measurement(); |
166 |
|
177 |
|
167 |
time=millis()/1000; |
178 |
time=millis()/1000.0; |
168 |
|
179 |
|
169 |
set_light_sensor(SENSE_IR); // setup sensor for infrared measuring |
180 |
set_light_sensor(SENSE_IR); // setup sensor for infrared measuring |
170 |
led_blink(); // Delay for measurement |
181 |
led_blink(); // Delay for measurement |
171 |
luxIR=get_light_measurement(); |
182 |
luxIR=get_light_measurement(); |
172 |
|
183 |
|
173 |
// open the file. note that only one file can be open at a time, |
184 |
// open the file. note that only one file can be open at a time, |
174 |
// so you have to close this one before opening another. |
185 |
// so you have to close this one before opening another. |
175 |
File dataFile = SD.open("datalog.txt", FILE_WRITE); |
186 |
File dataFile = SD.open(filename, FILE_WRITE); |
176 |
|
187 |
|
177 |
// if the file is available, write to it: |
188 |
// if the file is available, write to it: |
178 |
if (dataFile) { |
189 |
if (dataFile) { |
179 |
dataFile.print("$LUX0.1 "); |
190 |
dataFile.print("$LUX0.1 "); |
180 |
dataFile.print(time,3); |
191 |
dataFile.print(time,3); |
Line 192... |
Line 203... |
192 |
Serial.print(" "); |
203 |
Serial.print(" "); |
193 |
Serial.println(luxIR,3); |
204 |
Serial.println(luxIR,3); |
194 |
} |
205 |
} |
195 |
// if the file isn't open, pop up an error: |
206 |
// if the file isn't open, pop up an error: |
196 |
else { |
207 |
else { |
197 |
Serial.println("error opening datalog.txt"); |
208 |
Serial.print("error opening "); |
- |
|
209 |
Serial.println(filename); |
198 |
} |
210 |
} |
199 |
} |
211 |
} |
200 |
|
212 |
|