swinbkh / Ambilight2WLED

ESP8266 based conversion from Philips Ambilight to WLED
GNU General Public License v3.0
17 stars 2 forks source link

separate led strips for each side #5

Open celik75 opened 1 year ago

celik75 commented 1 year ago

i have 2 led strips(gradient), i want to use it for left and right of my tv as a floor lamp vertical.

If i want to use for example the left side of my tv, do i need to delete this snippet of the code or change any other code?

` JsonObject layer1_top = layer1["top"];

    JsonObject layer1_top_3 = layer1_top["3"];
    top_rgb[0] = layer1_top_3["r"]; //RED value of the top-center LED
    top_rgb[1] = layer1_top_3["g"]; //GREEN value of the top-center LED
    top_rgb[2] = layer1_top_3["b"]; //BLUE value of the top-center LED

    JsonObject layer1_right = layer1["right"];

    JsonObject layer1_right_1 = layer1_right["1"];
    right_rgb[0] = layer1_right_1["r"]; //RED value of the right-center LED
    right_rgb[1] = layer1_right_1["g"]; //GREEN value of the right-center LED
    right_rgb[2] = layer1_right_1["b"]; //BLUE value of the right-center LED`
celik75 commented 1 year ago

i managd to fix it, for someone else who want to use it.

`#include

include

ifdef ARDUINO_ARCH_ESP32

include

include

include

else //ESP8266 boards

include

include

endif

define USE_SERIAL Serial

if ARDUINO_ARCH_ESP32

WiFiMulti wifiMulti;

else

ESP8266WiFiMulti wifiMulti;

endif

const char ssid = "xx"; const char password = "xx"; const char AmbilightSource = "http://192.168.2.xx:1925/6/ambilight/processed"; const char WLEDSourceLeft = "http://192.168.2.xx/json";

int l_0_rgb[3] = {0}; int l_1_rgb[3] = {0}; int l_2_rgb[3] = {0};

void setup() {

USE_SERIAL.begin(115200);

for (uint8_t t = 4; t > 0; t--) { USE_SERIAL.printf("[SETUP] WAIT %d...\n", t); USE_SERIAL.flush(); delay(1000); }

wifiMulti.addAP(ssid, password);

}

void loop() { // wait for WiFi connection if ((wifiMulti.run() == WL_CONNECTED)) { HTTPClient httpAmbilight; httpAmbilight.begin(AmbilightSource); //HTTP int httpCode = httpAmbilight.GET();

if (httpCode > 0) {
  if (httpCode == HTTP_CODE_OK) {
    String payload = httpAmbilight.getString();
    DynamicJsonDocument doc(1024);
    deserializeJson(doc, payload);

    JsonObject layer1 = doc["layer1"];
    JsonObject layer1_l = layer1["left"];
    JsonObject layer1_l_0 = layer1_l["0"];
    JsonObject layer1_l_1 = layer1_l["1"];
    JsonObject layer1_l_2 = layer1_l["2"];

      l_0_rgb[0] = layer1_l_0["r"], l_0_rgb[1] = layer1_l_0["g"], l_0_rgb[2] = layer1_l_0["b"];
      l_1_rgb[0] = layer1_l_1["r"], l_1_rgb[1] = layer1_l_1["g"], l_1_rgb[2] = layer1_l_1["b"];
      l_2_rgb[0] = layer1_l_2["r"], l_2_rgb[1] = layer1_l_2["g"], l_2_rgb[2] = layer1_l_2["b"];

    HTTPClient httpWLED;
    httpWLED.begin(WLEDSourceLeft);
    httpWLED.addHeader("Content-Type", "application/json");
    int httpResponseCode = httpWLED.POST("{ \"on\": true, \"bri\": 25, \"transition\": 10, \"mainseg\": 0, \"seg\": [{ \"id\": 0, \"start\": 0, \"stop\": 26, \"grp\": 1, \"spc\": 0, \"on\": true, \"bri\": 255, \"col\": [ [" + String(l_0_rgb[0]) + ", " + String(l_0_rgb[1]) + ", " + String(l_0_rgb[2]) + "], [0, 0, 0], [0, 0, 0] ], \"fx\": 0, \"sx\": 64, \"ix\": 50, \"pal\": 0, \"sel\": false, \"rev\": false, \"mi\": false }, { \"id\": 1, \"start\": 26, \"stop\": 52, \"grp\": 1, \"spc\": 0, \"on\": true, \"bri\": 255, \"col\": [ [" + String(l_1_rgb[0]) + ", " + String(l_1_rgb[1]) + ", " + String(l_1_rgb[2]) + "], [0, 0, 0], [0, 0, 0] ], \"fx\": 0, \"sx\": 64, \"ix\": 50, \"pal\": 0, \"sel\": false, \"rev\": false, \"mi\": false }, { \"id\": 2, \"start\": 52, \"stop\": 78, \"grp\": 1, \"spc\": 0, \"on\": true, \"bri\": 255, \"col\": [ [" + String(l_2_rgb[0]) + ", " + String(l_2_rgb[1]) + ", " + String(l_2_rgb[2]) + "], [0, 0, 0], [0, 0, 0] ], \"fx\": 0, \"sx\": 64, \"ix\": 50, \"pal\": 0, \"sel\": false, \"rev\": false, \"mi\": false } ] }");
    httpWLED.end();
  }
}
else {
  USE_SERIAL.printf("[HTTP] GET... failed, error: %s\n", httpAmbilight.errorToString(httpCode).c_str());
}
httpAmbilight.end();

} delay(200); }`