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 most likely no translated for the post!





Blinking Halloween ...
 
Share:
Notifications
Clear all

Blinking Halloween Eyes with different colors  

Page 1 / 3
  RSS

 Hans
(@hans)
Prominent Member Admin
Joined: 7 years ago
Posts: 870
January 16, 2017 2:33 AM  

Continuation of this comment concerning using different colors in the Blinking Halloween Eyes effect.


ReplyQuote
(@bravozulu)
Active Member
Joined: 4 years ago
Posts: 15
January 17, 2017 6:39 AM  

Hi Hans,

First the title "Halloween Eyes" does not really fit my project. It would rather be the "Eye of the Cyclops"
(I use for now only one LED - Not one LED Strip).
But in the end and to make it more romantic it is about "Soft luminous variations" (Brooch, headband, neckband, etc.) for pretty girls   (See image of a brooch/pin - next Post - Due to problem of Forum).

Equipment used: ATtiny85 + 1x LED RGB "WS2812B".
The base comes from: "Blinking Halloween Eyes".
This is the random side that interested me - but I guess this script can be much simplified.
Currently I come back with another color with function: [setAll(0x94, 0x00, 0xD3);].

I would just edit this script to: (write another)
a) Use 1 LED (eg 2-3 LEDs in random sequence);
b) Use 2-3 colors (possibly 3rd colors as black) - See interaction with: [setAll(0,0,0);];
c) Get a Fade-In & Fade-Out effect - Between each color;
d) All with random functions !

My current script: (based on "NeoPixel" Adafruit)

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif
#define PIN 4
#define NUM_LEDS 1
// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
  strip.begin();
  strip.setBrightness(64); // Decrease the brightness of the LEDs.
  strip.show(); // Initialize all pixels to 'off'
}
// *** REPLACE FROM HERE ***
void loop() {
  // Fixed:
  // HalloweenEyes(0xff, 0x00, 0x00, 1,4, true, 10, 80, 3000);
  // or Random:
  HalloweenEyes(0x94, 0x00, 0xD3, // DarkViolet.
                1, 1,
                true, random(20,120), random(150,300),
                random(5000, 15000));
}
void HalloweenEyes(byte red, byte green, byte blue,
                   int EyeWidth, int EyeSpace,
                   boolean Fade, int Steps, int FadeDelay,
                   int EndPause){
  randomSeed(analogRead(0));
 
  int i;
  int StartPoint = random( 0, NUM_LEDS - (2*EyeWidth) - EyeSpace );
  int Start2ndEye = StartPoint + EyeWidth + EyeSpace;
 
  for(i = 0; i < EyeWidth; i++) {
    setPixel(StartPoint + i, red, green, blue);
    setPixel(Start2ndEye + i, red, green, blue);
  }
 
  showStrip();
 
  if(Fade==true) {
    float r, g, b;
 
    for(int j = Steps; j >= 0; j--) {
      r = j*(red/Steps);
      g = j*(green/Steps);
      b = j*(blue/Steps);
     
      for(i = 0; i < EyeWidth; i++) {
        setPixel(StartPoint + i, r, g, b);
        setPixel(Start2ndEye + i, r, g, b);
      }
     
      showStrip();
      delay(FadeDelay);
    }
  }
 
  setAll(0x94, 0x00, 0xD3); // Set all DarkViolet.
 
  delay(EndPause);
}
// *** REPLACE TO HERE ***
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 = 0; i < NUM_LEDS; i++ ) {
    setPixel(i, red, green, blue);
  }
  showStrip();
}

I hope you can help me.
I am waiting for your comments. Thank you !
Guy-Laurent
PS: And do not forget to turn On the coffee maker  


ReplyQuote
(@bravozulu)
Active Member
Joined: 4 years ago
Posts: 15
January 17, 2017 7:08 AM  

(* Image of a brooch/pin) [86kb]

DSC_0017_10.jpg


ReplyQuote
 Hans
(@hans)
Prominent Member Admin
Joined: 7 years ago
Posts: 870
January 18, 2017 3:49 AM  

Testing an upload ... 2Mb


ReplyQuote
 Anonymous
Joined: 51 years ago
Posts: 0
January 18, 2017 3:52 AM  

Second test ... 2Mb as a regular user ...


ReplyQuote



 Hans
(@hans)
Prominent Member Admin
Joined: 7 years ago
Posts: 870
January 18, 2017 3:55 AM  

Both seem to work 
I'm starting to get tired of the forum issues ... better do a real effort to find a replacement that blends in well with WordPress.


ReplyQuote
 Hans
(@hans)
Prominent Member Admin
Joined: 7 years ago
Posts: 870
January 18, 2017 4:00 AM  

OK, back to what we were really talking about ... pretty girls  .... oh no wait ... LEDs and Arduino 

The broche looks really nice! 

So, I was thinking, instead of tweaking the Halloween Eyes, maybe we should create something new, more geared towards what you have in mind.

So we have 2 to 3 LEDs, and you want to have them (one at a time?) to randomly fade in/out one of the 2 or 3 predefined colors.
Did I understand that right? (man you always seem to catch me in the morning hahah)
Or do all LEDs fade in/out?
The time between LEDs lighting up is random as well?
And the fade in/out speed as well?


ReplyQuote
(@bravozulu)
Active Member
Joined: 4 years ago
Posts: 15
January 18, 2017 6:28 AM  

Another object - Headband Style year '20. [Test download - 2.7MB]


ReplyQuote
(@bravozulu)
Active Member
Joined: 4 years ago
Posts: 15
January 18, 2017 6:45 AM  

Hi Hans !

Yes, it would certainly be easier to start from scratch with a new script. Can be with the base of: "Fade In and Fade Out Your own Color (s)" by adding the random functions. (Read my first post).

