LED Controll via Bluetooth :D

Hello guys, i'm here again to be a waste of time to you.

Yesterday I did a 2 LED control Android APP via Bluetooth with a char variable and letters A, B and C.
Now i'm trying to do exactly the same but using an int variable and numbers 999, 1000 and 1001 but it doesn't work. I think my Android code is correct (anyways i will put it here) and my mistake is in the ArduCode :smiley:

I have HC-05 Module and Arduino Uno board. Here is a screenshot of the Android code and the ArduCode. Thank you mates :smiley:

void setup() {
  pinMode(7,OUTPUT);
  pinMode(8,OUTPUT);
  Serial.begin(9600);
}

void loop() {
 
  int data = Serial.read();
 
  if(data == 999)digitalWrite(7,HIGH);
  if(data == 1001)digitalWrite(8,HIGH);
  
  if(data == 1000){
    digitalWrite(7,LOW);
    digitalWrite(8,LOW);
  }
}

.

None?

You send a 2-byte number in the Android app, but read just 1 byte in Arduino.

And how i can read a 2 byte number in Arduino. Maybe with more bauds in Serial.begin(...)?

Because the int variable can use 2-byte numbers

Thank you :smiley:

Read 2 bytes and combine them:

if (Serial.available() > 1) {
  byte b1 = Serial.read();
  byte b2 = Serial.read();
  value = b1 | (b2 << 8); // swap b1 and b2 if necessary, depending on how the Android app sends them
}

It's true haha and it's working now. I have a lot to learn. Thanks!