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

Ws2811 10×10 panel

Page 2 / 3

 Hans
(@hans)
Noble Member Admin
Joined: 8 years ago
Posts: 2027
 

Hi Darek,

implementing buttons like that wil take some extra work, since the All-in-One LED effects relies on an interrupt being triggered when a button is being pressed. I'm not even sure if the interrupt approach will work that well for this.

Can you explain in more detail what you're thinking of? 
I'm not quite getting what you mean with the LED bounce?
You're thinking of 3 buttons, 2 for the bounce and 1 for selecting a LED effect?

If that is the case then I'd do some testing with attaching interrupts to all 3 buttons.
Eg:

attachInterrupt (digitalPinToInterrupt(BUTTON1), changeEffect, CHANGE); // pressed
attachInterrupt (digitalPinToInterrupt(BUTTON2), changeEffect, CHANGE); // pressed
attachInterrupt (digitalPinToInterrupt(BUTTON3), changeEffect, CHANGE); // pressed

 

And in the "changeEffect" button, detect which button actually was pressed.
Note that we reset the Arduino when changing the effect, therefor it would be a good idea to define the bounce LED effects as individual effects as well, so that we can call it as a selectedEffect from EEPROM.

Eg.

void changeEffect() {
  if (digitalRead (BUTTON1) == HIGH) {
    // some bounce effect
    EEPROM.put(0, XYZ); // store the chose effect (XYZ = number for this effect)
    asm volatile ("  jmp 0");
  }
  else if (digitalRead (BUTTON2) == HIGH) {
    // another bounce effect
    EEPROM.put(0, ABC); // store the chose effect (ABC = number for this effect)
    asm volatile ("  jmp 0");
  }
  else if (digitalRead (BUTTON3) == HIGH) {
    selectedEffect++;
    EEPROM.put(0, selectedEffect); // store the chose effect
    asm volatile ("  jmp 0");
  }
}

 

I hope that makes sense ... 😊 


ReplyQuote
(@darek)
Eminent Member
Joined: 7 months ago
Posts: 21
Topic starter  

Hi Hans.  Thanks for your reply.

1.

I was thinking about to use One push button.  Let's say with bouncing led  if  button pressed once than the one led bounce couple of times.  When button pressed twice than two leds bouncing  . Three times button pressed three leds bouncing couple of times.( Someting like pinball )

2.

Another what I was thinking this is for the meteor  effect.  If the button will be pressed the moeteor start to going from left to right side . And when pressed again meteor start moving from right to left side. ( Basically button for changing direction of meteor)

3.

And the last modification with a bouncing leds.  If we will have three stripes  1 meter each. On first stipe one led bouncing on second stripe one led bouncing and on third stipe one led bouncing.  ( but this I was thinking to do without push button). How those stripes should be connected to arduino? Data pin should be connected differently to each stripe (3 digital pins on arduion) or they could be connected on one digital pin as usual??. 


ReplyQuote
 Hans
(@hans)
Noble Member Admin
Joined: 8 years ago
Posts: 2027
 

Hi Darek,

1 and 2.

You'd have to add one or two global variables, something like "Pressed1Time", "Pressed2Times" and "Pressed3Times" - all set initially to zero.

When the button is pressed, we call the changeEffect() function and there you'll have to detect if the button was pressed 2 or 3 times within a given time span.
Question here is we should change the effect at this time.

When a button is pressed and "Pressed1Time" is zero or "Pressed1Time"+"Allowed time between button pressed" is less than the current time (we waited too long), then we'd store the current time in "Pressed1Time", and reset both "Pressed2Times" and "Pressed3Times" to zero.

When a button press is detected again, and "Pressed1Time" is not zero, and the current time is less that "Pressed1Time"+"Allowed time between button pressed" (within allowed wait time), then we set "Pressed2Times" to the current time.

If we detect a button press again, and "Pressed2Times" is not zero, and the current time is less that "Pressed2Times"+"Allowed time between button pressed" (again within allowed wait time), then we set "Pressed3Times" to the current time.

Now in the effects we can change direction and such based on "Pressed2Times" and/or "Pressed3Times" begin zero or not.

This will be a little convoluted, but I do not think this is impossible.

3. 

There are 2 options when connecting 3 strips.
If the effects should be identical, then this would be very easy (assuming these are the same type and length): You can connect all 3 strips to the same data pin on the Arduino.
This will have them behave identically.

If the effects should not be identical, then you're in for some trouble.
FastLED does support multiple strips, controlled individually, just fine. However, your effects will have to split time in doing each step in the effect. This can be a challenge.


ReplyQuote
(@darek)
Eminent Member
Joined: 7 months ago
Posts: 21
Topic starter  

Hi Hans . 

Thanks for your reply and advise. 

The reason why I was asking for option  to add button  because I've seen in Adafruit library examples with button option. (I know you said earlier FastLed library is better but didn't notice examples with push button. )

And also I  didn't have a chance yet to try connect Adafruit push button example and trying how it works. ( I'm  little bit to busy with my job) .  But your Led Effects  are in both configurations Adafruit and FastLed.  So if I'll try to add smoe lines from examples with push button to your Led effects  it might be work. What do you think about??? 


ReplyQuote
 Hans
(@hans)
Noble Member Admin
Joined: 8 years ago
Posts: 2027
 

Handling a button would be the same for FastLED or NeoPixel. The only difference would be how to set LED colors, which should not affect how the button is handled.

Unless you're referring to a special feature in the NeoPixel library for handling buttons (not to be confused with other AdaFruit libraries of course).


ReplyQuote


(@darek)
Eminent Member
Joined: 7 months ago
Posts: 21
Topic starter  

@hans 

Hi Hans . 

I must to tell you something mate. After couple of months break from practicing on  leds.  I found some evenings lately to learning and practice. And that is the result of your helpful advising. Thanks a lot .

P.S.

The reason to different colours is I wanted to see how code is working. 

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

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

void loop() {
  for(int i=0; i<10; i++)  {   // rows lightning in
leds[i]=CRGB(0,0,10);  // blue
leds[i+90]=CRGB(10,0,0);   //green
for(int i=1; i<=8; i++)  {   // columns lighting in
leds[i×10]=CRGB(0,10,0);  //red
leds[(i×10)+9]=CRGB(0,10,0);
//basically  frame done!!!
//HOORAY
}
}

ReplyQuote
 Hans
(@hans)
Noble Member Admin
Joined: 8 years ago
Posts: 2027
 

Hi Darek!

Cool to see you practicing and learned! Nice! Keep going! 👍 

Code looks nice and clean! Well done!
Let me know if these is anything I can help with! 😊 

 

p.s. I assume you used copy and paste to paste your code - and forgot the last "}" ... (happens to me as well) ? 😊 

#include "FastLED.h"

#define NUM_LEDS 100
CRGB leds[NUM_LEDS];
#define PIN 6

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

void loop() {
    for (int i = 0; i < 10; i++) { // rows lightning in
      leds[i] = CRGB(0, 0, 10); // blue
      leds[i + 90] = CRGB(10, 0, 0); //green
      
      for (int i = 1; i <= 8; i++) { // columns lighting in
        leds[i× 10] = CRGB(0, 10, 0); //red
        leds[(i× 10) + 9] = CRGB(0, 10, 0);
        //basically  frame done!!!
        //HOORAY
      }
      
    }
}  // <-- your code was missing this one, probably a copy and paste thing 😉 

ReplyQuote
(@darek)
Eminent Member
Joined: 7 months ago
Posts: 21
Topic starter  

@hans

Hi Hans

I was thinking ....to 

#define BRIGHTNESS  10 

With all of defines  but i don't know how to execute for example HERE

Leds[i]=CRGB(10,0,0);  Where in the () brackets are colors with brightness.  I'm thinking now ,maybe is working when use  CRGB::RED or  with hexadecimal values like....

CRGB(ff00, 00ff.,ff)  something like this. Never used this form but maybe is working for those two forms. 


ReplyQuote
 Hans
(@hans)
Noble Member Admin
Joined: 8 years ago
Posts: 2027
 

Depends on what you'd like to accomplish. 😊 

FastLED has some very nice functions that can help with this.

If you only want one LED to become darker then you could use the fadeToBlackBy function. 

leds[i] = CRGB::Red; // just a random example color
leds[i].fadeToBlackBy( fadeValue );
FastLED.show();

 

There is also the fadeLightBy function ... (they both work slightly different)

leds[i] = CRGB::Red; // just a random example color
leds[i].fadeLightBy( fadeValue );
FastLED.show();

 

 

You could also use a setBrightness for all LEDs with the Brightness function.
You can call this brightness function anywhere in your code, but you may need to call FastLED.show after that.

#define BRIGHTNESS 10

...

// FastLED.Add ....

FastLED.setBrightness(BRIGHTNESS );

// may need "FastLED.show()" after that

...

 

Hope any of this is what you're looking for? 😊 


ReplyQuote
(@darek)
Eminent Member
Joined: 7 months ago
Posts: 21
Topic starter  

Hi Hans

Could you check this code for me please.  The second line coming to error while verify.  So i just comment on this line by  "//" to ignore it. Than I added 

#define[ NUM_LEDS] 50

CRGB  g_LEDs [NUM_LEDS]; 

and error compiling for Arduino Uno  coming out. 

What can be wrong here because is to complicated for me.


ReplyQuote


(@darek)
Eminent Member
Joined: 7 months ago
Posts: 21
Topic starter  
 
#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: 7 months ago
Posts: 21
Topic starter  

I mean if you could just verify on your Arduino Uno board  and see what is going  on I'll be very appreciate.  Thanks 


ReplyQuote
 Hans
(@hans)
Noble Member Admin
Joined: 8 years ago
Posts: 2027
 

In your code:

#define[ NUM_LEDS] 50
CRGB  g_LEDs [NUM_LEDS]; 

 

you used the "define" wrong. There should not be square brackets around it.
Corrected:

#define NUM_LEDS 50
CRGB  g_LEDs [NUM_LEDS]; 

 

Read the define function as: Before the compiler does its work, temporary replace all occurrences of "NUM_LEDS" with "50".

The square brackets on the other hand are used to set an index ... which is used with an array, but not with a "define" 😊

Hope this helps ...

If it still fails, then please post the entire sketch (or as an attachment) - I cannot verify only parts of the code, I will need the entire sketch.


ReplyQuote
(@darek)
Eminent Member
Joined: 7 months ago
Posts: 21
Topic starter  

Sorry my mistake.  I did it  define NUM_LEDS 

without those brackets which you mention  ,and this code come with the error  for Arduino  Uno .


ReplyQuote
(@darek)
Eminent Member
Joined: 7 months ago
Posts: 21
Topic starter  

Basically if you could run this main code on your Arduino or just verify on Arduino IDE. And tell if its ok. Thank you.


ReplyQuote


Page 2 / 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: