help me to how to run this program running

My project is about an air mouse with mpu6050 and a push-button act like a keyboard function. basically you can call it "PUBG" "Gun gamepad" ...I use Bluetooth modules HC-05 Master and Slave....both programs works if running separately...but I what to put them together at slave microcontroller using Arduino pro micro....and Uno at the master side....when running the program...only the mouse with mpu6050 is running but my button with keyboard function didn't work...please help me so that both programs work at the same time. please help me.... I need it....I attach my codes so you can see it.

MasterA.txt (1.96 KB)

SlaveB.txt (2.07 KB)

Please include short programs in your Post - many people use tablets and can't download code.

Have a look at this Simple nRF24L01+ Tutorial.

Wireless problems can be very difficult to debug so get the wireless part working on its own before you start adding any other features.

The examples are as simple as I could make them and they have worked for other Forum members. If you get stuck it will be easier to help with code that I am familiar with. Start by getting the first example to work

There is also a connection test program to check that the Arduino can talk to the nRF24 it is connected to.

I'm guessing there is a 3rd program which represents your best attempt at merging the programs. Please also post that and tell us in detail what it actually does and what you want it to do that is different. It will make it much easier to focus on the parts you need help with rather than wasting time on things that you can do.

...R

This program is working fine when I use the USB cable to run the program...Instead of using the USB cable, I wanna use Bluetooth. Here I use Bluetooth module HC-05... The problem is only the mouse program executed...but the keyboard program (using the switch pull-up- button) was not executed. I do test the keyboard program without the mouse program..it works fine..and also I do test the mouse program without the keyboard program also works fine.

Two things that I can't solve which is,

