"RMSVal" was not declared in this slope [SOLVED]

Hi, i'm kind of new to Arduino, and i'm using it for a schoolproject. Unfortunately, my teachers have also just been introduced to the program, so there's not much help available from them.

My problem is that when compiling (I've not tested it out on a board yet, i need some parts), i get an errorcode on a line with a digitalRead: "'RMSVal' was not declared in this scope".

I have tried checking if i could have misspelled an integer, misplaced some curly brackets or if i had missed some semicolons, but that didn't help. After that i checked the Arduino page on using the digitalRead function, and afterwards i checked how to use the int function to see if i had set the integers wrong. Still no succes. Finally i tried putting the digitalRead function in the setup to see if that could fix it, still nothing. Do anyone know what i have done wrong? Here's the relevant part of my code code:

void setup()
{
int RMSPin = 1;
int RESPin = 4;
int LMSPin = 2;
int LESPin = 7;
int LWPin = 3;
int RWPin = 5;

int RMSVal = 0;
int RESVal = 0;
int LMSVal = 0;
int LESVal = 0;

pinMode(RMSPin, INPUT);
pinMode(RESPin, INPUT);
pinMode(LMSPin, INPUT);
pinMode(LESPin, INPUT);
pinMode(LWPin, OUTPUT);
pinMode(RWPin, OUTPUT);


}

void loop()
{
RMSVal = digitalRead(RMSPIN);
RESVal = digitalRead(RESPin);
LMSVal = digitalRead(LMSPin);
LESVal = digitalRead(LESPin);

Thanks for your time!

The scope of a variable is either global - not defined in a function - or local - defined in a function.

All of yours are local, to setup(). Local variables can only be used in the function that they are defined in.

Also check use of RMSPin v. RMSPIN

Variables defined inside a function are only available to that function. To make variables that can be used by more than one functions you would typically make then 'global' by defining them outside the functions.

Also it is a good idea to use the 'const' keyword with things like pin numbers. That way the compiler will complain if your code accidentally tries to change the value.

Also it is bad practice to use Pin 1 for I/O. That's one of the Serial I/O pins (0 and 1) and is very useful for debugging messages. Best not to use it unless you have no other choice (and don't need Serial I/O for anything).

const int RMSPin = 1;
const int RESPin = 4;
const int LMSPin = 2;
const int LESPin = 7;
const int LWPin = 3;
const int RWPin = 5;

int RMSVal = 0;
int RESVal = 0;
int LMSVal = 0;
int LESVal = 0;

void setup()
{
pinMode(RMSPin, INPUT);
pinMode(RESPin, INPUT);
pinMode(LMSPin, INPUT);
pinMode(LESPin, INPUT);
pinMode(LWPin, OUTPUT);
pinMode(RWPin, OUTPUT);
}

void loop()
{
RMSVal = digitalRead(RMSPIN);
RESVal = digitalRead(RESPin);
LMSVal = digitalRead(LMSPin);
LESVal = digitalRead(LESPin);
}

Thank you very much for your fast and efficient replies - i found some errors in capitalization, also in some other parts of the code, and it worked putting the ints outside of the setup. Is there a way i can give you forum-credit for your help and close this thread?

Is there a way i can give you forum-credit for your help and close this thread?

Yes, using the Karma buttons, and no, please don't do that.

If you say so, then i won't. But i'm kind of curious - why not?

If you say so, then i won't. But i'm kind of curious - why not?

You could remove the Reply button, but then if someone want to ask another question, perhaps only tangentially related, they couldn't.

I got the impression, though, that you wanted to remove the whole thread. While it might be embarrassing for you to have asked the question in the first place, you are not the first person to ask the question, and you certainly won't be the last. Leaving the thread in place as searchable material may benefit someone else who searches for "not declared in this scope" (although the thread title is a bit misleading.

You could fix that, and add SOLVED to the end.

You could remove your post(s), but then the rest of the thread looks a little silly. Only moderators can remove whole threads, and they do that rarely.

Ah, i understand. I'll add solved to the end then, thanks for enlightening me.