Pixels Animation with sensor - UNO/SENSE/DOPPLER

Hi, I'm trying to code such event:

  • UNO/SENSE runs/animates neopixels o higher brightness when it recognizes motion for 5 seconds
  • when motion stops for 10 seconds, UNO/SENSE fades pixels (fade animation) and stays there on lower brightness without running fade animation (loop) effect until it recognizes movement for 5 seconds again and then it smoothly lights up to higher value.

CODE:


#include <Adafruit_NeoPixel.h>

#define PINPIXEL 5
#define NUMPIXELS 8

int DOPPLER = 2;    
int sensorval = 0;  
int isr_flag = 0;

Adafruit_NeoPixel pixels(NUMPIXELS, PINPIXEL, NEO_GRB + NEO_KHZ800);



void setup() {

  pinMode (DOPPLER, INPUT); 
  attachInterrupt(0, interruptRoutine, CHANGE);
  //attachInterrupt(1, interruptRoutine, FALLING);
  pixels.begin();
  pixels.show();
}

void loop() {


  if ( isr_flag == 1 ) {
    
    sensorval = digitalRead(DOPPLER); 
    detachInterrupt(0);
    stillMore();
    isr_flag = 0;
    attachInterrupt(0, interruptRoutine, LOW);
  }

  stillLess();

}

void stillLess() {
  uint16_t i, j;

  for (j = 96; j > 60; j--) {
    for (i = 0; i < pixels.numPixels(); i++) {
      pixels.setPixelColor(i, j, j, j);
    }

    pixels.show();
    //delay(30);

  }
}

void stillMore() {
  uint16_t i, j;

  for (j = 60; j < 96; j++) {
    for (i = 0; i < pixels.numPixels(); i++) {
      pixels.setPixelColor(i, j, j, j);

    }
    pixels.show();
    delay(3000);
  }

}

void interruptRoutine() {
  isr_flag = 1;
}

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination