我正在研究一些Neopixels和Arduino(teensy 3.2)并且两者都相当新。
我有一条LED,一个PIR和一个LDR,以区分白天和夜晚并关闭LED。我想要达到的目的是在检测到PIR运动时使LEDS达到全亮度,但仅在LDR为特定值时才会亮。
问题在于PIR超越了LDR并且无论白天或晚上都达到了全亮度,我怎样才能使LDR的模拟引脚胜过PIR?
我的代码在这里:
#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)
}
}