light dimming
parent
7dec30548e
commit
ca782b261e
73
src/main.cpp
73
src/main.cpp
|
@ -16,6 +16,9 @@ boolean wifiConnected = false;
|
||||||
|
|
||||||
Espalexa espalexa;
|
Espalexa espalexa;
|
||||||
|
|
||||||
|
const int freq = 5000;
|
||||||
|
const int resolution = 8;
|
||||||
|
|
||||||
int redPin1 = 18;
|
int redPin1 = 18;
|
||||||
int greenPin1 = 17;
|
int greenPin1 = 17;
|
||||||
int bluePin1 = 16;
|
int bluePin1 = 16;
|
||||||
|
@ -28,8 +31,6 @@ int redPin3 = 25;
|
||||||
int greenPin3 = 26;
|
int greenPin3 = 26;
|
||||||
int bluePin3 = 32;
|
int bluePin3 = 32;
|
||||||
|
|
||||||
const int freq = 5000;
|
|
||||||
|
|
||||||
const int redChannel1 = 0;
|
const int redChannel1 = 0;
|
||||||
const int greenChannel1 = 1;
|
const int greenChannel1 = 1;
|
||||||
const int blueChannel1 = 2;
|
const int blueChannel1 = 2;
|
||||||
|
@ -42,8 +43,6 @@ const int redChannel3 = 6;
|
||||||
const int greenChannel3 = 7;
|
const int greenChannel3 = 7;
|
||||||
const int blueChannel3 = 8;
|
const int blueChannel3 = 8;
|
||||||
|
|
||||||
const int resolution = 8;
|
|
||||||
|
|
||||||
// connect to wifi – returns true if successful or false if not
|
// connect to wifi – returns true if successful or false if not
|
||||||
boolean connectWifi(){
|
boolean connectWifi(){
|
||||||
boolean state = true;
|
boolean state = true;
|
||||||
|
@ -78,6 +77,10 @@ boolean connectWifi(){
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int lightDimming(int lightValue, int lightBrigtness) {
|
||||||
|
return (lightValue * lightBrigtness) / 255;
|
||||||
|
}
|
||||||
|
|
||||||
//our callback functions
|
//our callback functions
|
||||||
void workingLightChanged(EspalexaDevice* d) {
|
void workingLightChanged(EspalexaDevice* d) {
|
||||||
if (d == nullptr) return;
|
if (d == nullptr) return;
|
||||||
|
@ -87,19 +90,10 @@ void workingLightChanged(EspalexaDevice* d) {
|
||||||
ledcWrite(greenChannel3, 0);
|
ledcWrite(greenChannel3, 0);
|
||||||
ledcWrite(blueChannel3, 0);
|
ledcWrite(blueChannel3, 0);
|
||||||
} else {
|
} else {
|
||||||
ledcWrite(redChannel3, d->getR());
|
ledcWrite(redChannel3, lightDimming(d->getR(), d->getValue()));
|
||||||
ledcWrite(greenChannel3, d->getG());
|
ledcWrite(greenChannel3, lightDimming(d->getG(), d->getValue()));
|
||||||
ledcWrite(blueChannel3, d->getB());
|
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) {
|
void monitorLightChanged(EspalexaDevice* d) {
|
||||||
|
@ -110,19 +104,10 @@ void monitorLightChanged(EspalexaDevice* d) {
|
||||||
ledcWrite(greenChannel2, 0);
|
ledcWrite(greenChannel2, 0);
|
||||||
ledcWrite(blueChannel2, 0);
|
ledcWrite(blueChannel2, 0);
|
||||||
} else {
|
} else {
|
||||||
ledcWrite(redChannel2, d->getR());
|
ledcWrite(redChannel2, lightDimming(d->getR(), d->getValue()));
|
||||||
ledcWrite(greenChannel2, d->getG());
|
ledcWrite(greenChannel2, lightDimming(d->getG(), d->getValue()));
|
||||||
ledcWrite(blueChannel2, d->getB());
|
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) {
|
void cabinetLightChanged(EspalexaDevice* d) {
|
||||||
|
@ -133,19 +118,10 @@ void cabinetLightChanged(EspalexaDevice* d) {
|
||||||
ledcWrite(greenChannel1, 0);
|
ledcWrite(greenChannel1, 0);
|
||||||
ledcWrite(blueChannel1, 0);
|
ledcWrite(blueChannel1, 0);
|
||||||
} else {
|
} else {
|
||||||
ledcWrite(redChannel1, d->getR());
|
ledcWrite(redChannel1, lightDimming(d->getR(), d->getValue()));
|
||||||
ledcWrite(greenChannel1, d->getG());
|
ledcWrite(greenChannel1, lightDimming(d->getG(), d->getValue()));
|
||||||
ledcWrite(blueChannel1, d->getB());
|
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() {
|
void ledStripsSetup() {
|
||||||
|
@ -197,23 +173,22 @@ void setup() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// auf dem schrank - cabinet light
|
// auf dem schrank - cabinet light
|
||||||
|
/*
|
||||||
ledcWrite(redChannel1, 255);
|
ledcWrite(redChannel1, 255);
|
||||||
ledcWrite(greenChannel1, 0);
|
ledcWrite(greenChannel1, 0);
|
||||||
ledcWrite(blueChannel1, 255);
|
ledcWrite(blueChannel1, 255);
|
||||||
|
*/
|
||||||
// hinter monitoren - monitor light
|
// hinter monitoren - monitor light
|
||||||
|
|
||||||
ledcWrite(redChannel2, 255);
|
ledcWrite(redChannel2, 0);
|
||||||
ledcWrite(greenChannel2, 255);
|
ledcWrite(greenChannel2, 150);
|
||||||
ledcWrite(blueChannel2, 0);
|
ledcWrite(blueChannel2, 0);
|
||||||
|
|
||||||
// unterm schrank - working light
|
// unterm schrank - working light
|
||||||
|
/*
|
||||||
ledcWrite(redChannel3, 150);
|
ledcWrite(redChannel3, 0);
|
||||||
ledcWrite(greenChannel3, 150);
|
ledcWrite(greenChannel3, 150);
|
||||||
ledcWrite(blueChannel3, 150);
|
ledcWrite(blueChannel3, 0); */
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
|
Loading…
Reference in New Issue