light dimming

master
Alex 2022-01-08 22:25:12 +01:00
parent 7dec30548e
commit ca782b261e
1 changed files with 24 additions and 49 deletions

View File

@ -16,6 +16,9 @@ boolean wifiConnected = false;
Espalexa espalexa;
const int freq = 5000;
const int resolution = 8;
int redPin1 = 18;
int greenPin1 = 17;
int bluePin1 = 16;
@ -28,8 +31,6 @@ int redPin3 = 25;
int greenPin3 = 26;
int bluePin3 = 32;
const int freq = 5000;
const int redChannel1 = 0;
const int greenChannel1 = 1;
const int blueChannel1 = 2;
@ -42,8 +43,6 @@ const int redChannel3 = 6;
const int greenChannel3 = 7;
const int blueChannel3 = 8;
const int resolution = 8;
// connect to wifi returns true if successful or false if not
boolean connectWifi(){
boolean state = true;
@ -78,6 +77,10 @@ boolean connectWifi(){
return state;
}
int lightDimming(int lightValue, int lightBrigtness) {
return (lightValue * lightBrigtness) / 255;
}
//our callback functions
void workingLightChanged(EspalexaDevice* d) {
if (d == nullptr) return;
@ -87,19 +90,10 @@ void workingLightChanged(EspalexaDevice* d) {
ledcWrite(greenChannel3, 0);
ledcWrite(blueChannel3, 0);
} else {
ledcWrite(redChannel3, d->getR());
ledcWrite(greenChannel3, d->getG());
ledcWrite(blueChannel3, d->getB());
ledcWrite(redChannel3, lightDimming(d->getR(), d->getValue()));
ledcWrite(greenChannel3, lightDimming(d->getG(), d->getValue()));
ledcWrite(blueChannel3, lightDimming(d->getB(), d->getValue()));
}
Serial.print("D changed to ");
Serial.print(d->getValue());
Serial.print(", color R");
Serial.print(d->getR());
Serial.print(", G");
Serial.print(d->getG());
Serial.print(", B");
Serial.println(d->getB());
}
void monitorLightChanged(EspalexaDevice* d) {
@ -110,19 +104,10 @@ void monitorLightChanged(EspalexaDevice* d) {
ledcWrite(greenChannel2, 0);
ledcWrite(blueChannel2, 0);
} else {
ledcWrite(redChannel2, d->getR());
ledcWrite(greenChannel2, d->getG());
ledcWrite(blueChannel2, d->getB());
ledcWrite(redChannel2, lightDimming(d->getR(), d->getValue()));
ledcWrite(greenChannel2, lightDimming(d->getG(), d->getValue()));
ledcWrite(blueChannel2, lightDimming(d->getB(), d->getValue()));
}
Serial.print("D changed to ");
Serial.print(d->getValue());
Serial.print(", color R");
Serial.print(d->getR());
Serial.print(", G");
Serial.print(d->getG());
Serial.print(", B");
Serial.println(d->getB());
}
void cabinetLightChanged(EspalexaDevice* d) {
@ -133,19 +118,10 @@ void cabinetLightChanged(EspalexaDevice* d) {
ledcWrite(greenChannel1, 0);
ledcWrite(blueChannel1, 0);
} else {
ledcWrite(redChannel1, d->getR());
ledcWrite(greenChannel1, d->getG());
ledcWrite(blueChannel1, d->getB());
ledcWrite(redChannel1, lightDimming(d->getR(), d->getValue()));
ledcWrite(greenChannel1, lightDimming(d->getG(), d->getValue()));
ledcWrite(blueChannel1, lightDimming(d->getB(), d->getValue()));
}
Serial.print("D changed to ");
Serial.print(d->getValue());
Serial.print(", color R");
Serial.print(d->getR());
Serial.print(", G");
Serial.print(d->getG());
Serial.print(", B");
Serial.println(d->getB());
}
void ledStripsSetup() {
@ -197,23 +173,22 @@ void setup() {
}
// auf dem schrank - cabinet light
/*
ledcWrite(redChannel1, 255);
ledcWrite(greenChannel1, 0);
ledcWrite(blueChannel1, 255);
*/
// hinter monitoren - monitor light
ledcWrite(redChannel2, 255);
ledcWrite(greenChannel2, 255);
ledcWrite(blueChannel2, 0);
ledcWrite(redChannel2, 0);
ledcWrite(greenChannel2, 150);
ledcWrite(blueChannel2, 0);
// unterm schrank - working light
ledcWrite(redChannel3, 150);
/*
ledcWrite(redChannel3, 0);
ledcWrite(greenChannel3, 150);
ledcWrite(blueChannel3, 150);
ledcWrite(blueChannel3, 0); */
}
void loop() {