Go Down

Topic: not declared in this scope (Read 1 time) previous topic - next topic

My "setup" and "loop" from "void loop()" and "voidsetup()" aren't bold...
they used to always be whenever i typed them into the ide.

Also now there is an error message saying
"ledOn' was not declared in this scope"

Code: [Select]
int switchPin = 8;
int ledPin = 13;
boolean lastButton = LOW;
boolean ledOn = false;

void setup()
{
  pinMode(switchPin, INPUT);
  pinMode(ledPin, OUTPUT);
}
  void loop()
{
   if(digitalRead(switchPin) == HIGH && lastButton == LOW)
   {
     ledON = !ledON;
    lastButton = HIGH;
   }
   else
   {
     lastButton = digitalRead(switchPin);
   }
   digitalWrite(ledPin,ledON);
}

Coding Badly


Code: [Select]
boolean ledOn = false;
...lower case n

Code: [Select]
     ledON = !ledON;
...
   digitalWrite(ledPin,ledON);

...upper case N

ematson5897

The error message is because you declare it as ledOn, with a lowercase n, but try to use ledON, with an uppercase N.


MarkT

Indeed you have to spell consistently including case to program.  Or use an editor with auto-complete on variable names.
[ I won't respond to messages, use the forum please ]

UKHeliBob


Indeed you have to spell consistently including case to program.  Or use an editor with auto-complete on variable names.

I would be interested in such an editor.  Can you recommend one ?
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

thanks so much to everyone, obviously i am new to miss something like this, but i am just following what all these tutorials tell me to do so i can learn the language. i knew here would be the place to come, any other forum if you ask a simple question they just bash you and give you no answers.. guess i couldve figured it out haha sometimes you need a fresh set of eyes

PaulS

Quote
any other forum if you ask a simple question they just bash you and give you no answers..

If that's what you wanted, why didn't you say so?  8)

glenmcmurchy

Im having a similar problem, however i have checked the capital letters and I can't seem to find why LedOn was not declared in scope. :/

Here is my Code:


int switchPin = 8;
int ledPin = 13;
boolean lastButton = LOW;
boolean currentButton = LOW;
boolean ledOn = false;


void setup ()
{
  pinMode (switchPin, INPUT);
  pinMode (ledPin, OUTPUT);
}

boolean debounce(boolean last)
{
  boolean current = digitalRead(switchPin);
  if (last != current)
  {
    delay(5);
  current = digitalRead(switchPin);
}
return current;
}

void loop ()
{
  currentButton = debounce(lastButton);
  if (lastButton == LOW  && currentButton == HIGH)
  {
    ledOn = !ledOn;
  }
    lastButton = currentButton;
  digitalWrite (ledPin, LedOn);
}

:)

ellinnaj04

Code: [Select]
boolean ledOn = false;
contains small letter 'l' while
you use capital 'L' on
Code: [Select]
    lastButton = currentButton;
  digitalWrite (ledPin, LedOn);

glenmcmurchy

aw god I would have sworn I had checked every inch of it as well! thanks a lot haha :))) :D  :D
:)

ellinnaj04

no problem.. it also happens to me sometimes..

RayLivingston

I would be interested in such an editor.  Can you recommend one ?
Why anyone uses the Arduino IDE is beyond me.  Get AtmelStudio, and get the free VisualMicro plug-in, and you have a modern development environment based on Microfost VisualStudio that works really well.  When you get a compiler error, simply double-click on the error message, and it takes you right to the line that caused the error.  If has "Intellisense", so will auto-complete variabe and function names for you.  It uses the Arduino tools to do the build, so it is 100% compatible with the Arduino IDE.

Regards,
Ray L.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy