BASIC4MCU | 질문게시판 | 네오 픽셀에 불이 안들어옵니다. 조언 부탁드립니다.
페이지 정보
작성자 같이의가치 작성일2021-12-13 20:55 조회409회 댓글1건본문
#include <Adafruit_NeoPixel.h>
#define LED_PIN 6 // 네오픽셀 D핀과 연결한 아두이노 핀 번호
#define LED_COUNT 12 // 네오픽셀 LED 개수
#define BRIGHTNESS 255 // 네오픽셀 LED 밝기(0 ~ 255) *RGBW만
int trig=9;
int echo=8;
// RGB일 경우 NEO_GRBW 대신 NEO_GRBW 입력
Adafruit_NeoPixel strip(12, 6, NEO_GRB + NEO_KHZ800);
void setup() {
Serial.begin(9600);
strip.begin(); // 네오픽셀 초기화(필수)
strip.setBrightness(BRIGHTNESS); // 네오픽셀 밝기 설정 *RGBW만
strip.show();
pinMode(trig, OUTPUT);
pinMode(echo, INPUT);
}
void loop() {
int cds = analogRead(A0);
Serial.println(cds);
if(cds > 100)
{
if(digitalRead(4) ==HIGH)
{
digitalWrite(trig, LOW);
digitalWrite(echo, LOW);
delayMicroseconds(2);
digitalWrite(trig, HIGH);
delayMicroseconds(10);
digitalWrite(trig, LOW);
unsigned long duration = pulseIn(echo, HIGH);
float distance = duration / 29.0 / 2.0;
Serial.print(distance);
Serial.println("cm");
if (distance < 10)
{
int color_r = 0;
int color_g = 255;
int color_b = 0;
for (int i = 0; i < 12; i++)
{
strip.setPixelColor(i, color_r, color_g, color_b, 0);
}
strip.show();
}
else
{
neoPixelOff();
}
}
else
{
neoPixelOff();
}
}
else
{
neoPixelOff();
}
delay(1000);
}
void neoPixelOff()
{
for (int i = 0; i < 12; i++)
{
strip.setPixelColor(i, 0, 0, 0, 0);
}
strip.show();
}
목적은 설정밝기 이하로 떨어지면 조도센서 On -> 조도센서가 On되면 PIR센서와 초음파 센서 On -> PIR센서에 인체가 감지되고 + 동시에 초음파 센서로부터 10cm 이내 인체or물체 검출되면 -> 그경우만 네오픽셀 On, 나머진 OFF
입니다.
댓글 1
조회수 409master님의 댓글
master 작성일
#include <Adafruit_NeoPixel.h>
//
#define LED_PIN 6 // 네오픽셀 D핀과 연결한 아두이노 핀 번호
#define LED_COUNT 12 // 네오픽셀 LED 개수
#define BRIGHTNESS 255 // 네오픽셀 LED 밝기(0 ~ 255)*RGBW만
//
int trig=9;
int echo=8;
// RGB일 경우 NEO_GRBW 대신 NEO_GRBW 입력
Adafruit_NeoPixel strip(12,6,NEO_GRB + NEO_KHZ800);
//
void setup(){
pinMode(trig,OUTPUT); pinMode(echo,INPUT);
strip.begin(); strip.setBrightness(BRIGHTNESS); strip.show();
Serial.begin(9600);
}
//
void loop(){
int cds=analogRead(A0); Serial.print("cds:"); Serial.println(cds);
int pir=digitalRead(4); Serial.print("pir:"); Serial.println(pir);
digitalWrite(trig,HIGH); delayMicroseconds(10); digitalWrite(trig,LOW);
unsigned long duration=pulseIn(echo,HIGH);
float distance=duration/29.0/2.0; Serial.print(distance); Serial.println("cm");
//
if((cds>100)&&(pir)&&(distance<10)){ for(int i=0;i<12;i++)strip.setPixelColor(i,0,255,0,0); strip.show(); delay(1000); }
else{ for(int i=0;i<12;i++)strip.setPixelColor(i,0,0,0,0); strip.show(); delay(100); }
}
시리얼모니터에 센서값들이 출력되고 있으니 조건에 부합되는지 확인하세요