Issue sending an int or char over serial

Hey folks, I am trying to get the basics down of sending data over serial and I am having some trouble. I have a pro micro that I have set a flag that when set to 1 it will send the 1 over serial to a leonardo. When I try to receive the data all I get is a -1. Any ideas on what I am doing wrong? Is it the wrong data type? I’ve tried sending it as a char as well or as mySerial.print or write. Here is a simple test I am trying before I implement this into the larger project I need this in. Here is the code I am using:

Pro micro sending data:

#include <hidboot.h>
#include <usbhub.h>
#include "Keyboard.h"
#include <SoftwareSerial.h>

SoftwareSerial mySerial(9, 10); // RX, TX
int keyFlagger1 = 1;

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

}

void loop() {
    mySerial.write(keyFlagger1);
    delay(10000);
}

Leonardo receiving:

#include "Keyboard.h"
#include <SoftwareSerial.h>

SoftwareSerial mySerial(9, 10); // RX, TX
int keyFlagger1 = 0;

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

void loop() {
    Serial.print("key is set to");
    Serial.print(keyFlagger1);
    keyFlagger1 = mySerial.read();
    Serial.print(keyFlagger1);
    delay(10000);
}

Serial sends -1.

Serial sends -1.

That's what happens if you read stuff that isn't there.

keyFlagger1 = mySerial.read();

You should be checking mySerial.available() to see if there is anything to read first.

Thanks for the input, my suspicion was the case that nothing was coming through. Aside from the use of serial.available method, any thoughts on why it wouldn't send the 1? My thought would be a bad connection between the pins on the devices, the rest of the code seems fine am I correct?

It might be sending the 1. You're just printing so many -1's so fast you'd never stand a chance of seeing it.

yep started using mySerial.available and its picking up my flag test now. Thanks so much. Yeah it seems that it was getting lost in the -1s like you stated.