hi guys, i'm not a programmer i'm new to coding.
i'm installing some 2812b rgb strip to my stairway.
my code seems to work fine, except for one thing.
when i activate the pir at the bottom of the stairs...
it activates the leds. (happy days)
but then it loops and loops and loops.
how do i stop that loop until the next interupt occurs?
#include Adafruit_NeoPixel.h
Adafruit_NeoPixel strip = Adafruit_NeoPixel(81, 6, NEO_GRB + NEO_KHZ800);
int motionPin = 10; PIR Input pin 8, UPSTAIRS
int motionPin2 = 11; PIR 2 Input pin 7, DOWNSTAIRS
int senseMotion = 0; variable to hold current state of motion detector
int senseMotion2 = 0; 2nd variable for 2nd sensor
void setup() {
pinMode(motionPin, INPUT); PIRs declared as inputs
pinMode(motionPin2, INPUT);
strip.begin();
strip.show(); Initialize all pixels to 'off'
}
void loop() {
senseMotion = digitalRead (motionPin); set variables equal to what our sensors are reading (on or off)
senseMotion2 = digitalRead (motionPin2);
if (senseMotion == HIGH senseMotion2 == HIGH) { Testing both sensors at same time, if high, go to apropriate line.
if (senseMotion2 == HIGH) { If Upstairs motion sensor is triggered...
colorWipe (strip.Color (0, 0, 150), 50); Whiteblue color sweep going up stairs (Towards the arrow on the strip)
strip.show(); This being enabled or not, doesnt seem to make a difference. NVM it looks like its more responsive when trying to activate the PIRs one after another
delay (6000); Wait so someone can get to the bottom or top of stairs, will remove this when 2nd sensor is implemented with an interrupt
colorWipe (strip.Color (0, 0, 0), 50); This is needed for turn everything off, clear all pixels. More efficient with this here
strip.show();
}
if (senseMotion == HIGH) { If motion sensor 2 (Downstairs) if high go to next line
colorWipe2 (strip.Color(0, 0, 150), 50);
strip.show();
delay(6000);
colorWipe (strip.Color (0, 0, 0), 50);
strip.show();
}
}
else { no motion = no lights or animate til off
digitalWrite (motionPin, LOW); turning motion pins low, doesnt seem to make a difference either.
digitalWrite (motionPin2, LOW);
colorWipe (strip.Color(0, 0, 0), 50);
strip.show();
}
}
Function time!
void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; istrip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
strip.setPixelColor (0,0,0),50);
delay(wait);
}
}