motorspeed1 not declared in this scope

hello i am 9yrs old and i am trying to build a robot but i get an error message at the end. can somebody help me

Arduino: 1.8.9 (Windows Store 1.8.21.0) (Windows 10), Board: "Arduino/Genuino Uno"

C:\Users\Jim\Documents\Arduino\motorandjoystick\motor_and_joystick\motor_and_joystick.ino: In function 'void loop()':

motor_and_joystick:95:5: error: 'MotorSpeed1' was not declared in this scope

MotorSpeed1 = map(joyposVert, 0, 460, 0, 255);

^

motor_and_joystick:96:5: error: 'MotorSpeed2' was not declared in this scope

MotorSpeed2 = map(joyposVert, 0, 460, 0, 255);

^

motor_and_joystick:115:5: error: 'MotorSpeed1' was not declared in this scope

MotorSpeed1 = map(joyposVert, 564, 1023, 0, 255);

^

motor_and_joystick:116:5: error: 'MotorSpeed2' was not declared in this scope

MotorSpeed2 = map(joyposVert, 564, 1023, 0, 255);

^

motor_and_joystick:126:5: error: 'MotorSpeed1' was not declared in this scope

MotorSpeed1 = 0;

^

motor_and_joystick:127:5: error: 'MotorSpeed2' was not declared in this scope

MotorSpeed2 = 0;

^

motor_and_joystick:146:22: error: 'joyposHorze' was not declared in this scope

joyposHorz = map(joyposHorze, 0, 460, 0, 255);

^

motor_and_joystick:149:5: error: 'MotorSpeed1' was not declared in this scope

MotorSpeed1 = MotorSpeed1 - joyposHorz;

^

motor_and_joystick:150:5: error: 'MotorSpeed2' was not declared in this scope

MotorSpeed2 = MotorSpeed2 + joyposHorz;

^

motor_and_joystick:167:5: error: 'MotorSpeed1' was not declared in this scope

MotorSpeed1 = MotorSpeed1 + joyposHorz;

^

motor_and_joystick:169:5: error: 'MotorSpeed2' was not declared in this scope

MotorSpeed2 = MotorSpeed2 - joyposHorz;

^

motor_and_joystick:182:20: error: 'MotorSpeed1' was not declared in this scope

analogWrite(ENA, MotorSpeed1);

^

motor_and_joystick:184:20: error: 'MotorSpeed2' was not declared in this scope

analogWrite(ENB, MotorSpeed2);

^

exit status 1
'MotorSpeed1' was not declared in this scope

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.


// Motor A

int ENA = 9;
int in1 = 8;
int in2 = 7;

// Motor B

int ENB = 3;
int in3 = 5;
int in4 = 4;

// Joystick Input

int joyVert = A0; // vertical

int joyHorz = A1; // Horizontal

// Motor speed values - start at zero

int Motorspeed1 = 0;

int Motorspeed2 = 0;

// joystick values - start at 512 (middle position)

int joyposVert = 512;

int joyposHorz = 512;

void setup()

{

// set all the motor control pins to outputs

pinMode(ENA, OUTPUT);
pinMode(ENB, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);

// Start with motors disabled and direction forward

// Motor A

digitalWrite(ENA, LOW);
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);

// Motor B

digitalWrite(ENB, LOW);
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);

}

void loop() {

// Read the joystick x and y positions

joyposVert = analogRead(joyVert);
joyposHorz = analogRead(joyHorz);

// Determine if this is a forward or backward motion
// Do this by reading the vertical value
// Apply results to MotorSpeed and to direction

if (joyposVert < 460)
{

// This is Backward

// Set Motor A backward

digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);

// Motor B backward

digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);

// Determine MotorSpeeds

// As we are going backwards we need to reverse readings

joyposVert = joyposVert - 460; // This produces a negative number
joyposVert = joyposVert * -1; // Make the number positive

MotorSpeed1 = map(joyposVert, 0, 460, 0, 255);
MotorSpeed2 = map(joyposVert, 0, 460, 0, 255);

}
else if (joyposVert > 564)
{
// This is Forward

// Set Motor A forward

digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);

// Set Motor B forward

digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);

//Determine Motor Speeds

MotorSpeed1 = map(joyposVert, 564, 1023, 0, 255);
MotorSpeed2 = map(joyposVert, 564, 1023, 0, 255);

}

else

{

// This is Stopped

MotorSpeed1 = 0;
MotorSpeed2 = 0;

}

// Now do the steering
// The Horizontal position will "weigh" the motor
// Values for each motor

if (joyposHorz < 460)
{
// Move Left

// As we are going left we need to reverse readings

joyposHorz = joyposHorz - 460; // This produces a negative number
joyposHorz = joyposHorz * -1; // Make the number positive

// Map the number to a value of 255 maximum

joyposHorz = map(joyposHorze, 0, 460, 0, 255);

MotorSpeed1 = MotorSpeed1 - joyposHorz;
MotorSpeed2 = MotorSpeed2 + joyposHorz;

// Don`t exceed range of 0-255 for motor speeds

if (MotorSpeed1 < 0)MotorSpeed1 = 0;
if (MotorSpeed2 > 255)MotorSpeed2 = 255;

}
else if (joyposHorz > 564)
{
// Move Right

// Map the number to a value of 255 maximum

joyposHorz = map(joyposHorz, 564, 1023, 0, 255);

MotorSpeed1 = MotorSpeed1 + joyposHorz;

MotorSpeed2 = MotorSpeed2 - joyposHorz;

// Don`t exceed range 0-255 for motor speeds

if (MotorSpeed1 > 255)MotorSpeed1 = 255;
if (MotorSpeed2 < 0)MotorSpeed2 = 0;

}

// Set the motor speeds

analogWrite(ENA, MotorSpeed1);

analogWrite(ENB, MotorSpeed2);
}

Post your sketch. Please use code tags.

You should share your code if you want help. In your IDE you can use "copy for forum" under the edit menu. Or you can copy and paste it between code tags. [code]your code here[/code]

Either those variables are not defined or they are defined as local variables inside a different function. Remember, capitalization counts. Declaring "motorSpeed1" doesn't declare "MotorSpeed1".

If they are used in only one function, declare them in the one function. If they are shared between two or more functions, declare them outside of any function and somewhere above the first function they are used in.

Blackfin:
Post your sketch. Please use code tags.

// Motor A

int ENA = 9;
int in1 = 8;
int in2 = 7;

// Motor B

int ENB = 3;
int in3 = 5;
int in4 = 4;

// Joystick Input

int joyVert = A0; // vertical

int joyHorz = A1; // Horizontal

// Motor speed values - start at zero

int Motorspeed1 = 0;

int Motorspeed2 = 0;

// joystick values - start at 512 (middle position)

int joyposVert = 512;

int joyposHorz = 512;

void setup()

{

// set all the motor control pins to outputs

pinMode(ENA, OUTPUT);
pinMode(ENB, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);

// Start with motors disabled and direction forward

// Motor A

digitalWrite(ENA, LOW);
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);

// Motor B

digitalWrite(ENB, LOW);
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);

}

void loop() {

// Read the joystick x and y positions

joyposVert = analogRead(joyVert);
joyposHorz = analogRead(joyHorz);

// Determine if this is a forward or backward motion
// Do this by reading the vertical value
// Apply results to MotorSpeed and to direction

if (joyposVert < 460)
{

// This is Backward

// Set Motor A backward

digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);

// Motor B backward

digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);

// Determine MotorSpeeds

// As we are going backwards we need to reverse readings

joyposVert = joyposVert - 460; // This produces a negative number
joyposVert = joyposVert * -1; // Make the number positive

MotorSpeed1 = map(joyposVert, 0, 460, 0, 255);
MotorSpeed2 = map(joyposVert, 0, 460, 0, 255);

}
else if (joyposVert > 564)
{
// This is Forward

// Set Motor A forward

digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);

// Set Motor B forward

digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);

//Determine Motor Speeds

MotorSpeed1 = map(joyposVert, 564, 1023, 0, 255);
MotorSpeed2 = map(joyposVert, 564, 1023, 0, 255);

}

else

{

// This is Stopped

MotorSpeed1 = 0;
MotorSpeed2 = 0;

}

// Now do the steering
// The Horizontal position will "weigh" the motor
// Values for each motor

if (joyposHorz < 460)
{
// Move Left

// As we are going left we need to reverse readings

joyposHorz = joyposHorz - 460; // This produces a negative number
joyposHorz = joyposHorz * -1; // Make the number positive

// Map the number to a value of 255 maximum

joyposHorz = map(joyposHorze, 0, 460, 0, 255);

MotorSpeed1 = MotorSpeed1 - joyposHorz;
MotorSpeed2 = MotorSpeed2 + joyposHorz;

// Don`t exceed range of 0-255 for motor speeds

if (MotorSpeed1 < 0)MotorSpeed1 = 0;
if (MotorSpeed2 > 255)MotorSpeed2 = 255;

}
else if (joyposHorz > 564)
{
// Move Right

// Map the number to a value of 255 maximum

joyposHorz = map(joyposHorz, 564, 1023, 0, 255);

MotorSpeed1 = MotorSpeed1 + joyposHorz;

MotorSpeed2 = MotorSpeed2 - joyposHorz;

// Don`t exceed range 0-255 for motor speeds

if (MotorSpeed1 > 255)MotorSpeed1 = 255;
if (MotorSpeed2 < 0)MotorSpeed2 = 0;

}

// Set the motor speeds

analogWrite(ENA, MotorSpeed1);

analogWrite(ENB, MotorSpeed2);
}

As johnwasser notes, spelling and capitalization matter. You declare:

int Motorspeed1 = 0;

int Motorspeed2 = 0;

but reference (for example):

MotorSpeed1 = MotorSpeed1 + joyposHorz;

    MotorSpeed2 = MotorSpeed2 - joyposHorz;

Do you see the difference?

You quote a line that says to use code tags and then disregard using code tags. Smh

I just don't understand people.

DangerToMyself:
What the ???

You quote a line that says to use code tags and then disregard using code tags. Smh

I just don't understand people.

The OP said he/she is 9 yrs old. Assuming this to be true, I think we can cut them some slack.