My current projects works with only One LED. But I would like to make a brooch... variant with 2 or 3 LEDs.

That's why it would be nice to have the option to work with 1, 2 or 3 LEDs. (To infinity with the principle of a setup for each LED - If available/applicable in programming)  

Yes, I want to have them (all) to randomly fade in/out one of the 2 or 3 predefined colors.
So it would be ideal to have a configuration in the form:
- LED_1: colors, fade in/out speed, lighting up/down - all random functions;
- LED_2: same;
- Etc.

All LEDs fade in/out = Yes
The time between LEDs lighting up/down is random as well = Yes
And the fade in/out speed as well = Yes

Concerning colors: I do not know if it is possible to go for a random color in the predefined list. (Color_1, Color_2, etc.).

Is that simple or complicated ?

My English is better at reading than at writing. I check the translation with Google, since my language is French. (French speaking part of Switzerland). So if it's not clear ask me.

Sorry to disrupt you on waking  
It's jet lag (WI, USA < CH = -7:00) - I am not very early - rather nocturnal.

Thank you for considering my request  
Guy-Laurent


ReplyQuote
(@bravozulu)
Active Member
Joined: 4 years ago
Posts: 15
January 18, 2017 7:36 AM  

Another brooch - in use (hair), but before modification (Diamond with LED)  [450KB]


ReplyQuote



(@bravozulu)
Active Member
Joined: 4 years ago
Posts: 15
January 28, 2017 6:12 PM  

Hello Hans,
I hope you are well.

Do you have a bit of time and a track to give me for this script ?

I would be delighted  
Thank you !
Guy-Laurent

Photo: and now I realized my first flexible PCB.


ReplyQuote
 Hans
(@hans)
Prominent Member Admin
Joined: 7 years ago
Posts: 870
January 29, 2017 3:40 PM  

Hi Guy-Laurent!

Sorry for the quiet time - it's been quite busy the past days. The everlasting conflict between work and hobby I guess ...

OK, so I'd first need you to mail me that nice lady ... for test purposes 
Just kidding! 

Well, my French is ... pretty bad haha ... I have to stick with English, Dutch or German. Since others might read this as well, better stick to English. Dont' worry about it being 100% correct or not.

So, recap;

You want 1-3 LEDs that fade-in, fade-out in one of the predefined colors - they all fade equally?
Fade-in and fade-out moment is random.
Fade-in and fade-out speed is random (from one effect: are fade-in and fade-out equally fast?).
Pause in between is random.

OK, predefining colors we could do best with an array - since each color has 3 values (red, green, blue) we need X rows with 4 values:

#define NumberOfColors 4
byte MyColors[NumberOfColors][3] == { { 0xFF, 0x00, 0x00 }, // red
                          { 0x00, 0xFF, 0x00 }, // green { 0x00, 0x00, 0xFF }, // blue { 0xFF, 0xFF, 0xFF } }; // white

Setting a LED color then becomes something like this:

setPixel(Pixel, MyColors[0][0], MyColors[0][1], MyColors[0][2]);  // first color (red)

Remember that arrays start counting with zero and not with 1. So the first color has the index 0.

Now we can use the random function to generate a number between zero and 4 (not including 4).

int RandomColor;
...
RandomColor = random(0,3); // you'll need to play a little with this
setPixel(Pixel, MyColors[RandomColor][0], MyColors[RandomColor][1], MyColors[RandomColor][2]);
...

I have to get back to you for more ... duty calls on this end argh ...


ReplyQuote
(@bravozulu)
Active Member
Joined: 4 years ago
Posts: 15
January 29, 2017 7:57 PM  

Hi Hans !

First thank you very much for taking the time to write me this first part.    (Of course I wait for the continuation).

My German is even worse than my English.  
For testing purposes, sorry I think I'll keep my model (preferred) just for me. HiHiHi  

Thanks also for the links. I had not paid attention to these Arduino courses. (Still boring when you do not have a concrete project).

Recapitulation:
- I want 1-3 LEDs that fade-in, fade-out in one of the predefined colors – they all fade equally ? No
- Fade-in and fade-out moment is random.
- Fade-in and fade-out speed is random (from one effect: are fade-in and fade-out equally fast ?). No
- Pause in between is random.

Memo: my first project uses only One LED (RGB "WS2812B"). The following could use 2-3 LEDs.
I would like the whole thing to be random - it will be seen in practice if it is graceful.
(I want slow, almost imperceptible effects. Unlike a bling-bling effect).

I am pleased to be able to implement this  
See you !
Guy-Laurent

PS: Do you have a PayPal address ?


ReplyQuote
(@bravozulu)
Active Member
Joined: 4 years ago
Posts: 15
February 10, 2017 1:19 AM  

Hello Hans,
How are you ?

I come back to you because I would be happy to get the continuation of your first part of the script. (January 29).
So I could test these functions and familiarize myself with programming. 

Thank you in advance for your contribution  
Guy-Laurent

PS: Do you have a PayPal address ?


ReplyQuote
 Hans
(@hans)
Prominent Member Admin
Joined: 7 years ago
Posts: 870
February 10, 2017 9:07 AM  

Hi Guy-Laurant,

I'm still alive hahah -- sorry this week has been crazy at work. By the time I get home, I'm ready for crashing on the couch ... 
I think I'm getting the idea of your 1 and later 1-3 LEDs ... I have to think about the best way to accommodate the fading in/out, potentially for 1-3 LEDs (1 LED is easier). 

Yes, I do have PayPal, but let's first get your effect to work ... otherwise I'd feel guilty 


ReplyQuote



Page 1 / 3
Share: