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;
}