//https://www.boxentriq.com/code-breaking/pixel-values-extractor

#include "FastLED.h"
//#include <ArduinoJson.h>
//#include "Hex.h"

#define cols  50
#define rows  20

#define PIN 6
#define NUM_LED cols*rows
#define LED_Type WS2812
#define RGB_Type GRB
#define Brightness 255

CRGB leds1[NUM_LED];
//▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄


void setup()
{
  Serial.begin(9600);
  FastLED.addLeds<LED_Type, PIN, RGB_Type>(leds1, NUM_LED).setCorrection( TypicalLEDStrip );
  FastLED.setBrightness(Brightness);
  //Serial.println(cols * rows * 3);

}

void loop()
{


  Run_Hex();

  delay(1000);

}

//const char input[] PROGMEM = R"=====(#FFFF00)=====";

//const char* input[] = {"#FF0000","00FF00"};

void Run_Hex() {
  /*
    StaticJsonDocument<24576> doc;

    DeserializationError error = deserializeJson(doc, input);

    if (error) {
      Serial.print(F("deserializeJson() failed: "));
      Serial.println(error.f_str());
      return;
    }

    for (int i = 0; i < NUM_LED; i++) {

    const char* DataHex = doc[i];
  */
  HEX_RGB("FF0000");
  FastLED.show();
  //Serial.println(DataHex);


}




int HEX_RGB(String Hexdata) {

  // Remove the '#' symbol if it's included
  if (Hexdata.startsWith("#")) {
    Hexdata = Hexdata.substring(1);
  }

  // Parse the hexadecimal string to integer values
  long intColor = strtol(Hexdata.c_str(), NULL, 16);

  int R = (intColor >> 16) & 0xFF; // Extract the red component
  int G = (intColor >> 8) & 0xFF;  // Extract the green component
  int B = intColor & 0xFF;        // Extract the blue component

  // Now, R, G, and B contain the integer values for the color components

  leds1[0] = CRGB(R, G, B);


}


int HEX_RGB(uint8_t* payload) {

  //uint8_t* payload = "#FF3399";

  if (payload[0] == '#') {
    // we get RGB data
    // decode rgb data
    uint32_t rgb = (uint32_t) strtol((const char *) &payload[1], NULL, 16);
    int R = (rgb >> 16) & 0xFF;
    int G = (rgb >> 8) & 0xFF;
    int B = (rgb >> 0) & 0xFF;

    leds1[0] = CRGB(R, G, B);

  }


}