BASIC4MCU | 질문게시판 | 블루투스 연결이 안됩니다.
페이지 정보
작성자 비공개 작성일2018-06-18 21:07 조회7,806회 댓글0건본문
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Adafruit_NeoPixel.h>
#include <SoftwareSerial.h>
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display
SoftwareSerial bluetooth(6,5); // 블루투스 제어핀
#define PIN 7 // LED제어 신호핀
#define NUMPIXELS 10 // 제어하고 싶은 LED 개수
Adafruit_NeoPixel pixels=Adafruit_NeoPixel(NUMPIXELS,PIN,NEO_GRB+NEO_KHZ800);
int SOUND_SENSOR = A0; // A0 신호 입력
int threshold = 1020; //감도조절
int Sensor_value; // 아날로그 사운드 센서값
int count = 0;
#define BUTTON 2
//
void setup(){
Serial.begin(9600); // 시리얼모니터 출력
pinMode(SOUND_SENSOR,INPUT); // pinMode input 값
pinMode(BUTTON,INPUT);
pixels.begin(); // 네오픽셀 라이브러리 초기화
lcd.init(); // LCD 초기화
lcd.backlight(); // 백라이트 켜기
bluetooth.begin(9600); // 블루투스 초기화
}
//
void loop(){
Sensor_value=analogRead(SOUND_SENSOR);
//Serial.println(Sensor_value); // 시리얼모니터에 감도표시
// delay(10);//딜레이0.01초
if(Sensor_value>=threshold){
for(int i=0; i<NUMPIXELS; i++){
pixels.setPixelColor(i,pixels.Color(0,150,0)); //초록색 led
pixels.show(); // This sends the updated pixel color to the hardware.
lcd.setCursor(0,0); // 1번째, 1라인
lcd.print("Signal on!"); // signal on 출력
lcd.init();
delay(10);
count++;
}
}
else{
for(int i=0; i<NUMPIXELS; i++){
pixels.setPixelColor(i,pixels.Color(0,0,0));
pixels.show(); // This sends the updated pixel color to the hardware.
lcd.setCursor(0,0); // 1번째, 1라인
lcd.print(count); //count 출력 (10씩 증가)
delay(10);
}
}
//
if(bluetooth.available()){
Serial.write(bluetooth.read());
}
if(Serial.available()){
bluetooth.write(Serial.read());
}
} // 마스터
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
슬레이브
#include <LiquidCrystal_I2C.h>
#include <SoftwareSerial.h>
#include <Wire.h>
SoftwareSerial bluetooth(7, 6); //RX, TX
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display
void setup(){
Serial.begin(9600);
bluetooth.begin(9600);
pinMode(8,INPUT);
}
void loop(){
if (bluetooth.available()) {
int button = digitalRead(8); // 스위치
if(button == 1) {
lcd.init();
}
}
}
2개의 코드가 연결이 되지 않습니다 ㅠㅠ 혹시 뭐가 잘못된건 가요?
댓글 0
조회수 7,806등록된 댓글이 없습니다.