improve LED bightness calculation
This commit is contained in:
parent
3439c2d7ed
commit
2b603c3363
22
main.c
22
main.c
@ -96,8 +96,17 @@ uint8_t command_i = 0;
|
||||
uint8_t gamma_correction_lut[256] = {0};
|
||||
/** photo-resistor measurement of ambient luminosity */
|
||||
volatile uint16_t photoresistor_value = 0;
|
||||
/** photo-resistor voltage for the minimum brightness */
|
||||
#define PHOTORESISTOR_MIN 2.7
|
||||
/** photo-resistor voltage for the maximum brightness */
|
||||
#define PHOTORESISTOR_MAX 1.7
|
||||
/** factor to dim LED of the clock, depending on the ambient luminosity */
|
||||
float clock_brithtness = 0;
|
||||
/** minimum LED brightness */
|
||||
#define BRIGHTNESS_MIN 0.2
|
||||
/** maximum LED brightness */
|
||||
#define BRIGHTNESS_MAX 1.0
|
||||
|
||||
|
||||
int _write(int file, char *ptr, int len)
|
||||
{
|
||||
@ -493,20 +502,19 @@ int main(void)
|
||||
rtc_set_counter_val(rtc_get_counter_val()%ticks_midday); // reset time counter
|
||||
}
|
||||
clock_set_time(rtc_get_counter_val()); // set time
|
||||
//adc_start_conversion_regular(ADC1); // start measuring ambient luminosity
|
||||
}
|
||||
while (photoresistor_flag) { // new photo-resistor value has been measured
|
||||
photoresistor_flag = false; // reset flag
|
||||
action = true; // action has been performed
|
||||
float photoresistor_voltage = photoresistor_value*1.2/ref_value; // calculate voltage from value
|
||||
if (photoresistor_voltage<1.7) { // high ambient luminosity
|
||||
clock_brithtness = 1; // set highest brightness
|
||||
} else if (photoresistor_voltage>2.1) { // low ambient luminosity
|
||||
clock_brithtness = 0.3; // set low brightness
|
||||
if (photoresistor_voltage<PHOTORESISTOR_MAX) { // high ambient luminosity
|
||||
clock_brithtness = BRIGHTNESS_MAX; // set highest brightness
|
||||
} else if (photoresistor_voltage>PHOTORESISTOR_MIN) { // low ambient luminosity
|
||||
clock_brithtness = BRIGHTNESS_MIN; // set low brightness
|
||||
} else { // intermediate ambient luminosity
|
||||
clock_brithtness = 0.3+(0.7*(1-(photoresistor_voltage-1.7)/0.4)); // set variable brightness
|
||||
clock_brithtness = BRIGHTNESS_MIN+(BRIGHTNESS_MAX-BRIGHTNESS_MIN)*(1-(photoresistor_voltage-PHOTORESISTOR_MAX)/(PHOTORESISTOR_MIN-PHOTORESISTOR_MAX)); // set variable brightness
|
||||
}
|
||||
//printf("%f, %f\n", photoresistor_voltage, clock_brithtness);
|
||||
printf("%f, %f\n", photoresistor_voltage, clock_brithtness);
|
||||
}
|
||||
if (action) { // go to sleep if nothing had to be done, else recheck for activity
|
||||
action = false;
|
||||
|
Loading…
Reference in New Issue
Block a user