if (mySerial1.available() > 2) {
serialA = mySerial1.parseInt();
Serial.println(serialA);

Note: This is to read the MPU6050- 6axis accelerometer

if (mySerial1.available() > 0) {
char c = mySerial1.read();

Note: And this is for the Keyboard function to read the button pressed

The problem is the program only executes either one of them but not both. How can I combine them together so that the serial can read and print both of them?

Master code:

#include <Wire.h>
#include <I2Cdev.h>
#include <MPU6050.h>

const int buttonPin = 8;
const int buttonPin1 = 9;
const int buttonPin2 = 10;
const int buttonPin3 = 11;

int previousButtonState = HIGH;
int previousButtonState1 = HIGH;
int previousButtonState2 = HIGH;
int previousButtonState3 = HIGH;

MPU6050 mpu;
int16_t ax, ay, az;
int16_t gx, gy, gz;

void setup() {

pinMode(buttonPin, INPUT_PULLUP);
pinMode(buttonPin1, INPUT_PULLUP);
pinMode(buttonPin2, INPUT_PULLUP);
pinMode(buttonPin3, INPUT_PULLUP);

Serial.begin(9600);
Wire.begin();
mpu.initialize();
}

void loop() {

int buttonState = digitalRead(buttonPin);
int buttonState1 = digitalRead(buttonPin1);
int buttonState2 = digitalRead(buttonPin2);
int buttonState3 = digitalRead(buttonPin3);

mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);

long vx=map(ax,-17000,17000,20000,20008);
long vy=map(ay,-17000,17000,30000,30008);

Serial.println(vx);
delay(10);
Serial.println(vy);
delay(10);

if (buttonState == LOW && previousButtonState == HIGH) {
Serial.print('0');
}

if (buttonState == HIGH && previousButtonState == LOW) {
Serial.print('1');

}

if (buttonState1 == LOW && previousButtonState1 == HIGH) {
Serial.print('2');
}

if (buttonState1 == HIGH && previousButtonState1 == LOW) {
Serial.print('3');

}

if (buttonState2 == LOW && previousButtonState2 == HIGH) {
Serial.print('4');
}

if (buttonState2 == HIGH && previousButtonState2 == LOW) {
Serial.print('5');

}
if (buttonState3 == LOW && previousButtonState3 == HIGH) {
Serial.print('6');
}

if (buttonState3 == HIGH && previousButtonState3 == LOW) {
Serial.print('7');
}

previousButtonState = buttonState;
previousButtonState1 = buttonState1;
previousButtonState2 = buttonState2;
previousButtonState3 = buttonState3;

}

Slave code:

long vx;
long vy;
#include "Keyboard.h"
#include "Mouse.h"
#include <SoftwareSerial.h>
SoftwareSerial mySerial1(9, 8); // RX, TX

char c = ' ';
byte LED1 = 2;
byte LED2 = 3;
byte LED3 = 4;
byte LED4 = 5;

long serialA;
void setup() {

pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
pinMode(LED4, OUTPUT);

Serial.begin(9600);
mySerial1.begin(9600);
Mouse.begin();
Keyboard.begin();

}
void loop() {

if (mySerial1.available() > 2) {
serialA = mySerial1.parseInt();
Serial.println(serialA);

}

if (serialA>= 20000 && serialA <20008){

Serial.println("vxread");
Serial.println(vx);

vx=map(serialA,20000,20008,-4,4);
delay(10);

}

if (serialA>= 30000 && serialA <30008){

Serial.println("vyread");
vy=map(serialA,30000,30008,-4,4);
Serial.println(vy);

delay(10);

}
Mouse.move(vx, vy);

if (mySerial1.available() > 0) {
char c = mySerial1.read();

if (c=='0'){
digitalWrite(LED1, LOW );
//Send an ASCII 'B',
Keyboard.release(66);
}
if (c=='1'){
digitalWrite(LED1, HIGH);
//Send an ASCII 'B',
Keyboard.press(66);

}
if (c=='2') {
digitalWrite(LED2, LOW);
//Send an ASCII 'E',
Keyboard.release(69);
}
if (c=='3') {
digitalWrite(LED2, HIGH);
//Send an ASCII 'E',
Keyboard.press(69);
}
if (c=='4') {
digitalWrite(LED3, LOW);
//Send an ASCII 'F',
Keyboard.release(70);
}
if (c=='5'){
digitalWrite(LED3, HIGH);
//Send an ASCII 'F',
Keyboard.press(70);
}
if (c=='6'){
digitalWrite(LED4, LOW);
//Send an ASCII 'G',
Keyboard.release(71);
}
if (c=='7'){
digitalWrite(LED4, HIGH);
//Send an ASCII 'G',
Keyboard.press(71);
}
}
}

To make it easy for people to help you please modify your post and use the code button </>
codeButton.png

so your code 
looks like this

and is easy to copy to a text editor. See How to use the Forum

Your code is too long for me to study quickly without copying to my text editor.

...R

Here again, is my code...I hope you can help me,

Master Code:

``#include <Wire.h>
#include <I2Cdev.h>
#include <MPU6050.h>

const int buttonPin = 8;
const int buttonPin1 = 9;
const int buttonPin2 = 10;
const int buttonPin3 = 11;

int previousButtonState = HIGH;
int previousButtonState1 = HIGH;
int previousButtonState2 = HIGH;
int previousButtonState3 = HIGH;

MPU6050 mpu;
int16_t ax, ay, az;
int16_t gx, gy, gz;

void setup() {

pinMode(buttonPin, INPUT_PULLUP);
pinMode(buttonPin1, INPUT_PULLUP);
pinMode(buttonPin2, INPUT_PULLUP);
pinMode(buttonPin3, INPUT_PULLUP);

Serial.begin(9600);
Wire.begin();
mpu.initialize();
}

void loop() {
int buttonState = digitalRead(buttonPin);
int buttonState1 = digitalRead(buttonPin1);
int buttonState2 = digitalRead(buttonPin2);
int buttonState3 = digitalRead(buttonPin3);

mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);

long vx=map(ax,-17000,17000,20000,20008);
long vy=map(ay,-17000,17000,30000,30008);

Serial.println(vx);
delay(10);
Serial.println(vy);
delay(10);

if (buttonState == LOW && previousButtonState == HIGH) {
Serial.print('0');
}

if (buttonState == HIGH && previousButtonState == LOW) {
Serial.print('1');

}

if (buttonState1 == LOW && previousButtonState1 == HIGH) {
Serial.print('2');
}

if (buttonState1 == HIGH && previousButtonState1 == LOW) {
Serial.print('3');

}

if (buttonState2 == LOW && previousButtonState2 == HIGH) {
Serial.print('4');
}

if (buttonState2 == HIGH && previousButtonState2 == LOW) {
Serial.print('5');

}
if (buttonState3 == LOW && previousButtonState3 == HIGH) {
Serial.print('6');
}

if (buttonState3 == HIGH && previousButtonState3 == LOW) {
Serial.print('7');
}

previousButtonState = buttonState;
previousButtonState1 = buttonState1;
previousButtonState2 = buttonState2;
previousButtonState3 = buttonState3;
}

