Light-set-en

Automatic change of the brightness of the clock display depending on the illumination

One of the functions useful for the clock user is the automatic change of the display brightness. When there is a high level of illumination in the room where the clock is used, the brightness of the clock  display automatically increases. When the light level is low, the brightness of the clock display automatically decreases. Thanks to this function, the clock will not blind your eyes in the evening and early in the morning, in a darkened room. And also will not annoy the inability to recognize the readings of the current time in a brightly lit room.

 

In the variable definition block, we will set the following variables that will store the current and previous
values of the display brightness depending on the current illumination of the room.
The illumination of the room will be determined by the value of the sensor.

int ligth_Intensity;
int ligth_Intensity2;

Subroutine for controlling the brightness of the clock display:

void light_set ()
{

/*
//////////////for the green display/////////////////
assign the variable «light_Intensity», the value of the brightness of the clock display,
depending on the level of illumination of the room according to the following algorithm:

if (analogRead(lightPin)>=200 & analogRead(lightPin)<=900) ligth_Intensity=(int(analogRead(lightPin)/75));// if the illumination is between 200 and 900,
set the brightness value of the clock display between «2» and «12»
if (analogRead(lightPin)<200) ligth_Intensity=0;//if the illumination is below 200, then set the brightness value of the clock display to «0» — the minimum value
if (analogRead(lightPin)>900) ligth_Intensity=15;// if the illumination is above 900, then set the brightness value of the clock display to «0» — the maximum value

if (abs(ligth_Intensity2 — ligth_Intensity)>2) {// to reduce the flicker effect, we will change the brightness of the watch display only
when the brightness of the display needs to be increased or decreased by more than 2 levels

ligth_Intensity2=ligth_Intensity;
matrix.setIntensity(ligth_Intensity);// setting the display brightness
}
//////////////for the green display/////////////////
*/

 

// a similar algorithm for a red display, the difference is only in the formula for calculating the brightness, which were determined empirically
//////////////for the red display/////////////////
if (analogRead(lightPin) >= 400 & analogRead(lightPin) <= 1000) ligth_Intensity = (int(analogRead(lightPin) / 100) — 3);


if (analogRead(lightPin) < 400) ligth_Intensity = 0;
if (analogRead(lightPin) > 1000) ligth_Intensity = 14;


if (abs(ligth_Intensity2 — ligth_Intensity) > 2) {

ligth_Intensity2 = ligth_Intensity;
matrix.setIntensity(ligth_Intensity);


}
//////////////for the red display/////////////////

}

In order for the function to work, you need to call it every time from the main program cycle before displaying the clock time readings.

light-set-ru

Автоматическое изменение яркости дисплея часов в зависимости от освещенности

Одна из полезных для пользователя часов функций — это автоматическое изменение яркости дисплея. Когда в помещении, где используются часы, высокий уровень освещенности, яркость дисплея часов автоматически увеличивается. Когда уровень освещенности низкий, яркость дисплея часов автоматически уменьшается. Благодаря этой функции часы не будут слепить глаза вечером и рано утром, в затемненном помещении. А также не будут раздражать невозможностью распознать показания текущего времени в ярка залитой светом комнате.

 

В блоке определения переменных зададим следующие переменные которые будут хранить текущее и предыдущее
значение яркости дисплея в зависимости от текущей освещенности помещения.
Освещенность помещения будем определять по значению датчика.

int ligth_Intensity;
int ligth_Intensity2;

Подпрограмма по управлению яркостью дисплея часов:

void light_set ()
{

/*
//////////////для зеленого дисплея/////////////////
присвоим переменной ligth_Intensity, значение яркости дисплея часов в зависимости от уровня освещенности помещения по следующему алгоритму:

if (analogRead(lightPin)>=200 & analogRead(lightPin)<=900) ligth_Intensity=(int(analogRead(lightPin)/75));// если освещенность между 200 и 900,
установим значение яркости дисплея часов между «2» и «12»
if (analogRead(lightPin)<200) ligth_Intensity=0;// если освещенность ниже 200, то установим значение яркости дисплея часов «0» — минимальное значение
if (analogRead(lightPin)>900) ligth_Intensity=15;// если освещенность выше 900, то установим значение яркости дисплея часов «0» — максимальное значение

if (abs(ligth_Intensity2 — ligth_Intensity)>2) {// чтобы снизить эффект мерцания, изменять яркость дисплея часов будем только тогда,
когда яркость дисплея требуется увеличить или уменьшить более, чем на 2 уровня

ligth_Intensity2=ligth_Intensity;
matrix.setIntensity(ligth_Intensity);// установка яркости дисплея
}
//////////////зеленый/////////////////
*/

 

// аналогичный алгоритм для красного дисплея, разница только в формуле расчета яркости, которые были определены опытным путем
//////////////для красного дисплея/////////////////
if (analogRead(lightPin) >= 400 & analogRead(lightPin) <= 1000) ligth_Intensity = (int(analogRead(lightPin) / 100) — 3);


if (analogRead(lightPin) < 400) ligth_Intensity = 0;
if (analogRead(lightPin) > 1000) ligth_Intensity = 14;


if (abs(ligth_Intensity2 — ligth_Intensity) > 2) {

ligth_Intensity2 = ligth_Intensity;
matrix.setIntensity(ligth_Intensity);


}
//////////////красный/////////////////

}

Для того, чтобы функция заработала, нужно вызывать ее каждый раз из основного цикла программы перед отображением показаний времени часов.

Яндекс.Метрика