Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. Colorpicker-Wert als Hex z.B. #FF00FF

    NEWS

    • Neuer Blog: Fotos und Eindrücke aus Solingen

    • ioBroker@Smart Living Forum Solingen, 14.06. - Agenda added

    • ioBroker goes Matter ... Matter Adapter in Stable

    Colorpicker-Wert als Hex z.B. #FF00FF

    This topic has been deleted. Only users with topic management privileges can see it.
    • N
      nelzon last edited by

      @AndyUM61:

      Hey,

      danke,danke, danke!!!!

      Das ist genau das, was ich heute den ganzen Tag versucht habe hin zu bekommen.

      Tja, Profi ist Profi:).

      Ja, das sollte im ioBroker ein Script sein.

      Ich bin gerade dabei mit einem ESP8266 und MQTT ein wenig zu experimentieren.

      Der Chip ist unschlagbar günstig, und mit Hilfe von MQTT kann man über den ioBroker hervorragend entweder Sensoren realisieren, oder das Ganze halt auch für Lichtsteuerungen verwenden.

      MQTT-PIR-Sensoren und Temperatursensoren habe ich Hard- und Softwaremäßig - auf dem Steckbrett - fertig und auch schon eine Weile in Erprobung.

      Dank deiner Hilfe sind jetzt auch alle Funktionen zur Steuerung von WS8212-Stripes realisiert.

      Die ESP8266-Software um die Möglichkeiten dieser Stripes zu steuern und eine entsprechende MQTT-Verbindung hatte ich schon so weit fertig.

      Ich möchte diese Stripes neben der Beleuchtung unter anderem auch zur Visualisierung von Ereignissen nutzen, da ja damit vom Blinken über Faden bis zu Colorwipe oder Ähnlichem alles möglich ist. So z.B. für die Hausklingel, Waschmaschine, Telefon….mal sehen, was mir noch so einfällt;).

      Gestolpert bin ich halt über den Colorpicker im vis.

      Wäre es nicht möglich, eine solche Berechnung gleich fest in die beiden Colorpicker einzubauen?

      Das wäre doch eine klasse Zusatzoption, mit der man dann sicher auch relativ unkompliziert an anderen Stellen einen Color-Wert setzen könnte.

      Da stolpern sicher auch noch andere drüber.

      Nochmal Dankeschön!!! `

      Du hast genau das Projekt realisiert, was ich mir auch vorstelle!!

      Kannst du deinen verwendeten Sketch hier mal reinstellen? Kennst du schon Easyesp??

      1 Reply Last reply Reply Quote 0
      • A
        AndyUM61 last edited by

        Hallo "nelzon".

        Hier mal das Script das ich auf dem ESP8266 als Melder verwende.

        Dieses habe ich aus verschiedenen Beispielen zusammengestellt und angepasst.

        Welche Librarys du benötigst kannst du dem Script entnehmen.

        Ansonsten ist das Script gut dokumentiert und anzupassende Stellen habe ich markiert.

        Beim ersten Start erzeugt dieses Script die erforderlichen Topics im ioBroker selbst, vorausgesetzt du hast auch im ioBroker den MQTT-Adapter als Server installiert und die IP-Adressen und Zugangsdaten im Script entsprechend angepasst.

        `#include <esp8266wifi.h>
        #include <pubsubclient.h>
        #include <adafruit_neopixel.h>
        
        //#define DEBUG // Debug-Modus einschalten fuer spezielle Ausgaben ueber Serial
        
        //// Netzwerk-Settings
        const char* ssid = "WLAN-SSID";  // <---------------!!Anpassen!!
        const char* password = "WLAN-PASSW"; // <---------------!!Anpassen!!
        const char* USE_DHCP = "off"; // "on" fuer DHCP
        IPAddress Myip(192, 178, 0, 37); //static IP address <---------------!!Anpassen!!
        IPAddress gateway(192, 178, 0, 52); //gateway <---------------!!Anpassen!!
        IPAddress subnet(255, 255, 255, 0);//subnet
        //// MQTT-Settings
        IPAddress mqtt_server(192,178,0,99); // <---------------!!Anpassen!!
        const char* mqtt_username = "MQTT-USER"; // <---------------!!Anpassen!!
        const char* mqtt_key = "MQTT-PASSW"; // <---------------!!Anpassen!!
        
        #define BASE "RGB02"  // <---------------!!ClientID Anpassen!!
        #define mqtt_client_id BASE
        #define mqtt_topics_ip BASE "/IP"
        #define mqtt_topics_color BASE "/COLOR"
        #define mqtt_topics_bright BASE "/BRIGH"
        #define mqtt_topics_mode BASE "/MODE"
        #define mqtt_topics_reset BASE "/RESET"
        #define mqtt_topics BASE "/#"
        
        WiFiClient espClient;
        PubSubClient client(espClient);
        long lastMsg = 0;
        char msg[50];
        int value = 0;
        const char* res = "0";
        
        #define RESETPIN 12 // Pin für SoftResetFunktion (verbunden mit RST)
        #define LEDPIN 2
        //// Adafruit Settings //////////////////////////////////
        
        #define PIN            2 // Pin entsprechend der GPIO z.B GPIO13 -> 13
        #define NUMPIXELS      13 //Anzahl der Pixel im Stripe
        #define interval       70 //defines the delay interval between running the functions
        
        Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
        
        uint32_t red = pixels.Color(255, 0, 0);
        uint32_t blue = pixels.Color(0, 0, 255);
        uint32_t green = pixels.Color(0, 255, 0);
        uint32_t pixelColour;
        
        float activeColor[] = {255, 0, 0};//sets the default color to red
        
        boolean LEDstate[] = {false, false, false, false, true, false, false, false, false, false, false, false, false, false}; //saves the state of each of the functions
        String rawColor;  //raw color to differentiate if the color has changed
        String rawBright; // raw brightness to differentiate if the brightness level has changed
        
        String color = "#123456"; //default color for color wheel
        int status = WL_IDLE_STATUS;
        int neopixMode = 0; //sets a mode to run each of the functions
        long previousMillis = 0; // a long value to store the millis()
        int i = 0; //sets the pixel number in newTheatreChase() and newColorWipe()
        int CWColor = 0; //sets the newColorWipe() color value 0=Red, 1=Green, 2=Blue
        int j; //sets the pixel to skip in newTheatreChase() and newTheatreChaseRainbow()
        int cycle = 0;//sets the cycle number in newTheatreChase()
        int TCColor = 0;//sets the color in newTheatreChase()
        int l = 0; //sets the color value to send to Wheel in newTheatreChaseRainbow() and newRainbow()
        int m = 0; //sets the color value in newRainbowCycle()
        int n = 2; //sets the pixel number in cyclonChaser()
        int breather = 0; //sets the brightness value in breather()
        boolean dir = true; //sets the direction in breather()-breathing in or out, and cylonChaser()-left or right
        boolean beat = true; //sets the beat cycle in heartbeat()
        int beats = 0; //sets the beat number in heartbeat()
        int brightness = 150; //sets the default brightness value
        String Bright_Str; // Hilfsvariable für MQTT
        String Color_Str; // Hilfsvariable für MQTT
        String Modus_Str; // Hilfsvariable für MQTT
        
        ////////////////////////////////////////////////////////
        void setup() {
          pinMode(RESETPIN, OUTPUT);
          digitalWrite(RESETPIN, HIGH); 
        
          //// Adafruit /////////////////////////////////
            pixels.begin(); //starts the neopixels
            pixels.setBrightness(brightness); // sets the inital brightness of the neopixels
            writeLEDS(0, 0, 0); //sets all the pixels to off 
          /////////////////////////////////////////////
        
          Serial.begin(115200);
          if(USE_DHCP == "off") {setup_wifi();}
          client.setServer(mqtt_server, 1883);
          client.setCallback(callback);
          client.setClient(espClient);
        }
        
        uint32_t x=0;
        
        void setup_wifi() {
          Serial.println("");
          delay(10);
          Serial.print("Connecting to ");
          Serial.println(ssid);
          if(USE_DHCP == "off") {WiFi.config(Myip, gateway, subnet); }  
          WiFi.begin(ssid, password);
          while (WiFi.status() != WL_CONNECTED) {
            delay(500);
            Serial.print(".");
          }
        
          Serial.println("");
          Serial.println("WiFi connected");
          Serial.println("IP address: ");
          Serial.println(WiFi.localIP());
          }
        
        //// Callback Funktion von MQTT. Die Funktion wird aufgerufen wenn ein Wert empfangen wurde.
        void callback(char* topic, byte* payload, unsigned int length) {
         // Zähler 
         int i = 0;  
         // Hilfsvariablen für die Convertierung der Nachricht in ein String
         char message_buff[100]; 
         Serial.print("Empfangen: " + String(topic));
         // Kopieren der Nachricht und erstellen eines Bytes mit abschliessender \0
         for(i=0; i <length; i++)/{/message_buff[i]="payload[i];" }/;/string/msgstring="String(message_buff);" konvertierung/der/nachricht/in/ein/serial.println("/-="">" + msgString);
          if (String(topic) == mqtt_topics_reset){
            Serial.println("Reset");
            digitalWrite(RESETPIN, LOW);      
          }
        
         if (String(topic) == mqtt_topics_mode){
          if(msgString =="1"){Serial.println("Mode 1");handle_L0();}
          if(msgString =="2"){handle_L1();}
          if(msgString =="3"){handle_L2();}
          if(msgString =="4"){handle_L3();}
          if(msgString =="5"){handle_L4();}
          if(msgString =="6"){handle_L5();}
          if(msgString =="7"){handle_L6();}
          if(msgString =="8"){handle_L7();}
          if(msgString =="9"){handle_L8();}
          if(msgString =="10"){handle_L9();}
          if(msgString =="11"){handle_L10();}
          if(msgString =="12"){handle_L11();}
          if(msgString =="13"){handle_L12();}   
          }
         if (String(topic) == mqtt_topics_bright){
          Bright_Str = msgString;
          handle_bright(); 
         }
         if (String(topic) == mqtt_topics_color){
          Color_Str = msgString;
          Serial.print("Color: "+Color_Str);
          handle_color(); 
         }
        }
        
        void reconnect() {
          // Loop until we're reconnected
          while (!client.connected()) {
            if (LEDPIN){ digitalWrite(LEDPIN,LOW);}
            Serial.print("Attempting MQTT connection...");
            // Attempt to connect
            if (client.connect(mqtt_client_id,mqtt_username,mqtt_key)) {
              if (LEDPIN){ digitalWrite(LEDPIN,HIGH);}
              Serial.println("connected");
              Serial.println("Client: " BASE);
              // IP-Adresse umwandeln und publish
              IPAddress localAddr = WiFi.localIP();
              char s[16];  
              sprintf(s, "%d.%d.%d.%d", localAddr[0], localAddr[1], localAddr[2], localAddr[3]);     
              client.publish(mqtt_topics_ip,s);      
              client.publish(mqtt_topics_bright,"100");
              client.publish(mqtt_topics_color, "#000000");
              client.publish(mqtt_topics_mode,"5");
              client.publish(mqtt_topics_reset,res);      
            } else {
              Serial.print("failed, rc=");
              Serial.print(client.state());
              Serial.println(" try again in 5 seconds");
              // Wait 5 seconds before retrying
              delay(5000);
            }
          }
        }
        void loop() {
        
          if (!client.connected()) {
            reconnect();
            client.subscribe(mqtt_topics);
          }
          client.loop();
        
          long now = millis();
          // Setzen des Status, damit die entsprechende Funktion korrekt ausgeführt wird
          if (LEDstate[5] == true){newColorWipe();}
          if (LEDstate[6] == true){newTheatreChase();}
          if (LEDstate[7] == true){newRainbow();}
          if (LEDstate[8] == true){newTheatreChaseRainbow();}
          if (LEDstate[9] == true){cylonChaser();}
          if (LEDstate[10] == true){newRainbowCycle();}
          if (LEDstate[11] == true){breathing();}
          if (LEDstate[12] == true){heartbeat();}
        }
        
        //// Adafruit Functionen /////////////////////////////////////
        void handle_L0() {
          writeLEDS(255, 0, 0);//set the pixels to red
          activeColor[0] = 255;//sets the active color to red
          activeColor[1] = 0;
          activeColor[2] = 0;
          change_states(0);//change LEDstate to 0
        
        }
        
        void handle_L1() {//same as hanle_L0 only with green
          writeLEDS(0, 255, 0);
          activeColor[0] = 0;
          activeColor[1] = 255;
          activeColor[2] = 0;
          change_states(1);
        }
        
        void handle_L2() {//same as hanle_L0 only with blue
          writeLEDS(0, 0, 255);
          activeColor[0] = 0;
          activeColor[1] = 0;
          activeColor[2] = 255;
          change_states(2);
        
        }
        void handle_L3() {//same as hanle_L0 only with white
          writeLEDS(255, 255, 255);
          activeColor[0] = 255;
          activeColor[1] = 255;
          activeColor[2] = 255;
          change_states(3);
        }
        
        void handle_L4() {//same as hanle_L0 only turns off all pixels
          writeLEDS(0, 0, 0);
          change_states(4);
        }
        
        void handle_L5() {
          change_states(5); 
          newColorWipe();//starts the function
        }
        
        void handle_L6() {//same as above etc.
          change_states(6);
          newTheatreChase();
        }
        
        void handle_L7() {
          change_states(7);
          newRainbow();
        }
        
        void handle_L8() {
          change_states(8);
          newTheatreChaseRainbow();
        }
        
        void handle_L9() {
          change_states(9);
          cylonChaser();
        }
        
        void handle_L10() {
          change_states(10);
          newRainbowCycle();
        }
        void handle_L11() {
          change_states(11);
          breathing();
        }
        void handle_L12() {
          change_states(12);
          heartbeat();
        }
        
        void handle_color()
        {
          String color = Color_Str;//sets the color1 string to the value in argument 0
        #if defined DEBUG
          Serial.print("Color Received:");
          //Serial.println(color);
        #endif
        
          String r = "0x" + color.substring(1, 3);//sets string r to a string of the byte value
          String g = "0x" + color.substring(3, 5);//same as above
          String b = "0x" + color.substring(5, 7);
        
        #if defined DEBUG
          String colors = r + g + b;//sets the whole string up for printing in debug mode
          Serial.print("colors - String: ");
          Serial.print(colors);
        #endif
        
          const char *r1 = r.c_str(); //converts the string to a const char to convert to RGB values below
          const char *g1 = g.c_str(); //same as above
          const char *b1 = b.c_str();
          int red = RGBValue(r1);//converts to RGB value
          int green = RGBValue(g1);
          int blue = RGBValue(b1);
        #if defined DEBUG
          Serial.print(" ");
          Serial.print(red);
          Serial.print(" ");
          Serial.print(green);
          Serial.print(" ");
          Serial.println(blue);
        #endif
        
          writeLEDS(red, green, blue);//sets up the pixels to the color chosen
          //writeLEDS(red, green, blue);//sets up the pixels to the color chosen
          activeColor[0] = red; //sets the color chosen as the activeColor to be used in other functions
          activeColor[1] = green;
          activeColor[2] = blue;
        #if defined DEBUG
          Serial.println(activeColor[0]);
          Serial.println(activeColor[1]);
          Serial.println(activeColor[2]);
        #endif
        
          for (int x = 0; x < 14; x++)
          {
            LEDstate[x] = LOW;//write all LEDstate values to LOW
          }
          LEDstate[13] = HIGH;//sets LEDstate to 13
        
        }
        
        void handle_bright()
        {
          brightness = Bright_Str.toInt();//changes the argument0 to an int
          pixels.setBrightness(brightness);//sets it as the global brightness
          pixels.show();//displays new brightness level
        }
        
        /////////////////////////////////
        void change_states(int tgt) {
            for (int x = 0; x < 14; x++)
            {
              LEDstate[x] = LOW;//writes all LEDstate values to LOW
            }
            LEDstate[tgt] = HIGH; //sets the tgt value to HIGH
            //LEDstate[tgt] = state ? HIGH : LOW; //sets the tgt value to HIGH
        }
        ///////////////////////////////
        
        unsigned int RGBValue(const char * s)//converts the value to an RGB value
        {
          unsigned int result = 0;
          int c ;
          if ('0' == *s && 'x' == *(s + 1)) {
            s += 2;
            while (*s) {
              result = result << 4;
              if (c = (*s - '0'), (c >= 0 && c <= 9)) result |= c;
              else if (c = (*s - 'A'), (c >= 0 && c <= 5)) result |= (c + 10);
              else if (c = (*s - 'a'), (c >= 0 && c <= 5)) result |= (c + 10);
              else break;
              ++s;
            }
          }
          return result;
        }
        void heartbeat()
        {
        #if defined DEBUG
          Serial.print("testinterval");
          Serial.println(millis() - previousMillis);
        #endif
          if (millis() - previousMillis > interval * 2)//if the time between the function being last run is greater than intervel * 2 - run it
          {
            if ((beat == true) && (beats == 0) && (millis() - previousMillis > interval * 7)) //if the beat is on and it's the first beat (beats==0) and the time between them is enough
            {
              for (int h = 50; h <= 255; h = h + 15)//turn on the pixels at 50 and bring it up to 255 in 15 level increments
              {
                writeLEDS((activeColor[0] / 255) * h, (activeColor[1] / 255) * h, (activeColor[2] / 255) * h);
                delay(3);
              }
              beat = false;//sets the next beat to off
              previousMillis = millis();//starts the timer again
        
            }
            else if ((beat == false) && (beats == 0))//if the beat is off and the beat cycle is still in the first beat
            {
              for (int h = 255; h >= 0; h = h - 15)//turn off the pixels
              {
                writeLEDS((activeColor[0] / 255) * h, (activeColor[1] / 255) * h, (activeColor[2] / 255) * h);
                delay(3);
              }
              beat = true;//sets the beat to On
              beats = 1;//sets the next beat to the second beat
              previousMillis = millis();
            }
            else if ((beat == true) && (beats == 1) && (millis() - previousMillis > interval * 2))//if the beat is on and it's the second beat and the interval is enough
            {
              for (int h = 50; h <= 255; h = h + 15)
              {
                writeLEDS((activeColor[0] / 255) * h, (activeColor[1] / 255) * h, (activeColor[2] / 255) * h); //turn on the pixels
                delay(3);
              }
              beat = false;//sets the next beat to off
              previousMillis = millis();
            }
            else if ((beat == false) && (beats == 1))//if the beat is off and it's the second beat
            {
              for (int h = 255; h >= 0; h = h - 15)
              {
                writeLEDS((activeColor[0] / 255) * h, (activeColor[1] / 255) * h, (activeColor[2] / 255) * h); //turn off the pixels
                delay(3);
              }
              beat = true;//sets the next beat to on
              beats = 0;//starts the sequence again
              previousMillis = millis();
            }
        #if defined DEBUG
            Serial.print("previousMillis:");
            Serial.println(previousMillis);
        #endif
          }
        }
        void breathing()
        {
          if (millis() - previousMillis > interval * 2) //if the timer has reached its delay value
          {
            writeLEDS((activeColor[0] / 255) * breather, (activeColor[1] / 255) * breather, (activeColor[2] / 255) * breather); //write the leds to the color and brightness level
            if (dir == true)//if the lights are coming on
            {
              if (breather < 255)//once the value is less than 255
              {
                breather = breather + 15;//adds 15 to the brightness level for the next time
              }
              else if (breather >= 255)//if the brightness is greater or equal to 255
              {
                dir = false;//sets the direction to false
              }
            }
            if (dir == false)//if the lights are going off
            {
              if (breather > 0)
              {
                breather = breather - 15;//takes 15 away from the brightness level
              }
              else if (breather <= 0)//if the brightness level is nothing
                dir = true;//changes the direction again to on
            }
            previousMillis = millis();
          }
        }
        
        void cylonChaser()
        {
          if (millis() - previousMillis > interval * 2 / 3)
          {
            for (int h = 0; h < pixels.numPixels(); h++)
            {
              pixels.setPixelColor(h, 0);//sets all pixels to off
            }
            if (pixels.numPixels() <= 10)//if the number of pixels in the strip is 10 or less only activate 3 leds in the strip
            {
              pixels.setPixelColor(n, pixels.Color(activeColor[0], activeColor[1], activeColor[2]));//sets the main pixel to full brightness
              pixels.setPixelColor(n + 1, pixels.Color((activeColor[0] / 255) * 50, (activeColor[1] / 255) * 50, (activeColor[2] / 255) * 50)); //sets the surrounding pixels brightness to 50
              pixels.setPixelColor(n - 1, pixels.Color((activeColor[0] / 255) * 50, (activeColor[1] / 255) * 50, (activeColor[2] / 255) * 50));
              if (dir == true)//if the pixels are going up in value
              {
                if (n <  (pixels.numPixels() - 1))//if the pixels are moving forward and havent reach the end of the strip "-1" to allow for the surrounding pixels
                {
                  n++;//increase N ie move one more forward the next time
                }
                else if (n >= (pixels.numPixels() - 1))//if the pixels have reached the end of the strip
                {
                  dir = false;//change the direction
                }
              }
              if (dir == false)//if the pixels are going down in value
              {
                if (n > 1)//if the pixel number is greater than 1 (to allow for the surrounding pixels)
                {
                  n--; //decrease the active pixel number
                }
                else if (n <= 1)//if the pixel number has reached 1
                {
                  dir = true;//change the direction
                }
              }
            }
            if ((pixels.numPixels() > 10) && (pixels.numPixels() <= 20))//if there are between 11 and 20 pixels in the strip add 2 pixels on either side of the main pixel
            {
              pixels.setPixelColor(n, pixels.Color(activeColor[0], activeColor[1], activeColor[2]));//same as above only with 2 pixels either side
              pixels.setPixelColor(n + 1, pixels.Color((activeColor[0] / 255) * 150, (activeColor[1] / 255) * 150, (activeColor[2] / 255) * 150));
              pixels.setPixelColor(n + 2, pixels.Color((activeColor[0] / 255) * 50, (activeColor[1] / 255) * 50, (activeColor[2] / 255) * 50));
              pixels.setPixelColor(n - 1, pixels.Color((activeColor[0] / 255) * 150, (activeColor[1] / 255) * 150, (activeColor[2] / 255) * 150));
              pixels.setPixelColor(n - 2, pixels.Color((activeColor[0] / 255) * 50, (activeColor[1] / 255) * 50, (activeColor[2] / 255) * 50));
              if (dir == true)
              {
                if (n <  (pixels.numPixels() - 2))
                {
                  n++;
                }
                else if (n >= (pixels.numPixels() - 2))
                {
                  dir = false;
                }
              }
              if (dir == false)
              {
                if (n > 2)
                {
                  n--;
                }
                else if (n <= 2)
                {
                  dir = true;
                }
              }
            }
            if (pixels.numPixels() > 20)//if there are more than 20 pixels in the strip add 3 pixels either side of the main pixel
            {
              pixels.setPixelColor(n, pixels.Color((activeColor[0] / 255) * 150, (activeColor[1] / 255) * 150, (activeColor[2] / 255) * 150));
              pixels.setPixelColor(n + 1, pixels.Color((activeColor[0] / 255) * 150, (activeColor[1] / 255) * 150, (activeColor[2] / 255) * 150));
              pixels.setPixelColor(n + 2, pixels.Color((activeColor[0] / 255) * 100, (activeColor[1] / 255) * 100, (activeColor[2] / 255) * 100));
              pixels.setPixelColor(n + 3, pixels.Color((activeColor[0] / 255) * 50, (activeColor[1] / 255) * 50, (activeColor[2] / 255) * 50));
              pixels.setPixelColor(n - 1, pixels.Color((activeColor[0] / 255) * 150, (activeColor[1] / 255) * 150, (activeColor[2] / 255) * 150));
              pixels.setPixelColor(n - 2, pixels.Color((activeColor[0] / 255) * 100, (activeColor[1] / 255) * 100, (activeColor[2] / 255) * 100));
              pixels.setPixelColor(n - 3, pixels.Color((activeColor[0] / 255) * 50, (activeColor[1] / 255) * 50, (activeColor[2] / 255) * 50));
              if (dir == true)
              {
                if (n <  (pixels.numPixels() - 3))
                {
                  n++;
                }
                else if (n >= (pixels.numPixels() - 3))
                {
                  dir = false;
                }
              }
              if (dir == false)
              {
                if (n > 3)
                {
                  n--;
                }
                else if (n <= 3)
                {
                  dir = true;
                }
              }
            }
            pixels.show();//show the pixels
            previousMillis = millis();
          }
        }
        
        void newTheatreChaseRainbow()
        {
          if (millis() - previousMillis > interval * 2)
          {
            for (int h = 0; h < pixels.numPixels(); h = h + 3) {
              pixels.setPixelColor(h + (j - 1), 0);    //turn every third pixel off from the last cycle
            }
            for (int h = 0; h < pixels.numPixels(); h = h + 3)
            {
              pixels.setPixelColor(h + j, Wheel( ( h + l) % 255));//turn every third pixel on and cycle the color
            }
            pixels.show();
            j++;
            if (j >= 3)
              j = 0;
            l++;
            if (l >= 256)
              l = 0;
            previousMillis = millis();
          }
        }
        
        void newRainbowCycle()
        {
          if (millis() - previousMillis > interval * 2)
          {
            for (int h = 0; h < pixels.numPixels(); h++)
            {
              pixels.setPixelColor(h, Wheel(((h * 256 / pixels.numPixels()) + m) & 255));
            }
            m++;
            if (m >= 256 * 5)
              m = 0;
            pixels.show();
            previousMillis = millis();
          }
        }
        
        void newRainbow()
        {
          if (millis() - previousMillis > interval * 2)
          {
            for (int h = 0; h < pixels.numPixels(); h++)
            {
              pixels.setPixelColor(h, Wheel((h + l) & 255));
            }
            l++;
            if (l >= 256)
              l = 0;
            pixels.show();
            previousMillis = millis();
          }
        }
        
        void newTheatreChase()
        {
          if (millis() - previousMillis > interval * 2)
          {
            uint32_t color;
            int k = j - 3;
            j = i;
            while (k >= 0)
            {
              pixels.setPixelColor(k, 0);
              k = k - 3;
            }
            if (TCColor == 0)
            {
              color = pixels.Color(255, 0, 0);
            }
            else if (TCColor == 1)
            {
              color = pixels.Color(0, 255, 0);
            }
            else if (TCColor == 2)
            {
              color = pixels.Color(0, 0, 255);
            }
            else if (TCColor == 3)
            {
              color = pixels.Color(255, 255, 255);
            }
            while (j < NUMPIXELS)
            {
              pixels.setPixelColor(j, color);
              j = j + 3;
            }
            pixels.show();
            if (cycle == 10)
            {
              TCColor ++;
              cycle = 0;
              if (TCColor == 4)
                TCColor = 0;
            }
            i++;
            if (i >= 3)
            {
              i = 0;
              cycle ++;
            }
            previousMillis = millis();
          }
        }
        
        void newColorWipe()
        {
          if (millis() - previousMillis > interval * 2)
          {
            uint32_t color;
            if (CWColor == 0)
            {
              color = pixels.Color(255, 0, 0);
            }
            else if (CWColor == 1)
            {
              color = pixels.Color(0, 255, 0);
            }
            else if (CWColor == 2)
            {
              color = pixels.Color(0, 0, 255);
            }
            pixels.setPixelColor(i, color);
            pixels.show();
            i++;
            if (i == NUMPIXELS)
            {
              i = 0;
              CWColor++;
              if (CWColor == 3)
                CWColor = 0;
            }
            previousMillis = millis();
          }
        }
        uint32_t Wheel(byte WheelPos) {
          WheelPos = 255 - WheelPos;
          if (WheelPos < 85) {
            return pixels.Color(255 - WheelPos * 3, 0, WheelPos * 3);
          }
          if (WheelPos < 170) {
            WheelPos -= 85;
            return pixels.Color(0, WheelPos * 3, 255 - WheelPos * 3);
          }
          WheelPos -= 170;
          return pixels.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
        }
        
        void writeLEDS(byte R, byte G, byte B)
        {
          for (int i = 0; i < pixels.numPixels(); i ++)
          {
            pixels.setPixelColor(i, pixels.Color(R, G, B));
          }
          pixels.show();
        }
        
        void writeLEDS(byte R, byte G, byte B, byte bright)
        {
          float fR = (R / 255) * bright;
          float fG = (G / 255) * bright;
          float fB = (B / 255) * bright;
          for (int i = 0; i < pixels.numPixels(); i ++)
          {
            pixels.setPixelColor(i, pixels.Color(R, G, B));
          }
          pixels.show();
        }
        
        void writeLEDS(byte R, byte G, byte B, byte bright, byte LED)
        {
          float fR = (R / 255) * bright;
          float fG = (G / 255) * bright;
          float fB = (B / 255) * bright;
          pixels.setPixelColor(LED, pixels.Color(R, G, B));
          pixels.show();
        }</length;></adafruit_neopixel.h></pubsubclient.h></esp8266wifi.h>`[/i][/i][/i]
        
        1 Reply Last reply Reply Quote 0
        • paul53
          paul53 last edited by

          Zur Umwandlung kann auch das NPM-Modul https://www.npmjs.com/package/rgb-hex verwendet werden, das als "Zusätzliches NPM-Modul" in der JS-Konfiguration anzugeben wäre.

          1 Reply Last reply Reply Quote 0
          • N
            nelzon last edited by

            Danke schon mal im voraus. Werde mich die Tage mal damit beschäftigen.

            VG Niels

            1 Reply Last reply Reply Quote 0
            • A
              AndyUM61 last edited by

              @paul53:

              Zur Umwandlung kann auch das NPM-Modul https://www.npmjs.com/package/rgb-hex verwendet werden, das als "Zusätzliches NPM-Modul" in der JS-Konfiguration anzugeben wäre. `

              Hallo,

              also der Tip ist schon toll, aber wie kann man dieses Modul funktionsfähig einbinden/ Installieren??

              ****OK, hat sich erledigt:)!

              Für die, die es auch nicht wissen:

              1. npm install –save rgb-hex

              2. in der Konfiguration des javascript-Adapter unter "Zusätzliches NPM-Modul" rgb-hex eintragen;).****

              1 Reply Last reply Reply Quote 0
              • paul53
                paul53 last edited by

                Wie geschrieben: In der Konfiguration der Javascript-Instanz unter "Zusätzliche NPM-Module" rgb-hex eintragen. Dann wird es automatisch installiert.

                Im Skript steht dann mit

                const rgbHex = require('rgb-hex');
                

                die Funktion rgbHex(R,G,B) zur Verfügung.

                1 Reply Last reply Reply Quote 0
                • N
                  nelzon last edited by

                  habe da mal ne Frage..

                  ich kann an meinen Wemos via HTTP Befehle senden um mein WS2812-Strip zu steuern

                  z.B. http://192.168.xxx.xx/control?cmd=nfx+all+ff0022

                  in Blockly arbeite ich mit der URL um den Strip zu steuern (in Verbindung mit Taster in Homematic)

                  wie kann ich jetzt in VIS eine Farbsteuerung (Änderung des Hex-code in der URL) vornehmen? Jemand ne Idee? Am besten mit einem Farbkreis oder vergleichbarem.

                  Blockly ok, aber Javascript ist nicht mein Gebiet.

                  1 Reply Last reply Reply Quote 0
                  • R
                    rom.wagner80 last edited by

                    @Bluefox:

                    @AndyUM61:

                    Hallo,

                    ich basel heute schon den ganzen Tag an einem kleinen Problem, und komme nicht recht weiter:(.

                    Im Zuge meines kleinen RGB-WS8212-MQTT-Projekts benötige ich einen Datenpunkt,

                    der die RGB Farbwerte des Colorpicker-Widgets in der in HTML üblichen Hexadezimalen Darstellung, also z.B. #FF00FF beinhaltet.

                    Leider erzeugt der Colorpicker ja "nur" 3 separate Datenpunkte mit den einzelnen Farben R, G, B, und das noch als Zahl mit Nachkommastellen.

                    Also z.B. aus 16.000, 104.000, 30.000 aus dem Colorpicker soll #10681E werden

                    Ich habe nun schon diverse Umwandlungen versucht, komme aber zu keinem Ergebnis.

                    Kann mir da jemand helfen?? `
                    Wo machst du diese Umwandlung?

                    Wenn das ioBroker.javascript Adapter währe, dann wird so was gehen:

                    createState('ledRGB', 0);
                    createState('ledR', 0);
                    createState('ledG', 0);
                    createState('ledB', 0, function () {
                        on('javascript.0.ledR', calculateColor);
                        on('javascript.0.ledG', calculateColor);
                        on('javascript.0.ledB', calculateColor);
                    });
                    
                    function toHex(number) {
                        if (number < 0) number = 0xFFFFFFFF + number + 1;
                        var n = number.toString(16).toUpperCase();
                        if (n.length == 1) {
                            n = '0' + n;
                        }
                        return n;
                    }
                    
                    function calculateColor() {
                        var R = Math.round(parseFloat(getState('javascript.0.ledR').val) || 0);
                        var G = Math.round(parseFloat(getState('javascript.0.ledG').val) || 0);
                        var B = Math.round(parseFloat(getState('javascript.0.ledB').val) || 0);
                        setState('javascript.0.ledRGB', '#' + toHex(R) + toHex(G) + toHex(B));
                    }
                    ```` `  
                    

                    Hey. Das Script funktioniert super. Ich nutze allerdings den yahka adapter, der keine RGB-Daten sondern eine Zahl zwischen 0 und 65535 zurück gibt. es scheint ein Spezielles Hue-Format zu sein. ist dir dieses Format bekannt und wäre es möglich das Script dafür umzuwandeln?

                    vielen Dank und schönen Gruß

                    Roman

                    1 Reply Last reply Reply Quote 0
                    • R
                      rom.wagner80 last edited by

                      Gibt es bezüglich der Problematik mit dem Yahka und dem hue-wert eine Lösung ?

                      Gesendet von iPhone mit Tapatalk

                      1 Reply Last reply Reply Quote 0
                      • P
                        Poecki last edited by

                        @nelzon:

                        habe da mal ne Frage..

                        ich kann an meinen Wemos via HTTP Befehle senden um mein WS2812-Strip zu steuern

                        z.B. http://192.168.xxx.xx/control?cmd=nfx+all+ff0022

                        in Blockly arbeite ich mit der URL um den Strip zu steuern (in Verbindung mit Taster in Homematic)

                        wie kann ich jetzt in VIS eine Farbsteuerung (Änderung des Hex-code in der URL) vornehmen? Jemand ne Idee? Am besten mit einem Farbkreis oder vergleichbarem.

                        Blockly ok, aber Javascript ist nicht mein Gebiet. `

                        hast du eine lösung gefunden ? hab ein ähnliches Problem

                        1 Reply Last reply Reply Quote 0
                        • N
                          nelzon last edited by

                          Ich suche auch noch..

                          1 Reply Last reply Reply Quote 0
                          • First post
                            Last post

                          Support us

                          ioBroker
                          Community Adapters
                          Donate

                          858
                          Online

                          31.8k
                          Users

                          80.0k
                          Topics

                          1.3m
                          Posts

                          6
                          14
                          2961
                          Loading More Posts
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes
                          Reply
                          • Reply as topic
                          Log in to reply
                          Community
                          Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen
                          The ioBroker Community 2014-2023
                          logo