Pages: [1]   Go Down
Author Topic: "RMSVal" was not declared in this slope [SOLVED]  (Read 308 times)
0 Members and 1 Guest are viewing this topic.
Vejle
Offline Offline
Newbie
*
Karma: 1
Posts: 4
I'm studying at Vejle Technical Gymnasium
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:

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!
« Last Edit: April 03, 2013, 12:18:44 pm by Myxfig » Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 548
Posts: 46032
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

USA
Offline Offline
Jr. Member
**
Karma: 2
Posts: 86
If you can't fix it with a hammer, it must be an electrical problem.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Also check use of RMSPin v. RMSPIN
Logged


Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 179
Posts: 8066
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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).

Code:
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);
}
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Vejle
Offline Offline
Newbie
*
Karma: 1
Posts: 4
I'm studying at Vejle Technical Gymnasium
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 548
Posts: 46032
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.
Logged

Vejle
Offline Offline
Newbie
*
Karma: 1
Posts: 4
I'm studying at Vejle Technical Gymnasium
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 548
Posts: 46032
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.
Logged

Vejle
Offline Offline
Newbie
*
Karma: 1
Posts: 4
I'm studying at Vejle Technical Gymnasium
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: