I want Ala sequence to complete animation first when HC-SR501 PIR goes LOW =OK

I am running Ala-sequence BUBBLES code and I have modified the colours and it works fine, but now I added a PIR sensor (HC-SR501) .
The 60 led WS2812 strip and Arduino Uno run on 5V 4A, this I also use to power the sensor.

When the timer of the sensor goes low, the animation stops abrupt. And sometimes to leave a few LED's on. I use the animation to simulate rain... (set up without PIR, so constant rain on Relign Paneel Herfst 1 on Vimeo)

I would like the animation to run till the end and then stop when the PIR goes LOW. This is my -cut&pasted- code

#include <AlaLedRgb.h>

#define NUM_LEDS 60
#define PIN 6
#define COLOR R,G,B,

const byte pirPin = 3;


AlaLedRgb rgbStrip;

// custom palette :         black     white     black     red       green     blue
AlaColor mycolors_[6] = { 0x000000, 0xFFFFFF, 0x000000, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF };
AlaPalette mycolors = { 6, mycolors_ };

AlaSeq seq[] = {
  { ALA_OFF,            1000, 1, alaPalNull },
  { ALA_BUBBLES,        100, 1800, mycolors },
  { ALA_OFF,            1000, 1, alaPalNull },
  { ALA_BUBBLES,        100, 2000, mycolors },
  { ALA_ENDSEQ }
};

void setup() {

  pinMode(6, OUTPUT);
  (60);
  delay(50);

  rgbStrip. initWS2812 (60, 6);
  
  rgbStrip. setBrightness (0x332244);

  rgbStrip. setAnimation(seq);
}


void loop()
{
  if(digitalRead(pirPin) == HIGH) // if there is motion
  {

 rgbStrip. runAnimation();

int (num1);
int animation;
int currAnim;
}
  }

What is something like (60); supposed to do? Why do you have some variable declarations at the end of your if block?

No idea what ala is and how it works. Maybe post a link to where you found it.

#include <AlaLedRgb.h>

#define NUM_LEDS 60 
#define PIN 6 //"PIN"? How about calling it "LED_PIN"? You also don't actually *use* this #define, but instead put the number in... 
#define COLOR R,G,B,  //You don't use COLOR anywhere. Which is a good thing, considering that you've #defined it to something that's almost certain to not work. 

const byte pirPin = 3;


AlaLedRgb rgbStrip;

// custom palette :         black     white     black     red       green     blue
AlaColor mycolors_[6] = { 0x000000, 0xFFFFFF, 0x000000, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF };
AlaPalette mycolors = { 6, mycolors_ };

AlaSeq seq[] = {
  { ALA_OFF,            1000, 1, alaPalNull },
  { ALA_BUBBLES,        100, 1800, mycolors },
  { ALA_OFF,            1000, 1, alaPalNull },
  { ALA_BUBBLES,        100, 2000, mycolors },
  { ALA_ENDSEQ }
};

void setup() {

  pinMode(6, OUTPUT); //Not necessary - but good practice. 
  (60); //this line does nothing. 
  delay(50); //this line is unnecessary

  rgbStrip. initWS2812 (60, 6); //Why not use your #defines, ie, initWS2812(NUM_LEDS,PIN), or initWS2812(NUM_LEDS,LED_PIN) if you take my #define naming advice above) 
  
  rgbStrip. setBrightness (0x332244);

  rgbStrip. setAnimation(seq);
}


void loop()
{
  if(digitalRead(pirPin) == HIGH) // if there is motion
  {

 rgbStrip. runAnimation();

int (num1); // You do not use this variable anywhere! Delete this line, or use it! 
int animation; // You do not use this variable anywhere! Delete this line, or use it! 
int currAnim; // You do not use this variable anywhere! Delete this line, or use it! 
} else { //Since you want to do something, rather than nothing, if the pirPin is not HIGH, you need an else...
rgbStrip.off(); //Quick skim of AlaLedRgb.h shows a method "off()" - that sounds like what you want.... 
}
  }

General style: Use ctrl+T to automagically do the indentation for you.

Do not put a space between the object and a method call (ie, rgbStrip.runAnimation(), not rgbStrip. runAnimation() - nobody puts a space there, it looks weird.

Re: pinMode() on the WS2812 pin: The pin needs to be set as output. But under the hood, that library pulls in a renamed adafruit_neopixel library, and the constructor calls pinMode() anyway.

Okay DrAzzy. Thanks for your good remarks. like I said, this code is a compilation of cut&paste from different examples from the Ala-library. It makes my ledstrip work and that's important for me, now. The final touch would be if it would work when I add a PIR.

To add "else" in the code sounds plausible. Anyway I uploaded your suggestion and got this ERROR report: (and of course I tried my luck cutting and pasting away before sending you this reply)

Arduino: 1.8.1 (Mac OS X), Board:"Arduino/Genuino Uno"

In file included from /Users/gerrit/Documents/Arduino/Gerrit Sketches/Bubbles_Herfst2SequencePIRForum/Bubbles_Herfst2SequencePIRForum.ino:1:0:
/Users/gerrit/Documents/Arduino/libraries/ALA/src/AlaLedRgb.h: In function 'void loop()':
/Users/gerrit/Documents/Arduino/libraries/ALA/src/AlaLedRgb.h:57:10: error: 'void AlaLedRgb::off()' is private
     void off();
          ^
Bubbles_Herfst2SequencePIRForum:49: error: within this context
 (rgbStrip.off(); //Quick skim of AlaLedRgb.h shows a method "off()" - that sounds like what you want....
               ^
Bubbles_Herfst2SequencePIRForum:49: error: expected ')' before ';' token
 (rgbStrip.off(); //Quick skim of AlaLedRgb.h shows a method "off()" - that sounds like what you want....
                ^
/Users/gerrit/Documents/Arduino/Gerrit Sketches/Bubbles_Herfst2SequencePIRForum/Bubbles_Herfst2SequencePIRForum.ino: At global scope:
Bubbles_Herfst2SequencePIRForum:53: error: expected declaration before '}' token
 }
 ^
exit status 1
within this context

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

I showed my problem to my neighbour and he came up with an interesting idea: Add a "blind" sequence. This works, the (visible) sequence finishes after the PIR goes LOW, or: it stops raining! Great.

Only a New Thing happens now: It looks as if this solution eats too much data or memory. Only part of the LED's in the sequence light up.. This is spoiling the whole rain effect.

The good rain prototype (without PIR) can be seen here: Relign- what to solder on a sunny day on Vimeo

Check the whole painting (in progress, still without PIR) Relign Paneel Herfst 1 on Vimeo

The rain setup with PIR can be seen here: VID_20171221_110541 on Vimeo

you can now see how the modification has an unwanted and demoralising effect on the animation.

I again have tried different cut&paste actions, to no avail. For instance I deleted 4 of the 6 colours from the custompalette to make things simpeler for the chip. The colour didn't change but the animation is still "sick". Please have a look at the code as it is now:

#include <AlaLedRgb.h>

#define NUM_LEDS 60
#define LED_PIN = 6 


const byte pirPin = 3;


AlaLedRgb rgbStrip;

// custom palette :         black     white     black     red       green     blue
AlaColor mycolors_[6] = { 0x000000, 0xFFFFFF, 0x000000, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF };
AlaPalette mycolors = { 6, mycolors_ };

AlaSeq seq1[] = {
  { ALA_OFF,            1000, 1, alaPalNull },
  { ALA_BUBBLES,        100, 2000, mycolors },
  { ALA_ENDSEQ }
};

AlaSeq seq2[] = {
  { ALA_OFF,            1000, 1, alaPalNull },
  { ALA_ENDSEQ }
};
void setup() {
  
  pinMode(6, OUTPUT); //Not necessary - but good practice.
  pinMode(3,INPUT);
  digitalWrite(3, LOW);
  
  rgbStrip. initWS2812 (60, 6); 
 
  rgbStrip. setBrightness (0x332244);
 
}


void loop()
{
 if (digitalRead(pirPin) == HIGH) // if there is motion

  {
 rgbStrip. setAnimation(seq1);
 rgbStrip. runAnimation();

} else { 
rgbStrip. setAnimation(seq2);
rgbStrip. runAnimation();

  int (num1);
  int animation;
  int currAnim;
}
  }
else {
rgbStrip. setAnimation(seq2);
rgbStrip. runAnimation();

  int (num1);
  int animation;
  int currAnim;
}

(Why) (is) (num1) (in) (parentheses) (?)
Why are there local variables in this block at all?

Why do the if block and the else block, one of which MUST execute, both call runAnimation()?

It really seems to me that the solution is to look at the state change detection example. You want to do something while there is motion, and stop doing it when there isn't.

So, on every pass through loop(), see if the state of the PIR sensor changed. It it changed to "there is motion", set a flag indication that the LEDs should do their thing, but do NOT make them do it.

If the state changed to "there is no motion", clear the flag.

Then, if the flag is true, run the animation once.

Post a link to the AlaLedRgb library. There may be methods that perform the "sequence" once, which you should use, rather than performing the sequence over and over, which is what runAnimation() seems to be doing.

Dear Brattain

The „int” section I copied&pasted and the sequence seemed to have calmed down a bit after I did that, went a bit slower.

The „else” bit is the latest change to my code. In an attempt to make things clear to my Arduino I assumed that Animation(seq2); -which is a „blind” animation- will still have to run.

I am using the ALA library. I did cut from different examples, for instance to isolate BUBBLES from RgbStripSequence (to run only BUBBLES) and from RgbLedSequence the piece of code that enables me to adjust colors..

These are all things I have figured out myself without ever having studied C+ or any other programming besides my old dect phone. So cut&paste is my way until I have finished this project. Then I can lean back and buy a good book on the matter. I guess I have been quite lucky getting this far, and I’m sure I want to do more with these LED’s but for now I am shooting into the dark.

I cannot figure what interrupts the animation, when I add the PIR. The Pir should only switch ON and OFF and not interfere with the animation itself, right?

anyone?

The Pir should only switch ON and OFF and not interfere with the animation itself, right?

The sensor can NOT possibly interfere with the animation. It just sits there, detecting motion, and making an output HIGH or LOW. The Arduino reads that, and does something.

What affect what the action performed by the Arduino has on the animation is a mystery because you haven't posted a link the library that you clearly do not understand. No one can help you until you do that.

I am using the ALA (Arduino Light Animation) library

and

I basically used the

"RgbStripSequence - Animation sequence for an (adressable) RGB LED strip."

I deleted all unneeded animations an then cut the piece of code for custom color palette from

"RgbLedSequence - Animation sequence for one RGB LED. The example also shows how to create and use a custom color palette."

Even though there's some rattle and hum in the code, it passed verification and worked. That means it ran the animation and in a nice rainy, blue-grey colour too.

And then I thought adding a PIR would be nice, since it never rains ALL day.

And there the problem occured that the animation froze on the moment the PIR went LOW, leaving some LED's ON. To deal with that, my neighbour came up with the idea of adding a black animation, to run when PIR goes LOW. That basically works too.

It's just that the animation doesn't come out like it used and should. As I showed in the Vimeo video's in my post from dec 22. I happily stumble along and get lucky by trial and error, but this one I cannot fathom -let alone crack.

I wish you merry days and a great 2018

SOLVED!! I worked it out. Another lucky cut & (NOT) paste, I am afraid. A bit of logic though, in retrospect.
Sequence 1 started with an ALA_OFF command. I cut that away and Hey, Presto!

Code in working order:

#include <AlaLedRgb.h>

#define NUM_LEDS 60
#define LED_PIN 6 


const byte pirPin = 3;


AlaLedRgb rgbStrip;

// custom palette :         black     white     black     red       green     blue
AlaColor mycolors_[6] = { 0x000000, 0xFFFFFF, 0x000000, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF };
AlaPalette mycolors = { 6, mycolors_ };

AlaSeq seq1[] = {
  { ALA_BUBBLES,        100, 2000, mycolors },
  { ALA_ENDSEQ }
};

AlaSeq seq2[] = {
  { ALA_OFF,            1000, 1, alaPalNull },
  { ALA_ENDSEQ }
};
void setup() {
  
  pinMode(6, OUTPUT); //Not necessary - but good practice.
  pinMode(3,INPUT);
  digitalWrite(3, LOW);
  
  rgbStrip. initWS2812 (60,6); 
 
  rgbStrip. setBrightness (0x332244);
 
}


void loop()
{
 if(digitalRead(pirPin) == HIGH) // if there is motion

  {
 rgbStrip. setAnimation(seq1);
 rgbStrip. runAnimation();

} else 
{ 
rgbStrip. setAnimation(seq2);
rgbStrip. runAnimation();

  int (num1);
  int animation;
  int currAnim;
}
  }