SendMessage Issue (How can I solve this issue?)
Closed this issue · 1 comments
jeongcatfish commented
Hi
RIGHT TO THE POINT!
SendMessage sometimes don't work.
for ex:
led will turn On when I press "A".
but sometimes led is Off even if I press "A" over 2~4 times.
what's wrong with this? (HELP)
and the arduino tx led blinks whenever I press "A"
void setup() {
Serial.begin(9600);
pinMode(13,OUTPUT);
}
void loop() {
if(Serial.read()=='1')
digitalWrite(13,HIGH);
else if(Serial.read() == '2')
digitalWrite(13,LOW);
}
unity Code
if (Input.GetKeyDown(KeyCode.A))
{
Debug.Log("Sending 1");
serialController.SendSerialMessage("1");
}
if (Input.GetKeyDown(KeyCode.Z))
{
Debug.Log("Sending 2");
serialController.SendSerialMessage("2");
}
jeongcatfish commented
//SOLVED//
char data; //add
void setup() {
Serial.begin(9600);
pinMode(13,OUTPUT);
}
void loop() {
data = Serial.read(); //add
if(data=='1')
digitalWrite(13,HIGH);
else if(data == '2')
digitalWrite(13,LOW);
}