Im trying to create a 3d air mouse with bluetooth

I keep getting an error stating: ' mySerial' was not declared in this scope'
In not sure what im doing wrong can anyone help?
here is the code:

#include<Mouse.h>
#include<MPU6050.h>
#include<Wire.h>
#include<I2Cdev.h>
#include<Keyboard.h>
#include<SoftwareSerial.h>

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

void setup()
{
Serial.begin(9600);
Wire.begin();
mpu.initialize();
mySerial.begin(9600);
Mouse.begin();
Keyboard.begin();

SoftwareSerial mySerial (9,8); //pins RX, TX
long serialA;
long x;
long y;

}

void loop()
{

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

if (serialA>=20000 && serialA <20010)
{
Serial.println("xread");
Serial.println(x);

x=map(serialA,20000,20010,-5.5);
delay(10);

}

if (serailA>=30000 && serialA <30010)
{
Serial.println("yread");
y=map(serialA,30000,30010,-5.5);
serial.println(y);
dealay(10);
}

Mouse.move(x,y);

if (serialA==80000)
{
Serial.println("Left");
Mouse.press(MOUSE_RIGHT);
Serial.println(serialA);
delay(10);
}

if (serialA==90000)
{
Serial.println("RIGHT");
mouse.press(MOUSE_LEFT);
delay(10);
}
}

Your mySerial object should be defined outside the setup and loop functions.

Please remember to use code tags when posting code

Using both autoformat in the IDE and code tags here the result will be code, not text...

#include<Mouse.h>
#include<MPU6050.h>
#include<Wire.h>
#include<I2Cdev.h>
#include<Keyboard.h>
#include<SoftwareSerial.h>

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

void setup()
{
  Serial.begin(9600);
  Wire.begin();
  mpu.initialize();
  mySerial.begin(9600);
  Mouse.begin();
  Keyboard.begin();

  SoftwareSerial mySerial (9, 8); //pins RX, TX
  long serialA;
  long x;
  long y;

}

void loop()
{

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

  if (serialA >= 20000 && serialA < 20010)
  {
    Serial.println("xread");
    Serial.println(x);

    x = map(serialA, 20000, 20010, -5.5);
    delay(10);

  }
  if (serailA >= 30000 && serialA < 30010)
  {
    Serial.println("yread");
    y = map(serialA, 30000, 30010, -5.5);
    serial.println(y);
    dealay(10);
  }

  Mouse.move(x, y);

  if (serialA == 80000)
  {
    Serial.println("Left");
    Mouse.press(MOUSE_RIGHT);
    Serial.println(serialA);
    delay(10);
  }

  if (serialA == 90000)
  {
    Serial.println("RIGHT");
    mouse.press(MOUSE_LEFT);
    delay(10);
  }
}


This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.