From 3864026633a502effcc31ccc02697624a4b7c6f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?King=20K=C3=A9vin?= Date: Mon, 4 Apr 2016 21:52:11 +0200 Subject: [PATCH] fix brightness setting --- main.c | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/main.c b/main.c index ca85578..08a1051 100644 --- a/main.c +++ b/main.c @@ -101,12 +101,13 @@ volatile uint16_t photoresistor_value = 0; /** 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; +float clock_brightness = 1; /** minimum LED brightness */ #define BRIGHTNESS_MIN 0.2 /** maximum LED brightness */ #define BRIGHTNESS_MAX 1.0 - +/** the factor to change the brightness */ +#define BRIGHTNESS_FACTOR 0.1 int _write(int file, char *ptr, int len) { @@ -236,11 +237,6 @@ static void clock_show_time(uint32_t time) clock_leds[led_second*3+0] = 0xff-brightness_second; //clock_leds[led_second*3+1] = 0; // clear other colors (minutes/hours indication) //clock_leds[led_second*3+2] = 0; // clear other colors (minutes/hours indication) - - // adjust brightness - for (uint16_t i=0; iPHOTORESISTOR_MIN) { // low ambient luminosity - clock_brithtness = BRIGHTNESS_MIN; // set low brightness + new_clock_brightness = BRIGHTNESS_MIN; // set low brightness } else { // intermediate ambient luminosity - clock_brithtness = BRIGHTNESS_MIN+(BRIGHTNESS_MAX-BRIGHTNESS_MIN)*(1-(photoresistor_voltage-PHOTORESISTOR_MAX)/(PHOTORESISTOR_MIN-PHOTORESISTOR_MAX)); // set variable brightness + new_clock_brightness = 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); + clock_brightness = clock_brightness*(1-BRIGHTNESS_FACTOR)+new_clock_brightness*BRIGHTNESS_FACTOR; // calculate new brightness based on factor + //printf("photo-resistor voltage: %f, clock brightness: %f\n", photoresistor_voltage, clock_brightness); } if (action) { // go to sleep if nothing had to be done, else recheck for activity action = false;