Recently I´ve started creating an android app that controls the pins of the arduino. The app sends a text value that the arduino reads in ASCII compares it to a value and turns the pin on or off. The problem is that I dont know how to write a multi-digit number such as -2 in ASCII in the code.
Here is the code:
void setup() {
Serial.begin(9600);
pinMode(2, OUTPUT);
}
void loop() {
if(Serial.available()){
byte Data = Serial.read();
if(Data == 50){ //The app sends the value 2 which is 50 in ASCII. The arduino compares it
digitalWrite(2, HIGH); //and sets the pin2 high.
}
if(Data == ?){ // Here the app sends the value -2. I dont know how to write it
digitalWrite(2, LOW); //in ASCII in the code so arduino can understand it because they are
} //two diferent numbers: 45 and 50.
}
}
ArduBlue.ino (527 Bytes)