Serial1 communication problem between two Arduino MICROs (bluetooth)

Hi, I’m trying to tranfer analog and digital signals from slave to master Arduino.

After transferring just one analog or one digital signal, I have big problem…

In digital, the signal has to be ‘0’ or ‘1’. If it is analog, it has to be in 0~1023.

But minus signal is always mixed in serial monitor like below…
0 -1
0 0
0 0
0 -1
0 ------> -1
1 -1
1 1
1 -1
1 1
1 1

These are my codes for master and slave.

#include<SoftwareSerial.h>

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

void loop() 
{
 
  int x = Serial1.read();
  int y = Serial1.read();
  int s = Serial1.read();
  int x1, y1;
  x1 = map(x, 0, 255, 0, 1023);
  y1 = map(y, 0, 255, 0, 1023);
 
/*  Serial.print(" X = ");
  Serial.print(x1,DEC);
  Serial.println("  "); 
  
  Serial.print(" Y = ");
  Serial.println(y1,DEC);
  Serial.print("  ");     */
  
  Serial.print(" S = ");
  Serial.print(s,DEC);
  Serial.println(" ");      
   
}
#include<SoftwareSerial.h>

int X = A0;
int Y = A1;
int S = 7;


int xmap;
int ymap;
//int smap;

void setup() 
{
  Serial.begin(38400);
  Serial1.begin(38400);
  pinMode(X, INPUT);
  pinMode(Y, INPUT);
  pinMode(S, INPUT);
  digitalWrite(S, HIGH);
}

void loop() {
  int x,y,s;

  
/*  x = analogRead(X);
  Serial.print("   X =  ");
  Serial.println(x,DEC);
  xmap = map(x, 0, 1023, 0, 255);
  Serial1.write(xmap);

  
  y = analogRead(Y);
  Serial.print("   Y =  ");
  Serial.println(y,DEC);
  ymap = map(y, 0, 1023, 0, 255);
  Serial1.write(ymap);           */

  
  s = digitalRead(S);
  Serial.print("   S =  ");
  Serial.println(s,DEC);
//  smap = map(x, 0, 1023, 0, 255);
  Serial1.write(s);                                                        

/*    while(Serial1.available())
  {
    Serial.write(analogRead(X));
    Serial.write(analogRead(Y));
    Serial.write(digitalRead(S));
  }  
  
    while(Serial.available())
  {
    Serial1.write(analogRead(X));
    Serial1.write(analogRead(Y));
    Serial1.write(digitalRead(S));
  }  */

/*  while(Serial1.available())
  {
  Serial1.write(analogRead(X));  
  Serial1.write(analogRead(Y));
  Serial1.write(digitalRead(S));
  }     */

//delay(100);
}

You are not using SoftwareSerial so you can drop the #include line.

It will be much easier to send the data in human readable form using Serial1.print() rather than Serial1.write()

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data. There is also a parse example to illustrate how to extract numbers from the received text.

...R