Go Down

Topic: Problem with HC-05 (Read 132 times) previous topic - next topic

typix

Hi,

I am using Arduino Leonardo and HC-05 and I have a problem with this module.

So this is my code:

Code: [Select]


String WIRE_STRING = "", POS_STRING = "";
unsigned int WIRE, POS;

void MAKE_INTEGER() {

   if(WIRE_STRING == "0*")
    WIRE = 0;
   else if(WIRE_STRING == "1*")
    WIRE = 1;
 
}

void MAKE_INTEGER_P() {

   if(POS_STRING == "0")
    POS = 0;
   else if(POS_STRING == "1")
    POS = 1;

}

void setup() {
 
  Serial.begin(9600);
  Serial1.begin(9600);
 
}

void loop() {
 
  if(Serial1.available() > 0)
  {
    WIRE_STRING = Serial1.readString();
    MAKE_INTEGER();
    switch(WIRE)
    {
      case 0:
        if(!Serial1.readString());
        POS_STRING = Serial1.readString();
        MAKE_INTEGER_P();
        Serial.println(POS);
        break;

      case 1:
        if(!Serial1.readString());
        POS_STRING = Serial1.readString();
        MAKE_INTEGER_P();
        Serial.println(POS);
        break;
       
    }
  }
}



I want to send the Arduino the position of a wire. The problem is that after I am sending the wire number, and then his position, it prints me the wire number instead of the position because I think both the position and the wire read the same thing and I don't understand why.

For example, I sent the wire number "0" and then the position number "1" and the Arduino terminal prints "0" instead of "1".

Hope you can help me with that.
Thank you very much!

typix


Go Up