Rev 2245 Rev 2246
Line 18... Line 18...
18 #include <SD.h> 18 #include <SD.h>
19   19  
20 #define chipSelect 4 20 #define chipSelect 4
21   21  
22 #define address 0x44 // A0 = L 22 #define address 0x44 // A0 = L
-   23  
-   24 #define LIGHT_ENABLE 1
-   25 #define LIGHT_DISABLE 0
-   26  
-   27 #define LIGHT_MEASUREMENT_ONETIME 0
-   28 #define LIGHT_MEASUREMENT_CONTINUOUS 1
-   29  
23 #define SENSE_VIS 0 30 #define LIGHT_SENSE_VIS 0
24 #define SENSE_IR 1 31 #define LIGHT_SENSE_IR 1
-   32  
-   33 #define LIGHT_TIMING_INTERNAL_16 0b000
-   34 #define LIGHT_TIMING_INTERNAL_12 0b001
-   35 #define LIGHT_TIMING_INTERNAL_8 0b010
-   36 #define LIGHT_TIMING_INTERNAL_4 0b011
-   37 #define LIGHT_TIMING_EXTERNAL_ADC 0b100
-   38 #define LIGHT_TIMING_EXTERNAL_TIMER 0b101
25   39  
26 #define LIGHT_AUTORANGE 0 40 #define LIGHT_AUTORANGE 0
-   41  
27 #define LIGHT_RANGE1 1 42 #define LIGHT_RANGE1 1
28 #define LIGHT_RANGE2 2 43 #define LIGHT_RANGE2 2
29 #define LIGHT_RANGE3 3 44 #define LIGHT_RANGE3 3
30 #define LIGHT_RANGE4 4 45 #define LIGHT_RANGE4 4
31   46  
Line 73... Line 88...
73 delay(500); 88 delay(500);
74 digitalWrite(3, LOW); // set the LED off 89 digitalWrite(3, LOW); // set the LED off
75 delay(500); 90 delay(500);
76 } 91 }
77   92  
78 int set_light_sensor(int mode) 93 int set_light_sensor(int en, int mode, int light, int res, int range)
79 { 94 {
80 int command; 95 int command=0;
-   96  
-   97 commad= (en << 7 & 0b10000000);
81 98
82 switch (mode) 99 switch (light)
83 { 100 {
84 case SENSE_VIS: 101 case LIGHT_SENSE_VIS:
85 { 102 {
86 command=0b11000000; // setup (eye light sensing; one time measurement; measurement range 1) 103 command=0b11000000; // setup (eye light sensing; one time measurement; measurement range 1)
87 break; 104 break;
88 } 105 }
89   106  
90 case SENSE_IR: 107 case LIGHT_SENSE_IR:
91 { 108 {
92 command=0b11100000; // setup (eye light sensing; measurement range 2 [4000 lx]) 109 command=0b11100000; // setup (eye light sensing; measurement range 2 [4000 lx])
93 break; 110 break;
94 } 111 }
95 112
Line 112... Line 129...
112 // verify written command byte 129 // verify written command byte
113 Wire.beginTransmission(address); 130 Wire.beginTransmission(address);
114 Wire.requestFrom(address, 1); 131 Wire.requestFrom(address, 1);
115 if (command != Wire.receive()) 132 if (command != Wire.receive())
116 { 133 {
-   134 Serial.println(data, BIN);
117 return 4; 135 return 4;
118 Serial.print(data, BIN); -  
119 } 136 }
120 Wire.endTransmission(); // stop transmitting 137 Wire.endTransmission(); // stop transmitting
121 light_sensor_setup=command; 138 light_sensor_setup=command;
-   139 return 0;
122 } 140 }
123   141  
124 float get_light_measurement() 142 float get_light_measurement()
125 { 143 {
126 int ret=0; 144 int ret=0;
Line 154... Line 172...
154 { 172 {
155 float luxVIS=0; 173 float luxVIS=0;
156 float luxIR=0; 174 float luxIR=0;
157 float time; 175 float time;
158   176  
159 set_light_sensor(SENSE_VIS); //setup sensor for visible measuring 177 set_light_sensor(LIGHT_SENSE_VIS); //setup sensor for visible measuring
160 led_blink(); // Delay for measurement 178 led_blink(); // Delay for measurement
161 luxVIS=get_light_measurement(); 179 luxVIS=get_light_measurement();
162   180  
163 time=millis()/1000.0; 181 time=millis()/1000.0;
164 182
165 set_light_sensor(SENSE_IR); // setup sensor for infrared measuring 183 set_light_sensor(LIGHT_SENSE_IR); // setup sensor for infrared measuring
166 led_blink(); // Delay for measurement 184 led_blink(); // Delay for measurement
167 luxIR=get_light_measurement(); 185 luxIR=get_light_measurement();
168 186
169 // open the file. note that only one file can be open at a time, 187 // open the file. note that only one file can be open at a time,
170 // so you have to close this one before opening another. 188 // so you have to close this one before opening another.