Page 1 of 1
Forum

Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!

Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.

Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is no translation for that post!




Ws2811 10×10 panel
 
Share:
Notifications
Clear all

[Solved] Ws2811 10×10 panel

38 Posts
2 Users
1 Likes
9,747 Views
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2660
 

You will need to post your full sketch ... the code you posted before is incomplete ...

Als when you get an error message: copy and paste the error message here as well, this way I can find the problem much faster with much less effort.

For example in the code you posted earlier, you are missing a "void setup" and a "void loop" ...
I'm not sure where the DrawMarquee functions come from either or where the u8G2 library is being used ... 😔 

Posted by: @darek
 
#include <Arduino.h>
#include <U8g2lib.h>
#define FASTLED_INTERNAL
#include <FastLED.h>


void DrawMarquee()
{
    static byte j = 0;
    j+=4;
    byte k = j;

    // Roughly equivalent to fill_rainbow(g_LEDs, NUM_LEDS, j, 8);

    CRGB c;
    for (int i = 0; i < NUM_LEDS; i ++)
        g_LEDs[i] = c.setHue(k+=8);

    static int scroll = 0;
    scroll++;

    for (int i = scroll % 5; i < NUM_LEDS - 1; i += 5)
    {
        g_LEDs[i] = CRGB::Black;
    }
    delay(50);
}

void DrawMarqueeMirrored()
{
    static byte j = 0;
    j+=4;
    byte k = j;

    // Roughly equivalent to fill_rainbow(g_LEDs, NUM_LEDS, j, 8);

    CRGB c;
    for (int i = 0; i < (NUM_LEDS + 1) / 2; i ++)
    {
        g_LEDs[i] = c.setHue(k);
        g_LEDs[NUM_LEDS - 1 - i] = c.setHue(k);
        k+= 8;
    }


    static int scroll = 0;
    scroll++;

    for (int i = scroll % 5; i < NUM_LEDS / 2; i += 5)
    {
        g_LEDs[i] = CRGB::Black;
        g_LEDs[NUM_LEDS - 1 - i] = CRGB::Black;
    }   

    delay(50);
}

 


   
ReplyQuote
(@darek)
Eminent Member
Joined: 3 years ago
Posts: 21
Topic starter  

Yes I'm noticed void setup and loop is missing . I'm just copy that code from github .  I'm learning or try to learn all of this new staff. Maybe I missed some file from there. 

Thanks anyway. 


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2660
 

Well looking into the code of others is never a bad thing - I do this from time to time as well 😊 

Just be careful with copy and paste.

On that note:
It is not always easy to look at the code from others, and sometimes takes quite a bit of effort to understand what the programmer was trying to do.


   
ReplyQuote
(@darek)
Eminent Member
Joined: 3 years ago
Posts: 21
Topic starter  

HI Hans.

1)    I have issue with some codes. I'm using your LED strip effects . But what I trying to  do is. I'm trying to use three effects on one strip. First 5 LEDs light still , middle bit to cylon or other effect , and last 5 LEDs flashing. 

So I manage to do 5 LEDs still with middle bit Fade In and Fade Out ..... but something is blocking me to flashing rest of the LEDs. So I named middle bit TREE and flashing bit as TOP  and still  bit is in loop . I know is not enough LEDs in middle bit array becase this is testing code and my strip have 68 LEDs.I'm only try to wrork couple effects on one strip. Ihave moment it was work for while 3 effects I mean, but the TOP bit was flashing after when the middle loop was finish( fade in and out).

2)  Than another thing what I was thinkig of is METEOR effect . Hoe to make meteor go right after tail. Not to wait until all strip will be clear. Because I try to longer the Meteor tail or time etc. And new Meteor start run after last tail is dissapear. So my question is if is possible to make it your METEOR cde this way. And which line in this code is responsible for that.

P.S.  I didnt put code of meteor here . This code below is only for issue number 1.Thank you.

#include "FastLED.h"
#define NUM_LEDS 68
CRGB leds[NUM_LEDS];
#define PIN 6

#define NUM_TREE_LEDS 41

