아두이노간 블루투스로 조이스틱 값을 보내고싶은대
이코드로 하니까 시리얼모니터에 ?만 뜹니다
도와주세요
송신부
#include<SoftwareSerial.h>
SoftwareSerial BTSerial(2, 3);
int X = A0;
int Y = A1;
int S = 7;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
BTSerial.begin(9600);
pinMode(X, INPUT);
pinMode(Y, INPUT);
pinMode(S, INPUT);
digitalWrite(S, HIGH);
}
void loop() {
int bluetoothData =analogRead(X);
if(X>600){
BTSerial.print('1');
BTSerial.write(bluetoothData);
delay(100);
}
int x,y,s;
x = analogRead(X);
delay(1);
y = analogRead(Y);
delay(1);
s = digitalRead(S);
delay(1);
Serial.print(" X = ");
Serial.print(x,DEC);
Serial.print(" Y = ");
Serial.print(y,DEC);
Serial.print(" S = ");
Serial.println(s,DEC);
delay(100);
}
수신부
#include<SoftwareSerial.h>
SoftwareSerial BTSerial(2, 3);
void setup() {
Serial.begin(9600);
BTSerial.begin(9600);
}
void loop() {
if (BTSerial.available()) { // 받은 데이터가 있다면
char bluetoothData = BTSerial.read();
Serial.println(bluetoothData);
}
}
|