질문을 너무 많이 해서 죄송합니다.ㅠㅠ 너무 급한 일들이고 시간도 새벽 밖에 없어서 ㅠㅠ arduino mega2560은 그냥 softwareSerial로 연결하여 두 블루투스를 서로 페어링 했는데 마스터(uno)에 있는 조이스틱을 통해 조절한 숫자를 보내는 것이 안되 혹시 프로그램의 문제인지 싶어 질문드립니다. serial monitor에서는 계속 -1만 나오는데 통신이 안되고 있는 것 같습니다. 뭐가 문제일까요?
마스터(우노)
#include<SoftwareSerial.h>
SoftwareSerial btSerial(2,3);
const int udlow = 300;
const int udhigh = 450;
const int lrlow = 300;
const int lrhigh = 450;
int ud;
int lr;
char lrdirection;
char uddirection;
void setup() {
// put your setup code here, to run once:
btSerial.begin(9600);
Serial.begin(9600);
}
void loop() {
lrdirection = 0;
uddirection = 0;
ud=analogRead(0);
lr=analogRead(1);
if(ud>udhigh){
lrdirection='1';
Serial.println(lrdirection);
delay(100);
btSerial.write('1');
}
else if(ud<udlow){
lrdirection='2';
Serial.println(lrdirection);
btSerial.write('2');
delay(100);
}
else if(lr>lrhigh){
uddirection='3';
btSerial.write('3');
delay(100);
}
else if(lr<lrlow){
uddirection='4';
Serial.println(uddirection);
btSerial.write('4');
delay(100);}
else {
uddirection='5';
btSerial.write('5');
delay(100);
}
}
슬레이브(메가)
#include<SoftwareSerial.h>
SoftwareSerial btSerial(10,11);
void setup() {btSerial.begin(9600);
Serial.begin(9600);
// put your setup code here, to run once:
}
void loop() {
Serial.println(btSerial.read());
delay(100); // put your main code here, to run repeatedly:
}
|