int Tree[NUM_TREE_LEDS]={3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43};

#define NUM_TOP_LEDS  2
int Top[NUM_TOP_LEDS]={66,67};


void setup()
{
  FastLED.addLeds<WS2811, PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
}



void showStrip() {
 #ifdef ADAFRUIT_NEOPIXEL_H
   // NeoPixel
   strip.show();
 #endif
 #ifndef ADAFRUIT_NEOPIXEL_H
   // FastLED
   FastLED.show();
 #endif
}

void setPixel(int Pixel, byte red, byte green, byte blue) {
 #ifdef ADAFRUIT_NEOPIXEL_H
   // NeoPixel
   strip.setPixelColor(Pixel, strip.Color(red, green, blue));
 #endif
 #ifndef ADAFRUIT_NEOPIXEL_H
   // FastLED
   leds[Pixel].r = red;
   leds[Pixel].g = green;
   leds[Pixel].b = blue;
 #endif
}

void setAll(byte red, byte green, byte blue) {
  for(int i = 3; i < NUM_TREE_LEDS; i++ ) {           // here is change to TREE
    setPixel(i, red, green, blue);
  }
  showStrip();
}


void loop() {

 for(int i=0; i<3; i++){            // this is still bit
    leds[i]=CRGB(10,10,0);            
    FastLED.show();}

    for(int a=0;a<256 ;a++){              //this should be a TOP bit
    leds[Top]=CRGB(20,20,20);
    
    }
//    FastLED.show();
    delay (10);
    FastLED.show();
 
    for (int a=255;a>0;a--){
    leds[Top]=CRGB(0,0,0);
    
    }
    
 
 delay(10);
 FastLED.show();
 
 
  RGBLoop();
}

void RGBLoop(){
  for(int j = 0; j < 3; j++ ) {
    // Fade IN
    for(int Tree = 0; Tree < 256; Tree++) {
      switch(j) {
        case 0: setAll(Tree,0,0); break;
        case 1: setAll(0,Tree,0); break;
        case 2: setAll(0,0,Tree); break;
      }
      showStrip();
      delay(3);
    }
    // Fade OUT
    for(int Tree = 255; Tree >= 0; Tree--) {
      switch(j) {
        case 0: setAll(Tree,0,0); break;
        case 1: setAll(0,Tree,0); break;
        case 2: setAll(0,0,Tree); break;
      }
      showStrip();
      delay(3);
    }
  }
}

   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2660
 

So when combining effects, you will have to make sure that "steps" of each of effects is ebin executed.
This can come with a lot of challenges, since some effects keep running in their own loop, and won't allow the other effects to do their "steps".

If I understand things right: you have 5 LEDs steady and one color, then a few LEDs that do the RGB loop, and 5 LEDs at the end that flash (like the strobe effect maybe?).

Since the first 5 are easy, and you already managed the 2nd effect (I did not verify the code), the adding the 3rd effect may not be that difficult. The only thing that may be a challenge in the 3rd effect is how fast it should be flashing.

This is how I would approach this initially:

1. The Cylon Effect or RGB loop should run for the range between the 6th LED and the 6th LED before the end.
2. I'd modify the ShowStrip() function in which we set the first 5 LEDs to a solid color, and alternate on/off of the last 5 LEDs.