Slave Code:

``long vx;
long vy;
#include "Keyboard.h"
#include "Mouse.h"
#include <SoftwareSerial.h>
SoftwareSerial mySerial1(9, 8); // RX, TX

char c = ' ';
byte LED1 = 2;
byte LED2 = 3;
byte LED3 = 4;
byte LED4 = 5;

long serialA;
void setup() {

pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
pinMode(LED4, OUTPUT);

Serial.begin(9600);
mySerial1.begin(9600);
Mouse.begin();
Keyboard.begin();

}
void loop() {

if (mySerial1.available() > 2) {
serialA = mySerial1.parseInt();
Serial.println(serialA);

}

if (serialA>= 20000 && serialA <20008){

Serial.println("vxread");
Serial.println(vx);

vx=map(serialA,20000,20008,-4,4);
delay(10);

}

if (serialA>= 30000 && serialA <30008){

Serial.println("vyread");
vy=map(serialA,30000,30008,-4,4);
Serial.println(vy);

delay(10);

}

Mouse.move(vx, vy);

if (mySerial1.available() > 0) {
char c = mySerial1.read();

if (c=='0'){
digitalWrite(LED1, LOW );
//Send an ASCII 'B',
Keyboard.release(66);
}
if (c=='1'){
digitalWrite(LED1, HIGH);
//Send an ASCII 'B',
Keyboard.press(66);

}
if (c=='2') {
digitalWrite(LED2, LOW);
//Send an ASCII 'E',
Keyboard.release(69);
}
if (c=='3') {
digitalWrite(LED2, HIGH);
//Send an ASCII 'E',
Keyboard.press(69);
}
if (c=='4') {
digitalWrite(LED3, LOW);
//Send an ASCII 'F',
Keyboard.release(70);
}
if (c=='5'){
digitalWrite(LED3, HIGH);
//Send an ASCII 'F',
Keyboard.press(70);
}
if (c=='6'){
digitalWrite(LED4, LOW);
//Send an ASCII 'G',
Keyboard.release(71);
}
if (c=='7'){
digitalWrite(LED4, HIGH);
//Send an ASCII 'G',
Keyboard.press(71);
}
}
}

Right, first things first. Just delete your last post.

Go and read the instructions, then go back and modify your first post with the code (use the "More --> Modify" option to the bottom right of the post) to mark up the code as such so we can examine it conveniently and accurately. Do not re-post the same code.

If you do not do this, code you post could well be garbled and is certainly anything but easy to read.

Note: Also mark up any data in the same way. This includes error output that you get from the IDE.

And - before you post code, use "Auto Format" in the Tools menu to properly present the code. Then Ctrl-A to mark it all and the "Edit --> Save for Forum" option will add the "code" tags for you to post that code here.

Try and avoid unnecessary white space (blank lines). You should only use these to separate functional blocks of code.