diff --git a/firmware/config.h b/firmware/config.h index f190aec..ba39213 100644 --- a/firmware/config.h +++ b/firmware/config.h @@ -14,7 +14,8 @@ #define EEPROM_LAST_STATE_ADDRESS 4 // the first "last state" information for the first light #define EEPROM_TIMING_DATA_ADDRESS (EEPROM_LAST_STATE_ADDRESS + LIGHTS_COUNT) // Stored data date per light ELE_USED; HH; MM; CH1; CH2; CH3; CH4; -#define TIME_CHECK_INTERVAL_MS (60000UL) // 60 second interval +#define TIME_CHECK_INTERVAL_MS (60000UL) // 60 second interval +#define TIME_LIGHTENGINE_INTERVAL_MS (100UL) #define MY_NTP_SERVER "de.pool.ntp.org" diff --git a/firmware/firmware.ino b/firmware/firmware.ino index 2d8c58b..92e5624 100644 --- a/firmware/firmware.ino +++ b/firmware/firmware.ino @@ -36,10 +36,10 @@ IPAddress dns ( 192, 168, 0, 1); #define SCENE_NIGHTLY 2 // 10 bit PWM -#define PWM_OFF 0 // 0V -#define PWM_MIN 640 // 15V - minimum light amount (~1%) -#define PWM_MAX 1023 // 24V - maximum light amount (100%) -#define BRI_TO_PWM_FACTOR 4 // 24V-15V = 9V range; 9V ≙ 1024-640 = 383 counts; 383/100% = 3,83 counts (1%) / % => round up 4 counts / % (~1%) +#define PWM_OFF 0 // 0V +#define PWM_MIN 640 // 15V - minimum light amount (~1%) +#define PWM_MAX 1023 // 24V - maximum light amount (100%) +#define BRI_TO_PWM_FACTOR 1.506 // 24V-15V = 9V range; 9V ≙ 1024-640 = 384 counts; 384/255 counts =~ 1,506 counts //********************************// @@ -59,6 +59,8 @@ byte mac[6]; ESP8266WebServer server(80); ESP8266HTTPUpdateServer httpUpdateServer; +uint32_t last_lightengine_activity = 0; + //********************************// void apply_scene(uint8_t new_scene, uint8_t light) @@ -95,6 +97,15 @@ void process_lightdata(uint8_t light, float transitiontime) void lightEngine() { + + if (millis() < (last_lightengine_activity + TIME_LIGHTENGINE_INTERVAL_MS)) + { + // abort processing, the transition setting is a delay of seconds + return; + } + + last_lightengine_activity = millis(); + for (int i = 0; i < LIGHTS_COUNT; i++) { if (light_state[i]) @@ -102,27 +113,31 @@ void lightEngine() if (bri[i] != current_bri[i]) { in_transition = true; - current_bri[i] += step_level[i]; + current_bri[i] += step_level[i] / 10.0; if ((step_level[i] > 0.0 && current_bri[i] > bri[i]) || (step_level[i] < 0.0 && current_bri[i] < bri[i])) { current_bri[i] = bri[i]; } - analogWrite(pins[i], calcPWM(current_bri[i])); + uint16_t tmp_pwm = calcPWM(current_bri[i]); + Serial.println("pin" + (String)i + " = PWM(" + (String)tmp_pwm + ")"); + analogWrite(pins[i], tmp_pwm); } } else { if (current_bri[i] != 0) { in_transition = true; - current_bri[i] -= step_level[i]; + current_bri[i] -= step_level[i] / 10.0; if (current_bri[i] < 0) { current_bri[i] = 0; } - analogWrite(pins[i], calcPWM(current_bri[i])); + uint16_t tmp_pwm = calcPWM(current_bri[i]); + Serial.println("pin" + (String)i + " = PWM(" + (String)tmp_pwm + ")"); + analogWrite(pins[i], tmp_pwm); } } } @@ -147,6 +162,7 @@ uint16_t calcPWM(float tbri) { tmp_pwm = PWM_MAX; } + Serial.println((String)tbri + " => " + (String)tmp_pwm); return tmp_pwm; } @@ -485,7 +501,7 @@ void init_webserver() if (server.hasArg("bri" + (String)light)) { - bri[light] = server.arg("bri" + (String)light).toInt(); + bri[light] = (int)server.arg("bri" + (String)light).toInt(); Serial.print("Brightness set to "); Serial.println(bri[light]); } @@ -587,14 +603,14 @@ void init_webserver() http_content += "