아두이노 우노 자체에서는 시리얼모니터에 카운터가 되는데 이걸 앱인벤터에서 블루투스를 이용하여 최종적으로는 앱으로 카운터를 나타내려고 합니다. 그런데 블루투스 연결되서 앱을보면 ? 이라고 쓰레기값이 입력됩니다. 쓰레기값말고 카운터가 되어야하는데 어떻게하면 좋을까요..?
#include <SoftwareSerial.h>
int LED_Pin = 13;
int LED_Pin1 = 12;
int LED_Pin2 = 11;
int vibr_Pin = 5;
int vibr_Pin1 = 6;
int vibr_Pin2 = 7;
byte measurement;
int RxPin=2;
int TxPin=3;
int key=0, cnt=0;
SoftwareSerial BTSerial(RxPin,TxPin);
void setup(){
Serial.begin(9600);
BTSerial.begin(9600);
pinMode(LED_Pin, OUTPUT);
pinMode(vibr_Pin, INPUT);
pinMode(LED_Pin1, OUTPUT);
pinMode(vibr_Pin1, INPUT);
pinMode(LED_Pin2, OUTPUT);
pinMode(vibr_Pin2, INPUT);//set vibr_Pin input for measurment
//init serial 9600
// Serial.println("----------------------Vibration demo------------------------");
DDRB =0xFF;//출력모드
PORTB = 0x00; //LED OFF
DDRD = 0x00; //D포트 입력모드
PORTD = 0xFF; //PULL UP
}
void loop(){
measurement = TP_init();
// Serial.println(key);
//delay(1);
if(measurement == 0) key=0;
//Serial.println(key);
if (measurement == 32){ //비교 2개 ==
digitalWrite(LED_Pin, HIGH);
//sprintf(measurement,"d",measurement);
key = 1;
//BTSerial.print(key);
//Serial.println(key);
}
else{
digitalWrite(LED_Pin,LOW);
}
if (measurement == 64){
digitalWrite(LED_Pin1, HIGH);
//sprintf(measurement,"d",measurement);
key = 2;
//BTSerial.print(key);
//Serial.println(key);
}
else{
digitalWrite(LED_Pin1,LOW);
}
if (measurement == 128){
digitalWrite(LED_Pin2, HIGH);
// sprintf(measurement,"d",measurement);
key = 3;
//BTSerial.print(key);
//Serial.println(key);
}
else{
digitalWrite(LED_Pin2,LOW);
}
Serial.println(cnt);
if(key !=0) cnt=cnt+1;
}
long TP_init(){
int i=0;
byte sensor = 0xff; //진동없음
for (i=0;i<200;i++){
sensor &= PIND; //5,6,7
}
measurement = ~(sensor + 2);
return measurement;
}
< 앱인벤터>