For example, something like this (I removed the Adafruit stuff since you're using FastLED anyway):

void showStrip() {
  // fill 5 first LEDs with a color, say white for example
  for(i=0; i<5; i++) {
    leds[i]=CRGB(10,10,0);
  }

  // toggle last ones on/off
  CRGB lastColor;
  if(leds[i]==CRGB(0,0,0)) {
    lastColor = CRGB(10,10,0); 
  } else {
    lastColor = CRGB(0,0,0);
  }
 
  for(i=NUM_LEDS-5; i<NUM_LEDS; i++) {
    leds[i]=lastColor;
  }

  FastLED.show();
}

 

Note: untested code, and I may not have had enough coffee yet today to wake up my brain 😁 

Now the problem with this solution is that you have no control over the flashing speed. Right now it just toggles colors.

You could also try this, to make it flash (strobe like), but again, you have no control over the speed.

void showStrip() {
  // fill 5 first LEDs with a color, say white for example
  for(i=0; i<5; i++) {
    leds[i]=CRGB(10,10,0);
  }

  // set last ones off
  for(i=NUM_LEDS-5; i<NUM_LEDS; i++) {
    leds[i]=CRGB(0,0,0);
  }

  FastLED.show();
 
  // set last ones on
  for(i=NUM_LEDS-5; i<NUM_LEDS; i++) {
    leds[i]=CRGB(10,10,0);
  }

  FastLED.show();
}

 

Now, and I do not consider this a good solution but it may be sufficient for your application, you could add a delay after the first "FastLED.show()", but this would affect the cylon or RGBLoop effect as well.

You could make it more controllable (and complex) by using the internal clock of your Arduino and turn those last 5 LEDs on or off based on how much time has passed.

As yet another complex alternative; you could experiment with interrupts. I have to warn you though that working with interrupts can be a pain 😊 

I hope this at least gets you started.

 


   
ReplyQuote


(@darek)
Eminent Member
Joined: 3 years ago
Posts: 21
Topic starter  

Thank you Hans for your answer.  I will try it those codes how they will cooperate together.  

I've got another question about meteor effect. Where about we must change this code to new meteor cycle be right behind the meteor tail. I mean if we don't have to wait until whole strip is clear than new cycle is started.  

Thank you.

void loop() {
  meteorRain(0xff,0xff,0xff,10, 64, true, 30);
}

void meteorRain(byte red, byte green, byte blue, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay) {  
  setAll(0,0,0);
 
  for(int i = 0; i < NUM_LEDS+NUM_LEDS; i++) {
   
   
    // fade brightness all LEDs one step
    for(int j=0; j<NUM_LEDS; j++) {
      if( (!meteorRandomDecay) || (random(10)>5) ) {
        fadeToBlack(j, meteorTrailDecay );        
      }
    }
   
    // draw meteor
    for(int j = 0; j < meteorSize; j++) {
      if( ( i-j <NUM_LEDS) && (i-j>=0) ) {
        setPixel(i-j, red, green, blue);
      }
    }
   
    showStrip();
    delay(SpeedDelay);
  }
}

void fadeToBlack(int ledNo, byte fadeValue) {
 #ifdef ADAFRUIT_NEOPIXEL_H
    // NeoPixel
    uint32_t oldColor;
    uint8_t r, g, b;
    int value;
   
    oldColor = strip.getPixelColor(ledNo);
    r = (oldColor & 0x00ff0000UL) >> 16;
    g = (oldColor & 0x0000ff00UL) >> 8;
    b = (oldColor & 0x000000ffUL);

    r=(r<=10)? 0 : (int) r-(r*fadeValue/256);
    g=(g<=10)? 0 : (int) g-(g*fadeValue/256);
    b=(b<=10)? 0 : (int) b-(b*fadeValue/256);
   
    strip.setPixelColor(ledNo, r,g,b);
 #endif
 #ifndef ADAFRUIT_NEOPIXEL_H
   // FastLED
   leds[ledNo].fadeToBlackBy( fadeValue );
 #endif  
}

   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2660
 

Hi Darek,

if I recall correctly, tinker with these lines:

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

 

Change "NUM_LEDS+NUM_LEDS" to just "NUM_LEDS".
It's been a while that I've tinkered with it though. 😊 

 


   
ReplyQuote
(@darek)
Eminent Member
Joined: 3 years ago
Posts: 21
Topic starter  

Ok 👍.  Thank you so much Hans. 


   
Hans reacted
ReplyQuote
Page 3 / 3

Like what you see and you'd like to help out? 

The best way to help is of course by assisting others with their questions here in the forum, but you can also help us out in other ways:

- Do your shopping at Amazon, it will not cost you anything extra but may generate a small commission for us,
- send a cup of coffee through PayPal ($5, $10, $20, or custom amount),
- become a Patreon,
- donate BitCoin (BTC), or BitCoinCash (BCH).

Share: