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!




Blinking Halloween ...
 
Share:
Notifications
Clear all

[Solved] Blinking Halloween Eyes with different colors

36 Posts
3 Users
0 Likes
6,114 Views
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2660
Topic starter  

I'm trying to find some time this weekend, but I really have to finish another project first.

Just a question: say you'd build the 3 LED setup. Those 3 LEDs would be at random places right? So it's not like they "interact" or depend on each other? I was thinking about it last night and was initially thinking of 3 LEDs very close to each other, where it would give some kind of "sparkling" effect ...


   
ReplyQuote
(@bravozulu)
Active Member
Joined: 7 years ago
Posts: 15
 

Hi Hans,

Glad to read you !  

To answer your last question:
- Those 3 LEDs would be at random places right? Yes
- So it’s not like they “interact” or depend on each other? No
- I was thinking of 3 LEDs very close to each other, where it would give some kind of “sparkling” effect … : Yes, it is certainly that.

Find here an illustration (3 LEDs) of what could be a project with 2-3 LEDs.
The idea is to have a diffusion effect (through the fabric) and thus cross (merge) the hues between the LEDs.
This is the "romantic" version, but I also consider more modern/contemporary and graphic variants with other materials (foam...) and 3D (flexible-transparent) printing for LED inlay.

It just remains to set up the concept and see the result  

I wish you a nice day.
... and do not forget the airbag for landing in your sofa  
Guy-Laurent


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

Cool! Well, I made the test version available of my other project, so hopefully I get to play a little with your idea tonight ... and yes, that will happen on the sofa as well hahah 

Hope you're having a great day as well ... although, you're is close to ending right ... 


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

I've been playing for a bit with this (I'll continue tomorrow evening) but it's not going to be straight forward or easy ... hahah

Well, the challenge will be handling 1 - 3 async fade-in/out ... I'll figure out a way though 


   
ReplyQuote
(@bravozulu)
Active Member
Joined: 7 years ago
Posts: 15
 

Hello Hans,

Thank you for these informations and for your research and testing  

Well, I'm looking forward to testing these commands/scripts and seeing the results  
Good workflow ...
Guy-Laurent


   
ReplyQuote


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

OK, try this ... it took me a bit to make something that can handle more than 1 LED simultaneous in all possible random ways.
Color palette (ie the colors we randomly choose from are defined here (3 in this example):

CRGB palette[NUMCOLORS]= { CRGB(0xff,0,0), CRGB(0,0xff,0), CRGB(0,0,0xff) };

In the InitLED() function you can play a little with the values, but take the wrong values and things might not work as desired.
That's also the reason why I commented out all the Serial message (begin, print and println). You can uncomment them if you'd like to track what is going on.
Random activation moment:

  LEDStatus[led].active = (random(60)<50); 

Make the number 60 higher and it becomes less likely that a LED will light up.
Brightness can be limited with the maxvalue (chooses a value between 16 and 128):

  LEDStatus[led].maxvalue = random(16,128);

and max darkness (16 is not visible on my LED strip and is convenient with the if <= comparison:

  LEDStatus[led].minvalue = 16;

The stepsize determines how fast a fade goes, higher number means faster, max value is 256 (instant on/off).
Zero would mean no fading, so we have to avoid that, hence the constant "MINSTEPSIZE".

  LEDStatus[led].stepsize = MINSTEPSIZE+random(16); 

Here is the full code ... 

#include <FastLED.h>
#define NUMLEDS 3 // number of LEDs we want to work with
#define NUMCOLORS 3 // number of colors we'd like to define
#define LEDPIN 5 // The Arduino pin we connect our LEDs Din to
#define MINSTEPSIZE 4 // We need to set a minimum stepsize, >0 !!
struct ledstatus {
  CRGB colorBase; // The color at it's brightest setting
  boolean active; // is fading in/out or not (=off)
  boolean isFading; // is in the progress of fading (true) or brightening (false) if active
  byte maxvalue; // max brightness value (0-256, 256=brightest)
  byte minvalue; // min brightness value (0-256, 0=black)
  byte currentvalue; // current brightness tracking (0-256)
  byte stepsize; // fade step size (0-256, 5 = 5/256th) 
};
ledstatus LEDStatus[NUMLEDS];
CRGB palette[NUMCOLORS]= { CRGB(0xff,0,0), CRGB(0,0xff,0), CRGB(0,0,0xff) };
CRGB leds[NUMLEDS];
void setup() {
  FastLED.addLeds<NEOPIXEL, LEDPIN>(leds, NUMLEDS);
  
  randomSeed(analogRead(0));
  // Serial.begin(9600);
  
  for(int counter; counter<NUMLEDS; counter++) {
    InitLED(counter);
  }
}
void loop() {
  EVERY_N_MILLIS(50) // do this only every x milliseconds
  {  
    for(int counter; counter<NUMLEDS; counter++) // prep all LEDs
    {
      if(LEDStatus[counter].active) // if LED active, act on fade in or out
      { // LED is active - is it fading or brightening?
        if(LEDStatus[counter].isFading) // -> Fading
        {  
          // Serial.print(counter);
          // Serial.println(" LED is Fading");                                         
          leds[counter].nscale8(LEDStatus[counter].currentvalue);
          LEDStatus[counter].currentvalue=LEDStatus[counter].currentvalue-LEDStatus[counter].stepsize; 
          if(LEDStatus[counter].currentvalue<=LEDStatus[counter].minvalue) // we reached the lowest value
          {  
            //LEDStatus[counter].active=false;
            InitLED(counter);
            leds[counter] = CRGB::Black;
          }
        }
        else 
        { // -> brightening
          // Serial.print(counter);
          // Serial.println(" LED is Brightening");
          LEDStatus[counter].currentvalue=LEDStatus[counter].currentvalue+LEDStatus[counter].stepsize; 
          leds[counter]=LEDStatus[counter].colorBase;
          leds[counter].nscale8(LEDStatus[counter].currentvalue);
          
          if(LEDStatus[counter].currentvalue>=LEDStatus[counter].maxvalue) // we reached the highest value
          {  
            LEDStatus[counter].isFading = true; // start fading in next cycle
            LEDStatus[counter].stepsize = MINSTEPSIZE+random(8); // make fade out different from fade in speed
          }        
        }
      }
      else // led not active, set to black and guess new color and random activation
      {      
        // Serial.print(counter);
        // Serial.println(" LED is inactive");   
        leds[counter] = CRGB::Black;
        InitLED(counter); 
      } 
    }
    FastLED.show();
  } // EVERY_N_MILLIS
}
void InitLED(int led) {
  // Serial.print(led);
  // Serial.println(" LED INIT");
  LEDStatus[led].active = (random(60)<50);
  LEDStatus[led].colorBase = palette[random(NUMCOLORS)];
  LEDStatus[led].isFading = false;
  LEDStatus[led].maxvalue = random(16,128);
  LEDStatus[led].minvalue = 16;
  LEDStatus[led].currentvalue = LEDStatus[led].minvalue;
  LEDStatus[led].stepsize = MINSTEPSIZE+random(16); 
}

I'll post a little video after this code section ...


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

Obviously I could have picked better colors (I used red, green and blue and for your broches you'd probably want to pick a more elegant palette).


   
ReplyQuote
(@bravozulu)
Active Member
Joined: 7 years ago
Posts: 15
 

Hi Hans,

Fantastic !  
I will be able to bring out my programming materials to try to understand the principles - I'm going to have some work ...  

Unfortunately this week it's my turn to be very busy. But as soon as I have a moment I will try.
(Which leaves you a little respite - before my next questions - HiHiHi   ).

I still have 2 questions:
a) What is your main argument for choosing "FastLED" ? (Compared to "Neopixel");
b) Can I use the same script (by changing the number of LEDs) for a project with 1 LED ?

A big thank you for this work.
Guy-Laurent

PS: Regarding the video: is there a format (WebM, H.265, etc. /Detected) that can play (show) a video on your Forum ?


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

Hi Guy-Laurent,

(do folks just call you Guy? or the full Guy-Laurent? Just being curious )

If you have questions concerning the code; please feel free to ask. And I'm sure it can be optimized.

I prefer FastLED, in part for no real good reason and in part because they say it's faster than NeoPixel. But in all honesty I cannot deny or confirm that. I just like FastLED better ... 
Oh wait, I think FastLED has more advanced functions available ... 

I have not tested it for 1 LED (yet), but I can give it a try during lunch or tonight when I'm home. I did design it with that in mind though.


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

Forgot to answer your video format question; 
I'll have to look into that. bbPress migth or might not support it ...


   
ReplyQuote


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

I tried a few options, but it seems the forum is not liking it very much to embed video ...
I'm sure it's somewhere in the settings of functions file, but since I'm at work I do not have much time to look into that ... 

I am however still looking for a replacement forum ... bbPress works well, but has it's quirks ... I'd rather be using phpBB and the likes, but they all lack a proper WordPress integration ... 


   
ReplyQuote
(@bravozulu)
Active Member
Joined: 7 years ago
Posts: 15
 

Hello Hans,

People call me Guy-Laurent, because I just do not answer Guy    (I like my compound first name which is original...).

Concerning the video, at the start I forgot that your examples are on a page of Articles and not in the Forum.

About FastLED, I had read before that it was faster and with advanced features. What interested me was the use of "HSV" Hue, Saturation, and Value (or 'Brightness') for colors. Easier and more precise for my projects. FastLED CRGB (Hex).
On the other hand, by taking up the subject now, I can not find a converter to assign values 0-255 instead of 360°.

I will also work with color palette generators. In relation to the complementary colors.

To be continued...  
Guy-Laurent


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

Alright haha, I'll call you Guy-Laurent 
No problem - just didn't want to say your first name wrong hahah ...

FastLED does indeed support HSV - I actually considered using it for your project, but then I found an easier way haha (nscale8). Would have been great if we'd be able to use HSV to fade or brighten a color by using "value", however, I did not find a setValue() function.

We could modify the code a little and use the currentColor variable to keep track of the color and use currentValue to keep track of "Value".


   
ReplyQuote
(@bravozulu)
Active Member
Joined: 7 years ago
Posts: 15
 

Hi Hans !

One thing brings another. It's the Art of Creating. It is you who have definitively brought me to FastLED  

Dimming and Brightening Colors:
I actually have seen this function (nscale8) - thinking my project.

There is a way to set the "hue" - but not the "value" ?!
https://github.com/FastLED/FastLED/wiki/Pixel-reference#automatic-color-conversion

// set color to a pure, bright, fully saturated, hue
  leds.setHue( 160);

Actually, I still do not understand much about these setup. You are therefore the only "master on board" to evaluate the possible nesting in your script and my projects.

It is a shame not to find a conversion table between values of "hue" in 360° (Standard) and the hue chart FastLED in 0-255.
https://github.com/FastLED/FastLED/wiki/Pixel-reference#introduction-to-hsv
Often in other HSV color spaces, hue is represented as an angle from 0-360 degrees. But for compactness, efficiency, and speed, this library represents hue as a single-byte number from 0-255.
HSV color spaces: rainbow
HSV color spaces: spectrum

Saturday, I would do my tests - with the material and real conditions. (Before that will be impossible).
I'm looking forward to seeing the result  
Guy-Laurent


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

Correct - there is no function (that I could find) like setHue but then for setValue. I suspect the author assumes you'll be using one of the functions like nscale8(), FadeToBlackBy(), etc.

One thing we could change in the future is using HSV colors instead of RGB, and keep track of that in the struct 

Let me know how testing goes - no hurry on my end, just hope it does what you had in mind.
Don't forget to play with some of the numbers in the InitLed() function ... just write down what worked and what did not work. 


   
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: