Added fade off lamp

This commit is contained in:
2022-09-07 16:23:10 +03:00
parent 0dfa29d7c6
commit 0aab4963c4
3 changed files with 52 additions and 15 deletions

View File

@@ -175,6 +175,7 @@ void setup() {
request->send(200, "text/plain", "Hi! I am ESP32.");
});
AsyncElegantOTA.setID("BigRoom");
AsyncElegantOTA.begin(&server); // Start ElegantOTA
WebSerial.begin(&server);
@@ -185,6 +186,8 @@ void loop() {
static uint32_t cRun = millis();
static uint8_t sec = 0;
static uint16_t prevLLevel = 0;
static uint32_t levBlue = 0, levWhite = 0;
static unsigned long levRunB = 0, levRunW = 0;
char s[7];
//ArduinoOTA.handle();
@@ -202,31 +205,42 @@ void loop() {
samples.add(LightLev);
LightLev = samples.getMedian();
if ((LightLev < spLight) && move && !bLamp){
ledcWrite(PWM_BLUE,(levelBlue) * 2.55);
levBlue = levelBlue * 2.55;
ledcWrite(PWM_BLUE, levBlue);
statLamp |= 0x01;
bLamp = true;
Serial.println(F("BLamp On"));
WebSerial.println(F("Blue Lamp On"));
}
else if((LightLev > (spLight + dbLight)) || (move == 0)){
ledcWrite(PWM_BLUE, 0);
if((levRunB + 50 <= millis() && levBlue > 0)){
levRunB = millis();
levBlue--;
}
ledcWrite(PWM_BLUE, levBlue);
statLamp &= 0xFE;
bLamp = false;
}
if(lightWhite && !wLamp){
ledcWrite(PWM_WHITE, (levelWhite) * 2.55);
levWhite = levelWhite * 2.55;
ledcWrite(PWM_WHITE, levWhite);
statLamp |= 0x02;
wLamp = true;
Serial.println(F("WLamp On"));
WebSerial.println(F("White Lamp On"));
}
else if (!lightWhite){
ledcWrite(PWM_WHITE, 0);
if((levRunW + 30 <= millis() && levWhite > 0)){
//WebSerial.println(levWhite);
levRunW = millis();
levWhite--;
}
ledcWrite(PWM_WHITE, levWhite);
statLamp &= 0xFD;
wLamp = false;
}
if(statLamp > 0) digitalWrite(POWER, HIGH);
else digitalWrite(POWER, LOW);
else if((levBlue > 0) && (levWhite > 0)) digitalWrite(POWER, LOW);
if((cRun + 1000) <= millis()){ //Once per second
cRun = millis();
if(abs(LightLev - prevLLevel) > 100){