Added photoresistor and amb. light compensation
+ Added ambient light compensation logic + Added photocell on scheme + Added photoresitor to README.md --HG-- branch : phtoresistor
This commit is contained in:
@@ -12,6 +12,8 @@
|
||||
* usb phone charger as power supply
|
||||
* 2 push buttons
|
||||
* 1 on/off switch
|
||||
* 1 photoresistor
|
||||
* 1 resistor to make secund shoulder of photosensitive "bridge", 10 kOhms, 0.25 watts
|
||||
* Gainta G521G enclosure (92x66.5x28мм)
|
||||
* 5m power cord
|
||||
|
||||
|
||||
BIN
clock_schem.pdf
BIN
clock_schem.pdf
Binary file not shown.
@@ -61,6 +61,10 @@ bool dot = true;
|
||||
|
||||
/* time inaccuracy compensation flag */
|
||||
uint8_t compflag = 0;
|
||||
const uint8_t timeSkew = 6; // assume that clock runs faster than should
|
||||
|
||||
/* ambient light compensation aka night mode */
|
||||
const int photoPin = A2;
|
||||
|
||||
void setup()
|
||||
{
|
||||
@@ -70,7 +74,12 @@ void setup()
|
||||
byte digitPins[] = {9, 10, 11, 12};
|
||||
byte segmentPins[] = {2, 3, 4, 5, 6, 7, 8, 13};
|
||||
bool resistorsOnSegments = true; // 8 resistors, 330 Ohms each
|
||||
bool updateWithDelays = false; // Default. Recommended
|
||||
/* updateWithDelays defaults to false and it is recommended value,
|
||||
* but i was unable to make my display to change brightness with
|
||||
* recommended value, so i have to use updateWithDelays=true,
|
||||
* in this case brightness gets changed.
|
||||
*/
|
||||
bool updateWithDelays = true; // Default. Recommended
|
||||
|
||||
/* without it there is visual bug at 0 o'clock, and in current version
|
||||
* of SevSeg' setChars() does not dots at all */
|
||||
@@ -96,6 +105,9 @@ void setup()
|
||||
// setup control buttons
|
||||
pinMode(hrs_btn, INPUT_PULLUP);
|
||||
pinMode(min_btn, INPUT_PULLUP);
|
||||
|
||||
// setup brigtness sensor
|
||||
pinMode(photoPin, INPUT);
|
||||
}
|
||||
|
||||
void loop()
|
||||
@@ -104,6 +116,7 @@ void loop()
|
||||
currentPushTimer = currentMillis;
|
||||
char str[4];
|
||||
float d;
|
||||
unsigned int ambLight = analogRead(photoPin);
|
||||
|
||||
clock.getTime();
|
||||
|
||||
@@ -162,7 +175,7 @@ void loop()
|
||||
|
||||
if ((clock.hour == 21) and (clock.minute == 21) and
|
||||
(clock.second == 21) and (compflag == 0)) {
|
||||
clock.fillByHMS(clock.hour, clock.minute, 14);
|
||||
clock.fillByHMS(clock.hour, clock.minute, (clock.second - timeSkew));
|
||||
clock.setTime();
|
||||
compflag = 1;
|
||||
}
|
||||
@@ -191,6 +204,31 @@ void loop()
|
||||
}
|
||||
}
|
||||
|
||||
/* ambient light compensation
|
||||
* ambLight can be in range of 0..1023, if it 800, it has point to use fullbright
|
||||
*/
|
||||
if (ambLight >= 940) {
|
||||
Display.setBrightness(100);
|
||||
} else if ((ambLight < 900) and (ambLight >= 840)) {
|
||||
Display.setBrightness(95);
|
||||
} else if ((ambLight < 800) and (ambLight >= 735)) {
|
||||
Display.setBrightness(70);
|
||||
} else if ((ambLight < 700) and (ambLight >= 635)) {
|
||||
Display.setBrightness(25);
|
||||
} else if ((ambLight < 600) and (ambLight >= 530)) {
|
||||
Display.setBrightness(15);
|
||||
} else if ((ambLight < 500) and (ambLight >= 430)) {
|
||||
Display.setBrightness(12);
|
||||
} else if ((ambLight < 400) and (ambLight >= 325)) {
|
||||
Display.setBrightness(10);
|
||||
} else if ((ambLight < 300) and (ambLight >= 220)) {
|
||||
Display.setBrightness(8);
|
||||
} else if ((ambLight < 200) and (ambLight >= 110)) {
|
||||
Display.setBrightness(7);
|
||||
} else if (ambLight < 100) {
|
||||
Display.setBrightness(6);
|
||||
}
|
||||
|
||||
Display.refreshDisplay();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user