Serial.write over bluetooth works REALLY weird, only works in main()

I want to send data from a potentiometer over bluetooth via 2 HC-05 modules, I have paired them and I can send characers between them. I have decided to map the potentiometer to 25 possible values and send those values as char. here is the code for the remote:

//pin declaration
#define RX 11
#define TX 12
#define BUTTON 4
#define JOYSTICK A0

//variable declaration
char CharInput;
int x = 0;

//bluetooth setup code
#include <SoftwareSerial.h>
SoftwareSerial BTserial(RX, TX); // RX | TX

void SendData(int RawInput);

void setup() 
{
  BTserial.begin(9600);
  Serial.begin(9600);
  pinMode(JOYSTICK, INPUT);
}

void loop()
{
  int RawInput = analogRead(JOYSTICK);
  RawInput = map(RawInput,0,850,0,24);
  if(RawInput >= 13 && RawInput <= 15){
    RawInput = 14;
  }
  if(RawInput > 24){
    RawInput=24;
  }
    if(RawInput < 0){
    RawInput=0;
  }
  SendData(RawInput);
  //BTserial.write("M");
  delay(5);
  BTserial.write("M");
  delay(5);
  //Serial.println(RawInput);
}

void SendData(int RawInput){
  switch(RawInput){
    case 0:
      BTserial.write("A");
      Serial.println("A");
      break;
    case 1:
      BTserial.write("B");
      Serial.println("B");
      break;
    case 2:
      BTserial.write("C");
      Serial.println("C");
      break;
    case 3:
      BTserial.write("D");
      Serial.println("D");
      break;
    case 4:
      BTserial.write("E");
      Serial.println("E");
      break;
    case 5:
      BTserial.write("F");
      Serial.println("F");
      break;
    case 6:
      BTserial.write("G");
      Serial.println("G");
      break;
    case 7:
      BTserial.write("H");
      Serial.println("H");
      break;
    case 8:
      BTserial.write("I");
      Serial.println("I");
      break;
    case 9:
      BTserial.write("J");
      Serial.println("J");
      break;
    case 10:
      BTserial.write("K");
      Serial.println("K");
      break;
    case 11:
      BTserial.write("L");
      Serial.println("L");
      break;
    case 12:
      BTserial.write("M");
      Serial.println("M");
      break;
    case 13:
      BTserial.write("N");
      Serial.println("N");
      break;
    case 14:
      BTserial.write("O");
      Serial.println("O");
      break;
    case 15:
      BTserial.write("P");
      Serial.println("P");
      break;
    case 16:
      BTserial.write("Q");
      Serial.println("Q");
      break;
    case 17:
      BTserial.write("R");
      Serial.println("R");
      break;
    case 18:
      BTserial.write("S");
      Serial.println("S");
      break;
    case 19:
      BTserial.write("T");
      Serial.println("T");
      break;
    case 20:
      BTserial.write("U");
      Serial.println("U");
      break;
    case 21:
      BTserial.write("V");
      Serial.println("V");
      break;
    case 22:
      BTserial.write("W");
      Serial.println("W");
      break;
    case 23:
      BTserial.write("X");
      Serial.println("X");
      break;
    case 24:
      BTserial.write("Y");
      Serial.println("Y");
      break;
    default:
      BTserial.write("M");
      break;
  }
}

and the receiver code:

#define MOTOR 2
#define RPM A5
#define SWITCH1 3
#define SWITCH2 4
#define BLUETOOTH 12
#define POT A0

#include <Servo.h>
Servo Motor;

#include <SoftwareSerial.h>
SoftwareSerial BT(11,10); // RX | TX

bool RunFirstTimeOnly = true;
bool Brake = false;
char RawInput;
int IntInput;

void setup() {
  Motor.attach(MOTOR,700,2000);
  BT.begin(9600);
  Serial.begin(9600);
}

void loop() {
  if (RunFirstTimeOnly){
    //Motor.writeMicroseconds(700);
    RunFirstTimeOnly = false;
  }
  while(Brake==false){
    if(BT.available()){
      while(BT.available()){
        RawInput = BT.read();
      }
      IntInput = RawInput - '0';
      Serial.print(RawInput);
      Serial.print(": ");
      Serial.print(int(RawInput));
      Serial.print(": ");
      Serial.println(IntInput);
      
    }
    Serial.print(": ");
  }
  delay(10);
}

Now what is strange is that the Serial.write("M") in the main function works perfectly fine and it reads on the receiver as "M". Howerver when the RawInput equals 12, it should also Serial.write("M"), and it does it this way on the Serial monitor of the remote. But the serial monitor on the receiver displays the letter "U" or "T". all letters seem to be shifted by about 10.
When I ouput "A", it still receives "A". And when I output "Y" it will still receiver "Y"
The letters in between just seem to be shifted, and when i change it to range from ascii 0 to 127 it will mix up everything in between the value 0 and 127. then only 0 and 127 will be output correctly.

Please help me i've been bug testing for days but nothing seems to help

  RawInput = map(RawInput,0,850,0,24);

The output from the map() function is no longer raw input.

Why are you using write() to send character data? Why are you using it to send a string? Why do you have so much code to do something so simple?

void SendData(byte offset)
{
   char letter = 'A' + offset;
   BT.print(letter);
   Serial.println(letter);
}

Sure is a lot shorter, and does exactly the same thing (since you already constrained the input to be in the range that your switch cases cover).

I have tried all of the above except for using print instead of write. I did the whole switch thing to know that the issue couldnt be in sending a char, because sending it this way also worked in main.

I'll try using print instead of write this afternoon when i'm home, not sure whether it'll work but it's worth a try.
thanks for the repsonse

In the receiver, Servo can interfere with SoftwareSerial and vice versa. SoftwareSerial is very inefficient, because it disables interrupts for long periods of time.

If you can change to different pins, use AltSoftSerial on pins 8 & 9 instead. If you can't change pins, use NeoSWSerial.

Both libraries are available from the Arduino IDE Library Manager, under the menu Sketch -> Include Library -> Manager Libraries.

Cheers,
/dev

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data.

...R

**i am working on simular project. if you are interested here is my code **

p.s :it is working