아두이노 질문입니다.
페이지 정보
작성자 clown 작성일18-06-18 03:01 조회6,576회 댓글2건본문
// MCU BASIC: https://www.basic4mcu.com
// DateTime : 2018-06-17 오후 9:57:29
// by Ok-Hyun Park
//
#include <Adafruit_NeoPixel.h>
#include <LiquidCrystal.h>
#include <SoftwareSerial.h>
#define BT_RXD 6 // 블루투스 제어핀
#define BT_TXD 4 // 블루투스 제어핀
SoftwareSerial bluetooth(BT_RXD,BT_TXD); // 블루투스 제어핀
#define PIN 7 // LED제어 신호핀
#define NUMPIXELS 10 // 제어하고 싶은 LED 개수
Adafruit_NeoPixel pixels=Adafruit_NeoPixel(NUMPIXELS,PIN,NEO_GRB+NEO_KHZ800);
LiquidCrystal lcd(4,5,8,9,10,11); //(RS,E,DB4,DB5,DB6,DB7)
int SOUND_SENSOR=A0; // A0 신호 입력
int threshold=50; //감도조절
int Sensor_value;
//
void setup(){
Serial.begin(9600); // 시리얼모니터 출력
pinMode(SOUND_SENSOR,INPUT); // pinMode input 값
pixels.begin(); // 네오픽셀 라이브러리 초기화
lcd.begin(16,2); // lcd 초기화
bluetooth.begin(9600); // 블루투스 초기화
}
//
void loop(){
Sensor_value=analogRead(SOUND_SENSOR);
Serial.println(Sensor_value); // 시리얼모니터에 감도표시
delay(10);//딜레이0.1초
if(Sensor_value>=threshold){
for(int i=0; i<NUMPIXELS; i++){
pixels.setPixelColor(i,pixels.Color(0,150,0));
pixels.show(); // This sends the updated pixel color to the hardware.
delay(10);
}
lcd.setCursor(4,1); lcd.print("signal!"); // 5열,2행부터 출력 // 'Eduino'
}
else{}
//
if(bluetooth.available()){
Serial.write(bluetooth.read());
}
//
if(Serial.available()){
bluetooth.write(Serial.read());
}
int threshold=50; //감도조절
이 값이 너무 작아서 약한 소리에도 반응하는겁니다.
Serial.println(Sensor_value); // 시리얼모니터에 감도표시
시리얼모니터에 값이 표시되고 있으니
어느정도 큰 소리에 반응하게 하려는지 입력을 보면서 정하세요
이렇게 올려주셔서 threshold 값을 500까지 올렸는데도 led 불이 꺼지지 않습니다.
시리얼 모니터에는 28~30 사이에 숫자만 입력되고 있습니다.
혹시 무슨 문제인가요?
댓글 : 2
조회수 : 6,576
master님의 댓글
master 작성일
void setup(){
Serial.begin(9600); // 시리얼모니터 출력
pinMode(SOUND_SENSOR,INPUT); // pinMode input 값
pixels.begin(); // 네오픽셀 라이브러리 초기화
strip.show(); // <---------------------------------추가
lcd.begin(16,2); // lcd 초기화
bluetooth.begin(9600); // 블루투스 초기화
}
처음에 전원 넣으면 아무 LED가 임의의 색상으로 켜지게 되는데요
셋업 함수에서 꺼줘야합니다.
master님의 댓글
master 작성일
https://www.basic4mcu.com/bbs/board.php?bo_table=gac&wr_id=1951
이 글에 flag 변수를 사용해서 조금 수정한 글이 있으니 참고하세요