I'm working on Some Neopixels and Arduino (teensy 3.2) and fairly new to both.
I have a strip of the LEDs, one PIR, and an LDR to differentiate between day and night and turn off the LEDs. What I'm trying to achieve is to have the LEDS go full brightness when PIR motion is detected but only when the LDR is a certain value.
The issue is that the PIR is over-riding the LDR and going full brightness day or night, how can I make the Analog Pin of the LDR trump the PIR?
My code is here:
#include <Adafruit_NeoPixel.h>
#define PIN 5 // P0
int POTPIN =A1; //P5
int LDRPIN = A2; //P2
int PIRPIN = 1; //P1
int sensorValue = 0; //potpin sensor value
int colorValue = 0;
Adafruit_NeoPixel strip = Adafruit_NeoPixel(50, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
pinMode(PIRPIN, INPUT); // PIR SENSOR INPUT
strip.begin();
strip.setBrightness(255); //overall led brightness setup (0-255)
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
if (analogRead (LDRPIN)< 500) // LDR light sensor, need to adjust "300"
{
colorWipe(strip.Color(0, 0, 0), 50); // BLACK
}
if (digitalRead(PIRPIN) == HIGH)
{
analogRead (LDRPIN);
if (analogRead (LDRPIN)> 300)
colorWipe(strip.Color(0, 0, 0), 50);
else {
colorWipe(strip.Color(255,255, 88), 50);
delay(8000);
}
}
}
void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
}
uint32_t Wheel(byte WheelPos) {
if(WheelPos < 85) {
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
} else if(WheelPos < 170) {
WheelPos -= 85;
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else {
WheelPos -= 170;
return strip.Color(170,170,120); //white from potentiometer selection
(HALF BRIGHTNESS)
}
}