如何调试Arduino中意外的模拟输出?
我正在研究Neopixels和Arduino(teensy 3.2),对这两款产品都很陌生 我有一个LED条,一个PIR和一个LDR来区分白天和黑夜,并关闭LED。我试图实现的是,当检测到PIR运动时,使LED变为全亮度,但仅当LDR为某个值时 问题是,PIR超越了LDR,白天或晚上都是全亮度的,我怎样才能使LDR的模拟引脚胜过PIR 我的代码在这里:如何调试Arduino中意外的模拟输出?,arduino,led,motion,teensy,Arduino,Led,Motion,Teensy,我正在研究Neopixels和Arduino(teensy 3.2),对这两款产品都很陌生 我有一个LED条,一个PIR和一个LDR来区分白天和黑夜,并关闭LED。我试图实现的是,当检测到PIR运动时,使LED变为全亮度,但仅当LDR为某个值时 问题是,PIR超越了LDR,白天或晚上都是全亮度的,我怎样才能使LDR的模拟引脚胜过PIR 我的代码在这里: #include <Adafruit_NeoPixel.h> #define PIN 5 // P0 int POTPIN =A
#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)
}
}
#包括
#定义引脚5//P0
int-POTPIN=A1//P5
int-LDRPIN=A2//P2
int-PIRPIN=1//P1
int-sensorValue=0//potpin传感器值
int colorValue=0;
Adafruit_Neopix条=Adafruit_Neopix条(50针,NEO_GRB+NEO_KHZ800);
无效设置(){
pinMode(PIRPIN,输入);//PIR传感器输入
strip.begin();
strip.setBrightness(255);//整体led亮度设置(0-255)
strip.show();//将所有像素初始化为“关闭”
}
void循环(){
如果(模拟读取(LDRPIN)<500)//LDR光传感器,需要调整“300”
{
彩色擦拭(strip.Color(0,0,0,50);//黑色
}
if(数字读取(PIRPIN)=高)
{
模拟阅读(LDRPIN);
如果(模拟读取(LDRPIN)>300)
彩色擦拭(条纹颜色(0,0,0,50);
否则{
彩色擦拭(条状彩色(255255,88,50);
延迟(8000);
}
}
}
无效颜色擦除(uint32\u t c、uint8\u t等待){
对于(uint16_t i=0;i您的实际LDR值是多少?使用正确的代码缩进并打印到串行。