Announcement

Collapse
No announcement yet.

SK6812 RGBW Arduino Sketches.

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • SK6812 RGBW Arduino Sketches.

    Hello,

    Need some help with a setup using SK6812 RGBW Sketches.

    The sketch already has several LED functions that run in a loop, but I want to separate them as different actions, that can be triggered by HS events.

    So, how do I stop the loop? Do I remove the following code?
    void loop(){
    colorFill(CRGB::Red);
    colorFill(CRGB::Green);
    colorFill(CRGB::Blue);
    fillWhite();
    rainbowLoop();

    Using your plugin, how do I create HS Devices for each Function?
    *rainbowLoop
    *fillWhite
    *rainbow
    *colorFill



    Code:
    /* FastLED RGBW Example Sketch
     *
     * Example sketch using FastLED for RGBW strips (SK6812). Includes
     * color wipes and rainbow pattern.
     *
     * Written by David Madison
     * http://partsnotincluded.com
    */
    
    #include "FastLED.h"
    #include "FastLED_RGBW.h"
    
    #define NUM_LEDS 60
    #define DATA_PIN 6
    
    CRGBW leds[NUM_LEDS];
    CRGB *ledsRGB = (CRGB *) &leds[0];
    
    const uint8_t brightness = 128;
    
    void setup() { 
        FastLED.addLeds<WS2812B, DATA_PIN, RGB>(ledsRGB, getRGBWsize(NUM_LEDS));
        FastLED.setBrightness(brightness);
        FastLED.show();
    }
    
    void loop(){
        colorFill(CRGB::Red);
        colorFill(CRGB::Green);
        colorFill(CRGB::Blue);
        fillWhite();
        rainbowLoop();
    }
    
    void colorFill(CRGB c){
        for(int i = 0; i < NUM_LEDS; i++){
            leds[i] = c;
            FastLED.show();
            delay(50);
        }
        delay(500);
    }
    
    void fillWhite(){
        for(int i = 0; i < NUM_LEDS; i++){
            leds[i] = CRGBW(0, 0, 0, 255);
            FastLED.show();
            delay(50);
        }
        delay(500);
    }
    
    void rainbow(){
        static uint8_t hue;
    
        for(int i = 0; i < NUM_LEDS; i++){
            leds[i] = CHSV((i * 256 / NUM_LEDS) + hue, 255, 255);
        }
        FastLED.show();
        hue++;
    }
    
    void rainbowLoop(){
        long millisIn = millis();
        long loopTime = 5000; // 5 seconds
    
        while(millis() < millisIn + loopTime){
            rainbow();
            delay(5);
        }
    }
    HSPro: 3.0.0.194
    PL: Insteon PLM 3.0.5.20,Insteon Thermostat 3.0.1.1 , UltraM1G, RainRelay8, UltraECM3, UltraPioneerAVR3, BLBackup, weatherXML, Jon00 Network & PC Monitor
    HW : Win 7 64bit, Intel i7-2600, 16 GB DDR3 Ram, 60 Plus Insteon Dual Band Devices, Rain8 Pro2, Elk M1 Gold, Brueltech GreenEye.

  • #2
    As it happens I am looking to do something similar but it is not as easy as you would think because there is timing problems as the sketch you have uses the delay function and this blocks the plugin sketch from working.
    To answer your question you can use a switch case against FromHS[] to pick a value but you still need to change the code so it is non blocking. I have modified the code of one library to be non blocking but there is another bug the causes it to crash on the esp8266 which is what I want to run it on. I will post back if I get a working solution.

    Greig.

    Sent from my SM-G950F using Tapatalk

    Zwave = Z-Stick, 3xHSM100 7xACT ZDM230, 1xEverspring SM103, 2xACT HomePro ZRP210.
    X10 = CM12U, 2xAM12, 1xAW10, 1 x TM13U, 1xMS13, 2xHR10, 2xSS13
    Other Hardware = ADI Ocelot + secu16, Global Cache GC100, RFXtrx433, 3 x Foscams.
    Plugings = RFXcom, ActiveBackup, Applied Digital Ocelot, BLDeviceMatrix, BLGarbage, BLLAN, Current Cost, Global Cache GC100,HSTouch Android, HSTouch Server, HSTouch Server Unlimited, NetCAM, PowerTrigger, SageWebcamXP, SqueezeBox, X10 CM11A/CM12U.
    Scripts =
    Various

    Comment


    • #3
      Much appreciated Greig.

      Is crashing susceptible only on the Esp8622, but not others like the Uno?

      Sent from my SM-G965U using Tapatalk

      HSPro: 3.0.0.194
      PL: Insteon PLM 3.0.5.20,Insteon Thermostat 3.0.1.1 , UltraM1G, RainRelay8, UltraECM3, UltraPioneerAVR3, BLBackup, weatherXML, Jon00 Network & PC Monitor
      HW : Win 7 64bit, Intel i7-2600, 16 GB DDR3 Ram, 60 Plus Insteon Dual Band Devices, Rain8 Pro2, Elk M1 Gold, Brueltech GreenEye.

      Comment


      • #4
        Sorry I look at this on my phone and it did not show your code. The Fast LED Library is what I am now using with as it looks to be non blocking. I have a test set up and working here but would like to leave it running to check we do not get the crashing I seen with the other libraries.
        To answer your first question you just need to create 1 chase select device and then use the value in the FromHS[] to select the chase in the code.

        I have the following device in HS
        Chase Select
        Intensity 0 - 255
        Speed (not yet implemented)
        Red Value 0 - 255
        Green Value 0 - 255
        Blue Value 0 - 255

        Here is some of my code to give you an idea of how I am doing it. My Sketch has lots of other things in it to so I will need to clean it up and strip out all my other code before posting a working solution.

        Hope this helps.
        Code:
        // List of patterns to cycle through.  Each is defined as a separate function below.
        typedef void (*SimplePatternList[])();
        SimplePatternList gPatterns = {FadeOut, rainbow, rainbowWithGlitter, confetti, sinelon, juggle, SetColour, ToDoor };
        
        uint8_t gCurrentPatternNumber = 0; // Index number of which pattern is current
        uint8_t gHue = 0; // rotating "base color" used by many of the patterns
        
        
        void LED() {
        
         #define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))
        
          FastLED.setBrightness(FromHS[2]);//Set the Brighness form a HS device 0 - 255 range
        
          FastLED.show(); // send the 'leds' array out to the actual LED strip 
        
          FastLED.delay(1000/FRAMES_PER_SECOND);  // insert a delay to keep the framerate modest
        
          // do some periodic updates
          EVERY_N_MILLISECONDS( FromHS[3] ) { gHue++; } // slowly cycle the "base color" through the rainbow
        
          //if the chase has changed.
          if (FromHS[1] != LastChase) {
           LastChase = FromHS[1];
            gCurrentPatternNumber = FromHS[1] ; // change pattern number
            i = 0;//Clear Selected LED back to 0
          gPatterns[gCurrentPatternNumber]();// Call the current pattern function once, updating the 'leds' array
        }
        
        void FadeOut() {
         fadeToBlackBy( leds, NUM_LEDS, 20);
        }
        
        void rainbow() 
        {
          // FastLED's built-in rainbow generator
          fill_rainbow( leds, NUM_LEDS, gHue, 7);
        }
        
        void rainbowWithGlitter() 
        {
          // built-in FastLED rainbow, plus some random sparkly glitter
          rainbow();
          addGlitter(80);
        }
        
        void addGlitter( fract8 chanceOfGlitter) 
        {
          if( random8() < chanceOfGlitter) {
            leds[ random16(NUM_LEDS) ] += CRGB::White;
          }
        }
        
        void confetti() 
        {
          // random colored speckles that blink in and fade smoothly
          fadeToBlackBy( leds, NUM_LEDS, 10);
          int pos = random16(NUM_LEDS);
          leds[pos] += CHSV( gHue + random8(64), 200, 255);
        }
        
        void sinelon()
        {
          // a colored dot sweeping back and forth, with fading trails
          fadeToBlackBy( leds, NUM_LEDS, 20);
          int pos = beatsin16( 13, 0, NUM_LEDS-1 );
          leds[pos] += CHSV( gHue, 255, 192);
        }
        
        void bpm()
        {
          // colored stripes pulsing at a defined Beats-Per-Minute (BPM)
          uint8_t BeatsPerMinute = 62;
          CRGBPalette16 palette = PartyColors_p;
          uint8_t beat = beatsin8( BeatsPerMinute, 64, 255);
          for( int i = 0; i < NUM_LEDS; i++) { //9948
            leds[i] = ColorFromPalette(palette, gHue+(i*2), beat-gHue+(i*10));
          }
        }
        
        void juggle() {
          // eight colored dots, weaving in and out of sync with each other
          fadeToBlackBy( leds, NUM_LEDS, 20);
          byte dothue = 0;
          for( int i = 0; i < 8; i++) {
            leds[beatsin16( i+7, 0, NUM_LEDS-1 )] |= CHSV(dothue, 200, 255);
            dothue += 32;
          }
        }
        
        void SetColour() {
          for (int i = 0; i < NUM_LEDS; i++){
           leds[i].setRGB( FromHS[4], FromHS[5], FromHS[6]);
          }
        }
        
        void ToDoor() { 
        
        if (i > 150) {
          return;
            }
            if (i >= NUM_LEDS) {
            i = 0;
          }
          if (i >= 25 && i < 150){
           leds[i-25] = CRGB::Black;
          }
           leds[i] = CRGB::White;
        
        if (i = 150){
        // for( int i = 0; i = 125; i++) {
        //  leds[i] = CRGB::White;
        // }
        }
        
          i++;
        
        }
        Zwave = Z-Stick, 3xHSM100 7xACT ZDM230, 1xEverspring SM103, 2xACT HomePro ZRP210.
        X10 = CM12U, 2xAM12, 1xAW10, 1 x TM13U, 1xMS13, 2xHR10, 2xSS13
        Other Hardware = ADI Ocelot + secu16, Global Cache GC100, RFXtrx433, 3 x Foscams.
        Plugings = RFXcom, ActiveBackup, Applied Digital Ocelot, BLDeviceMatrix, BLGarbage, BLLAN, Current Cost, Global Cache GC100,HSTouch Android, HSTouch Server, HSTouch Server Unlimited, NetCAM, PowerTrigger, SageWebcamXP, SqueezeBox, X10 CM11A/CM12U.
        Scripts =
        Various

        Comment


        • #5
          Here's something I didn't count on. At first I ordered 1 strip (5m w/300 led) and ran the modified Fast LED code with an Uno. Today I tried running 3 strips (15m w/900 led) and its way beyond what an Uno can do.

          Below is only running 400 LED and uses 82% of memory;

          Code:
          Sketch uses 4078 bytes (12%) of program storage space. Maximum is 32256 bytes.
          Global variables use 1698 bytes (82%) of dynamic memory, leaving 350 bytes for local variables. Maximum is 2048 bytes.
          Low memory available, stability problems may occur.

          This is the website I took the code from, to get the SK6812 to run on WS2812B code. Your correct about different timing, and that's where they modified a fix. Here's the link,

          https://www.partsnotincluded.com/pro...pixels-sk6812/
          HSPro: 3.0.0.194
          PL: Insteon PLM 3.0.5.20,Insteon Thermostat 3.0.1.1 , UltraM1G, RainRelay8, UltraECM3, UltraPioneerAVR3, BLBackup, weatherXML, Jon00 Network & PC Monitor
          HW : Win 7 64bit, Intel i7-2600, 16 GB DDR3 Ram, 60 Plus Insteon Dual Band Devices, Rain8 Pro2, Elk M1 Gold, Brueltech GreenEye.

          Comment

          Working...
          X