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!



Trying to setup fad...
 
Share:
Notifications
Clear all

[Solved] Trying to setup fadein/out to one pin, twinkle to another

5 Posts
2 Users
0 Reactions
1,789 Views
 biqa
(@biqa)
Active Member
Joined: 9 years ago
Posts: 3
Topic starter  

Hello Hans,

I can't tell you how happy I was to find your page! I'm new to NeoPixels/Arduino and am building a little project where I want to use your fadein/out script on one led strip and the twinkle script to appear on another strip. I was thinking two separate pins (6,7) because I wanted the effects to work at the same time. Since your code is so well written, even a n00b like me was even able to figure it out! :) However even though I have them working separately I don't know how to combine them so they both are going at the same time. Any assistance is greatly appreciated! I've posted the code below for each one that it's successfully working on it's own, just needing assistance on making them both work at the same time. Thanks in advance for any help! :)

-------------------------------------------FadeIn/Out Example-------------------------------------------------------

#include <Adafruit_NeoPixel.h>

#define PIN 7

#define NUM_LEDS 8

// 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.show(); // Initialize all pixels to 'off'

}

// REPLACE FROM HERE

void loop() { 

  FadeInOut(0xff, 0x00, 0x00); // red

  FadeInOut(0xff, 0xff, 0xff); // white 

  FadeInOut(0x00, 0xd4, 0x15); // green

  FadeInOut(0x00, 0x00, 0xff); // blue

}

void FadeInOut(byte red, byte green, byte blue){

  float r, g, b;   

  for(int k = 0; k < 256; k=k+1) { 

    r = (k/256.0)*red;

    g = (k/256.0)*green;

    b = (k/256.0)*blue;

    setAll(r,g,b);

    showStrip();

  }   

  for(int k = 255; k >= 0; k=k-2) {

    r = (k/256.0)*red;

    g = (k/256.0)*green;

    b = (k/256.0)*blue;

    setAll(r,g,b);

    showStrip();

  }

}

// ---> here we define the effect function <---

// 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();

}

------------------------------------------Twinkle Example ------------------------------------------------------

#include <Adafruit_NeoPixel.h>

#define PIN 6

#define NUM_LEDS 8

// 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.show(); // Initialize all pixels to 'off'

}

// REPLACE FROM HERE

void loop() {

  TwinkleRandom(4, 25, false);

}

void TwinkleRandom(int Count, int SpeedDelay, boolean OnlyOne) {

  setAll(0,0,0);

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

     setPixel(random(NUM_LEDS),random(0,255),random(0,255),random(0,255));

     showStrip();

     delay(SpeedDelay);

     if(OnlyOne) { 

       setAll(0,0,0); 

     }

   }

  delay(SpeedDelay);

}

// ---> here we define the effect function <---

// 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();

}


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2859
 

Hi Biqa,

Using two separate strands (on two individual pins) will work, but I cannot recommend it. I've seen a few cases where the effects are not as expected or the speed is just dropping too much.

Personally I would stick to just one 1 and divide the strand in 2 sections. You can cut the strand and reconnect the 2 pins with 3 longer wires, so they can be placed as if they were individual strands.

To address the LEDs, we now have to change a few things.
Let's assume the first strand is 10 leds, then LED 1 - 10, would be strand1.
Ditto for strand 2, so strand2 would be LED 11-20.

Where things get complicated is that both effects need to be merged. So when a step is done for one effect, a step for the other effect should be done as well. This makes it complicated to follow ... however it's needed, since the Arduino doesn't handle multi-tasking ...


   
ReplyQuote
 biqa
(@biqa)
Active Member
Joined: 9 years ago
Posts: 3
Topic starter  

Thanks for the quick reply Hans! I did read in a past post where you mentioned handling items under 1 pin. I wouldn't even know where to start with merging the code so that it sends the twinkling lights to 1-8  and the fade in/out to 9-16. I guess I'll stick to one effect and send it to both lights. Thanks again for the quick reply!


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2859
 

Since clone Arduino's can be pretty cheap, maybe use a second Arduino for the second effect?

Trying to combine the effects is possible, but it will take some time to figure out what works best. Unfortunately, I'm traveling so I do not have my gear with me to do some testing ... 


   
ReplyQuote
 biqa
(@biqa)
Active Member
Joined: 9 years ago
Posts: 3
Topic starter  

Oh no worries at all! I'll try some experimenting at this end. :) Yeah the price of a second one isn't the issue, it's the power. See the project I'm using it for is a small pinball table. I'm already using two cards, one to drive the arcade controls, the other to drive the lights in the body of the cabinet and was hoping the same card would drive the lights in the marquee. So if I had to separate the lights into being driven by 2 cards, the pinball table would have a total of three cards. Not a big deal but I'm not sure if I could successfully power all three off of the same power (it's a very small table with minimal space for different power supplies). If I can't figure out how to combine the codes then three cards it will be and I'll figure out how to power all three. :) Thanks again!


   
ReplyQuote
Share: