|
|
@ -12,10 +12,14 @@ void loop() {
|
|
|
|
int ss = 20; // sample size for light sensor
|
|
|
|
int ss = 20; // sample size for light sensor
|
|
|
|
int average = 0;
|
|
|
|
int average = 0;
|
|
|
|
for (int x = 0; x < ss; x++) {
|
|
|
|
for (int x = 0; x < ss; x++) {
|
|
|
|
average += analogRead(light) / 4;
|
|
|
|
//average += 256-log(256-analogRead(0) / 4) * (256 /5.55); // old linearization
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//linearization using resistance to lux relationship
|
|
|
|
|
|
|
|
average += (1250000.0 * pow(1023-analogRead(0), -1.4059) - 73) / 2.08;
|
|
|
|
delay(3);
|
|
|
|
delay(3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
average /= ss;
|
|
|
|
average /= ss;
|
|
|
|
|
|
|
|
//Serial.println(average);
|
|
|
|
if(oldavg == 0) {
|
|
|
|
if(oldavg == 0) {
|
|
|
|
oldavg = average;
|
|
|
|
oldavg = average;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -25,11 +29,11 @@ void loop() {
|
|
|
|
Serial.println(average);
|
|
|
|
Serial.println(average);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while(oldavg < average) {
|
|
|
|
while(oldavg < average) {
|
|
|
|
oldavg ++;
|
|
|
|
oldavg += 1;
|
|
|
|
setColor(oldavg);
|
|
|
|
setColor(oldavg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while(oldavg > average) {
|
|
|
|
while(oldavg > average) {
|
|
|
|
oldavg --;
|
|
|
|
oldavg -= 1;
|
|
|
|
setColor(oldavg);
|
|
|
|
setColor(oldavg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
digitalWrite(13, LOW);
|
|
|
|
digitalWrite(13, LOW);
|
|
|
@ -66,10 +70,14 @@ void loop() {
|
|
|
|
int ss = 20; // sample size for light sensor
|
|
|
|
int ss = 20; // sample size for light sensor
|
|
|
|
int average = 0;
|
|
|
|
int average = 0;
|
|
|
|
for (int x = 0; x < ss; x++) {
|
|
|
|
for (int x = 0; x < ss; x++) {
|
|
|
|
average += analogRead(light) / 4;
|
|
|
|
//average += 256-log(256-analogRead(0) / 4) * (256 /5.55); // old linearization
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//linearization using resistance to lux relationship
|
|
|
|
|
|
|
|
average += (1250000.0 * pow(1023-analogRead(0), -1.4059) - 73) / 2.08;
|
|
|
|
delay(3);
|
|
|
|
delay(3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
average /= ss;
|
|
|
|
average /= ss;
|
|
|
|
|
|
|
|
//Serial.println(average);
|
|
|
|
if(oldavg == 0) {
|
|
|
|
if(oldavg == 0) {
|
|
|
|
oldavg = average;
|
|
|
|
oldavg = average;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -79,11 +87,11 @@ void loop() {
|
|
|
|
Serial.println(average);
|
|
|
|
Serial.println(average);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while(oldavg < average) {
|
|
|
|
while(oldavg < average) {
|
|
|
|
oldavg ++;
|
|
|
|
oldavg += 1;
|
|
|
|
setColor(oldavg);
|
|
|
|
setColor(oldavg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while(oldavg > average) {
|
|
|
|
while(oldavg > average) {
|
|
|
|
oldavg --;
|
|
|
|
oldavg -= 1;
|
|
|
|
setColor(oldavg);
|
|
|
|
setColor(oldavg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
digitalWrite(13, LOW);
|
|
|
|
digitalWrite(13, LOW);
|
|
|
|