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!





Arduino - All LED e...
 
Share:
Notifications
Clear all

Arduino - All LED effects in one Sketch

Page 2 / 6

 nyo
(@nyo)
New Member
Joined: 4 years ago
Posts: 3
 

Thank you Hans. Actually the pin 4 is grounded and it has a simple button attached to it. 

If I join pin4 and pin3 together and read only the pin3(and use it as an interrupt) I should be able to ignore pin4, right?


ReplyQuote
(@pierre)
Active Member
Joined: 4 years ago
Posts: 10
 

I want to make a Ghost.

Fond your effects that i what want to use.

But my problem is i am a dummy newby from 72 and use Google translater to write Englisch.

Have been trying to prepare something, but am not strong enough at this time to be able to.

Have data mentioned below that I would like to use in four colors, white, red, green and blue as this is possible.

By the numbers 1 to 6 consecutive would follow in one color, then comes number 7 in all colors. 

Here the course of the first six numbers run into the second color and number 7 again, until all 4 colors are in that cycle.

This cycle will then normally restart automatically.

The second problem, with each number is also a time indicated to the effect.

Wat i whant tu use are: ± Time

1) Theatre Chase 15 sec.

2) Fade In and Fade Out: Your own Color(s) 10 sec.

3) Strobe 15 sec.

4) Color Wipe 20 sec.

5) Cylon (Larson Scanner) 10 sec.

6) Running Lights 15 sec

7) Fade In and Fade Out: Your own Color(s) 15 sec. any time the 4 colors (end cyclus)

Can you please help me out of my suffering. Pierre


ReplyQuote
(@pierre)
Active Member
Joined: 4 years ago
Posts: 10
 

The strips are about 2 meter 20 centimeter.

#include "FastLED.h"

#define NUM_LEDS 130 à 132 (only sur wen i put the leds in)60/m.

CRGB leds[NUM_LEDS];

#define PIN 6

// 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'

void loop() { 

// RGBLoop();

// theaterChase(0xff,0,0,50);

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

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

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

   // Slower:

   // Strobe(0xff, 0x77, 0x00, 10, 100, 1000);

   // Fast:

   // Strobe(0xff, 0xff, 0xff, 10, 50, 1000);

// colorWipe(0x00,0x00,0x00, 50);

   // CylonBounce(0xff, 0, 0, 4, 10, 50);

   // RunningLights(0xff,0,0, 50); // red

   // RunningLights(0xff,0xff,0xff, 50); // white

   // RunningLights(0,0,0xff, 50); // blue

   // RunningLights(0xff,0xff,0x00, 50);

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

}

void RGBLoop(){

  for(int j = 0; j < 3; j++ ) { 

    // Fade IN

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

      switch(j) { 

        case 0: setAll(k,0,0); break;

        case 1: setAll(0,k,0); break;

        case 2: setAll(0,0,k); break;

      }

      showStrip();

      delay(3);

    }

    // Fade OUT

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

      switch(j) { 

        case 0: setAll(k,0,0); break;

        case 1: setAll(0,k,0); break;

        case 2: setAll(0,0,k); break;

      }

      showStrip();

      delay(3);

    }

  }

}

void theaterChase(byte red, byte green, byte blue, int SpeedDelay) {

  for (int j=0; j<10; j++) { //do 10 cycles of chasing

    for (int q=0; q < 3; q++) {

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

        setPixel(i+q, red, green, blue); //turn every third pixel on

      }

      showStrip();

         delay(SpeedDelay);

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

        setPixel(i+q, 0,0,0); //turn every third pixel off

      }

    }

  }

}

void FadeInOut{

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

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

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

}

void Strobe(byte red, byte green, byte blue, int StrobeCount, int FlashDelay, int EndPause){

  for(int j = 0; j < StrobeCount; j++) {

    setAll(red,green,blue);

    showStrip();

    delay(FlashDelay);

    setAll(0,0,0);

    showStrip();

    delay(FlashDelay);

  }

 

 delay(EndPause);

}

void colorWipe(byte red, byte green, byte blue, int SpeedDelay) {

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

      setPixel(i, red, green, blue);

      showStrip();

      delay(SpeedDelay);

  }

}

void CylonBounce(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay){

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

    setAll(0,0,0);

    setPixel(i, red/10, green/10, blue/10);

    for(int j = 1; j <= EyeSize; j++) {

      setPixel(i+j, red, green, blue); 

    }

    setPixel(i+EyeSize+1, red/10, green/10, blue/10);

    showStrip();

    delay(SpeedDelay);

  }

  delay(ReturnDelay);

  for(int i = NUM_LEDS-EyeSize-2; i > 0; i--) {

    setAll(0,0,0);

    setPixel(i, red/10, green/10, blue/10);

    for(int j = 1; j <= EyeSize; j++) {

      setPixel(i+j, red, green, blue); 

    }

    setPixel(i+EyeSize+1, red/10, green/10, blue/10);

    showStrip();

    delay(SpeedDelay);

  }

    delay(ReturnDelay);

}

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

  }

}

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
(@wreckweim)
New Member
Joined: 4 years ago
Posts: 2
 

I am interested in something similar.  The difference that I am looking for is the ability to control the different patterns.  Here is some more information. I am looking for some input or direction to links that could
help me out. I have a wearable light
project. I am using a Teensy 3.2 and
Bluetooth to send commands from my Android phone. The lights I am using are WS2812B. I am currently using the Adafruit_Neopixel
Arduino library but want to change to FastLED. I understand that FastLED is faster and more capable. I currently have four light patterns and want
to add more. The interface I have from
my phone to the Teensy was made using App Inventor. Basically I press a button on my phone that
sends a signal stating which pattern to run. 

I am using code from Adafruit that works with multi-tasking. (reference https://learn.adafruit.com/multi-tasking-the-arduino-part-3/overview?view=all )
This code is useful in that I can “interrupt” code mid run and have minimal
lag.
So, the help I am looking for is how can I add multiple
patterns / sketches in to one sketch and control it from my phone using FastLED
and not have any lag from changing from one pattern to the next?
I have
searched for FastLED and multiple sketches in one but have not been successful
yet.
I want the multi-tasking abilities
and not have to deal with the issues the multi-task article describes regarding
interrupts and having to wait for the cycle to complete before the command is
recognized and implemented.
Thanks

ReplyQuote
(@pierre)
Active Member
Joined: 4 years ago
Posts: 10
 

Is it possible to make a conbinatie with FastLED. h & Adafruit_NeoPixel. h.

If so, how is that accomplish in the formula at setup (): void {?

#include "FastLED.h"

include <Adafruit_NeoPixel.h>

#define NUM_LEDS 132 

CRGB leds[NUM_LEDS];

#define PIN 6 

void setup() ???


ReplyQuote



 Hans
(@hans)
Noble Member Admin
Joined: 8 years ago
Posts: 1767
Topic starter  

Hi Wreckweim and Pierre ...

Replacing AdaFruit with FastLED is not very difficult. You'll just have to make sure you include the correct .h file, and properly initialize the LED strip;

For example (FastLED):

#include "FastLED.h"
#define NUM_LEDS 60 
CRGB leds[NUM_LEDS];
#define PIN 6 
void setup()
{
  FastLED.addLeds<WS2811, PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
}

versus AdaFruit:

#include <Adafruit_NeoPixel.h>
#define PIN 6
#define NUM_LEDS 60
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
}

Now the next step, as can be seen in the explanation and code here you'll need to "translate" the AdaFruit statements to FastLED statements. They both have quite a few statements that are comparable, just written slightly different.

For example:

AdaFruit/NeoPixel: 

strip.show();

FasteLED: 

FastLED.show();

AdaFruit/NeoPixel: 

strip.setPixelColor(Pixel, strip.Color(red, green, blue));

FastLED:

   leds[Pixel].r = red;
   leds[Pixel].g = green;
   leds[Pixel].b = blue;

That's why I created this tiny "framework" in that article, so I can make the calls all the same by using my own functions, which adapt to whichever library is being used.

Now, for using interrupts, this might be a litle trickier, but I have to admit that I have never played with those (it's on my "to do" list though hahah).


ReplyQuote
(@pierre)
Active Member
Joined: 4 years ago
Posts: 10
 

Thanks Hans for the explanation.

Pierre


ReplyQuote
(@wreckweim)
New Member
Joined: 4 years ago
Posts: 2
 

Thanks Pierre


ReplyQuote
(@pierre)
Active Member
Joined: 4 years ago
Posts: 10
 

I have taken your Striptest and Striptest-FastLED.

Striptekst is OK

Striptest-FastLED go wrong, sie attachment


ReplyQuote
(@pierre)
Active Member
Joined: 4 years ago
Posts: 10
 

Maby this one


ReplyQuote



(@pierre)
Active Member
Joined: 4 years ago
Posts: 10
 

Got the error found.

Apparently piece of too short by some reason.

When I was there FastLED. addLeds < WS2811, PIN, GRB > (leds, NUM_LEDS) and it must have been FastLED. addLeds < WS2811, PIN, GRB > (leds, NUM_LEDS). setCorrection (TypicalLEDStrip);


ReplyQuote
(@pierre)
Active Member
Joined: 4 years ago
Posts: 10
 

By FadeIn-FadeOut wy have the possibility to take RGB or RWB. 

Is it possible to have RGB+W or RWB+R and how to do this?


ReplyQuote
(@juanchu23)
New Member
Joined: 3 years ago
Posts: 1
 

Hello!

awesome  and very usefull post.

I have a question: how can make a effect running in a delimited time (ej. 10 seconds)?

For example: fire 10 seconds, bouncingballs 15, fader 12;   To make a routine.  (like Pierre said in his post, but i cant understand at all)

I´m juggler and this its for a led juggling clubs, 

THANKS

Juan,


ReplyQuote
 Hans
(@hans)
Noble Member Admin
Joined: 8 years ago
Posts: 1767
Topic starter  

Hi Juanchu23,

Awesome! (being a juggler - I tried a few times but I'm just horrible at it hahah)

As for your question: you may have to resort to the use of Timer Interrupts. I have not done anything with these yet, but maybe the links below will get you started. Basically what you want is to abort a certain effect based on a time you have set, so the next effect can start.

  1. Arduino website - Timer
  2. Robotshop Arduino 101
  3. Instructables.com Arduino Timer Interrupts
It most certainly isn't the easiest topic ... but with some reading and playing around with timers, you may get it done.
Hope this helps ...


ReplyQuote
(@pierre)
Active Member
Joined: 4 years ago
Posts: 10
 

Hello Hans!

Am already a little further but please count me even to the beginners,  some things are a little more difficult for someone of 74 years.. 

I'm still using AllLEDEffets-NeoPixel, so this without push button,  so previous version. 

Select all that I want to use by removing the "//" and copier this that I want to use longer. 

The code are apart on page https://www.tweaking4all.com/hardware/arduino/adruino-led-strip-effects/ 

But at two effects I have a problem: 

1)  I change in BouncingBalls (0xff, 0xff, 0xff, 3); rest of the code as on no. 22 on page the aforementioned page, once this picture he keeps this effect student and does not go back to the first or next effect. 

2) NewKITT (0xff, 0xff, 0xff, 8, 10, 50); code is on no. 11 of the aforementioned page. If I use at the place where it stands, everything stops for 15 seconds and then runs normally by.


ReplyQuote



Page 2 / 6

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: