ERROR, was not declared in this scope (Trying to make a LCD MENU)

Can someone tell me why I get this error?

menu.ino: In function 'void loop()':
menu:72: error: 'LedPin1S' was not declared in this scope
menu:73: error: 'LedPin1S' was not declared in this scope
menu:86: error: 'LedPin1S' was not declared in this scope
menu:87: error: 'LedPin1S' was not declared in this scope
menu:114: error: 'LedPin2S' was not declared in this scope
menu:115: error: 'LedPin2S' was not declared in this scope
menu:128: error: 'LedPin2S' was not declared in this scope
menu:129: error: 'LedPin2S' was not declared in this scope
menu:154: error: 'LedPin3S' was not declared in this scope
menu:155: error: 'LedPin3S' was not declared in this scope
menu:168: error: 'LedPin3S' was not declared in this scope
menu:169: error: 'LedPin3S' was not declared in this scope
menu:194: error: 'LedPin4S' was not declared in this scope
menu:195: error: 'LedPin4S' was not declared in this scope
menu:208: error: 'LedPin3S' was not declared in this scope
menu:209: error: 'LedPin3S' was not declared in this scope
menu:215: error: 'LedPin1S' was not declared in this scope
menu:216: error: 'LedPin1S' was not declared in this scope
menu:217: error: 'LedPin2S' was not declared in this scope
menu:218: error: 'LedPin2S' was not declared in this scope
menu:219: error: 'LedPin3S' was not declared in this scope
menu:220: error: 'LedPin3S' was not declared in this scope
menu:221: error: 'LedPin4S' was not declared in this scope
menu:222: error: 'LedPin4S' was not declared in this scope

This is the code:

#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);

int  menuPos = 1;
//Ledit
const int ledPin1 = 13;
const int ledPin2 = 14;
const int ledPin3 = 15;
const int ledPin4 = 16;
//LedSetting
int ledPin1S = 0;
int ledPin2S = 0;
int ledPin3S = 0;
int ledPin4S = 0;
//Buttonit
int menuD = 17;
int menuU = 18;
int menuF = 19;
int menuB = 20;
boolean buttonPressed = false;





void setup()


{

 	pinMode(ledPin1, OUTPUT);
	pinMode(ledPin2, OUTPUT);
 	pinMode(ledPin3, OUTPUT);
 	pinMode(ledPin4, OUTPUT);
	pinMode(menuD, INPUT);
	pinMode(menuU, INPUT);
	pinMode(menuF, INPUT);
	pinMode(menuB, INPUT);

	lcd.begin(16, 2); 
 	lcd.print("    LED Menu    ");
	delay(1000);

}

void loop() 
{
	delay(1000);
	if (menuD == LOW && menuU == LOW && menuF == LOW && menuB == LOW) buttonPressed = false;

	if ( menuPos = 1) 
	{
		lcd.clear();
		lcd.print("Led1 Settings  >"), lcd.setCursor(1, 2);	 
		lcd.print("Led2 Settings   ");
		if (buttonPressed == LOW)
			{
			if (menuD == HIGH)  menuPos += 1, buttonPressed = true;
			if (menuF == HIGH)  menuPos +=10, buttonPressed = true;
			if (menuU == HIGH)  menuPos =4, buttonPressed = true;
 			}
	}
	if ( menuPos = 11) 
	{
		lcd.clear();
		lcd.print("ON             >"), lcd.setCursor(1, 2); 
		lcd.print("OFF             ");
		if (buttonPressed == LOW)
			{
			if (menuD == HIGH)   menuPos +=100, buttonPressed = true;
			if (menuF == HIGH && LedPin1S == 1 ) lcd.clear(), lcd.print("LED1 already ON"), buttonPressed = true; 
			if (menuF == HIGH && LedPin1S == 0 ) lcd.clear(), lcd.print("LED1 is now ON") , buttonPressed = true, ledPin1S =1;
	 		if (menuB == HIGH)  menuPos -=10, buttonPressed = true;
			}
	}

		if (  menuPos = 111) 
		{
			lcd.clear();
			lcd.print("OFF            >"), lcd.setCursor(1, 2); 
			lcd.print("ON              ");
			if (buttonPressed == LOW)
				{
				if (menuU == HIGH)   menuPos -=100, buttonPressed = true;
				if (menuF == HIGH && LedPin1S == 1) lcd.clear(), lcd.print("LED1 is now OFF"),  buttonPressed = true, ledPin1S =0;
				if (menuF == HIGH && LedPin1S == 0) lcd.clear(), lcd.print("LED1 already OFF"), buttonPressed = true; 		
				if (menuB == HIGH)  menuPos -=110, buttonPressed = true;
				}
		}



	if ( menuPos = 2) 
	{
		lcd.clear();
		lcd.print("Led2 Settings  >"), lcd.setCursor(1, 2);	 
		lcd.print("Led3 Settings   ");
		if (buttonPressed == LOW)
			{
			if (menuD == HIGH)  menuPos += 1, buttonPressed = true;
			if (menuF == HIGH)  menuPos +=10, buttonPressed = true;
			if (menuU == HIGH)  menuPos -=1, buttonPressed = true;
 			}
	}
		if ( menuPos = 12) 
		{
			lcd.clear();
			lcd.print("ON             >"), lcd.setCursor(1, 2); 
			lcd.print("OFF             ");
			if (buttonPressed == LOW)
				{
				if (menuD == HIGH)   menuPos +=100, buttonPressed = true;
				if (menuF == HIGH && LedPin2S == 1 ) lcd.clear(), lcd.print("LED2 already ON"), buttonPressed = true; 
				if (menuF == HIGH && LedPin2S == 0 ) lcd.clear(), lcd.print("LED2 is now ON"),  buttonPressed = true,  ledPin2S =1;
				if (menuB == HIGH)  menuPos -=10, buttonPressed = true;
				}
		}	

		if (  menuPos = 112) 
		{
			lcd.clear();
			lcd.print("OFF            >"), lcd.setCursor(1, 2); 
			lcd.print("ON              ");
			if (buttonPressed == LOW)
				{
				if (menuU == HIGH)   menuPos -=100, buttonPressed = true;
				if (menuF == HIGH && LedPin2S == 1) lcd.clear(), lcd.print("LED2 is now OFF"),  buttonPressed = true ,ledPin2S =0;
				if (menuF == HIGH && LedPin2S == 0) lcd.clear(), lcd.print("LED2 already OFF"), buttonPressed = true; 		
				if (menuB == HIGH)  menuPos -=110, buttonPressed = true;
				}
		}

	if ( menuPos = 3) 
	{
		lcd.clear();
		lcd.print("Led3 Settings  >"), lcd.setCursor(1, 2);	 
		lcd.print("Led4 Settings   ");
		if (buttonPressed == LOW)
			{
			if (menuD == HIGH)  menuPos += 1, buttonPressed = true;
			if (menuF == HIGH)  menuPos +=10, buttonPressed = true;
			if (menuU == HIGH)  menuPos -=1, buttonPressed = true;
 			}
	}
		if ( menuPos = 13) 
		{
			lcd.clear();
			lcd.print("ON             >"), lcd.setCursor(1, 2); 
			lcd.print("OFF             ");
			if (buttonPressed == LOW)
				{
				if (menuD == HIGH)   menuPos +=100, buttonPressed = true;
				if (menuF == HIGH && LedPin3S == 1 ) lcd.clear(), lcd.print("LED3 already ON"), buttonPressed = true; 
				if (menuF == HIGH && LedPin3S == 0 ) lcd.clear(), lcd.print("LED3 is now ON"),  buttonPressed = true,  ledPin3S =1;
				if (menuB == HIGH)  menuPos -=10, buttonPressed = true;
				}
		}

		if (  menuPos = 113) 
		{
			lcd.clear();
			lcd.print("OFF            >"), lcd.setCursor(1, 2); 
			lcd.print("ON              ");
			if (buttonPressed == LOW)
				{
				if (menuU == HIGH)   menuPos -=100, buttonPressed = true;
				if (menuF == HIGH && LedPin3S == 1) lcd.clear(), lcd.print("LED3 is now OFF"),  buttonPressed = true ,ledPin3S =0;
				if (menuF == HIGH && LedPin3S == 0) lcd.clear(), lcd.print("LED3 already OFF"), buttonPressed = true; 		
				if (menuB == HIGH)  menuPos -=110, buttonPressed = true;
				}
		}


	

	if (LedPin1S = 1)digitalWrite(ledPin1 , HIGH);
	if (LedPin1S = 0)digitalWrite(ledPin1 , LOW);

I’m also wondering how to use functions
I read http://arduino.cc/en/Reference/FunctionDeclaration but still don’t understand exactly how it works

If I want to tidy up:

	{
		lcd.clear()
		lcd.print("Led1 Settings  >"), lcd.setCursor(1, 2);	 
		lcd.print("Led2 Settings   ");
		if (buttonPressed == LOW)
			{
			if (menuD == HIGH)  menuPos += 1, buttonPressed == HIGH;
			if (menuF == HIGH)  menuPos +=10, buttonPressed == HIGH;
			if (menuU == HIGH)  menuPos =4, buttonPressed == HIGH;
 			}
	}

would i do this:

void Menu1 (char firstline[],char secondline[])
	{
		lcd.clear()
		lcd.print("firstline"), lcd.setCursor(1, 2);	 
		lcd.print("secondline");
		if (buttonPressed == LOW)
			{
			if (menuD == HIGH)  menuPos += 1, buttonPressed == HIGH;
			if (menuF == HIGH)  menuPos +=10, buttonPressed == HIGH;
			if (menuU == HIGH)  menuPos =4, buttonPressed == HIGH;
 			}
	}
}

And use it like this:

Menu1 (Led1 Settings >, Led2 Settings )

And what about this one:

{
		lcd.clear()
		lcd.print("ON             >"), lcd.setCursor(1, 2); 
		lcd.print("OFF             ");
		if (buttonPressed == LOW)
			{
			if (menuD == HIGH)   menuPos +=100, buttonPressed == HIGH;
			if (menuF == HIGH && LedPin1S = 1 ) lcd.clear(), lcd.print("LED1 already ON"), buttonPressed == HIGH; 
			if (menuF == HIGH && LedPin1S = 0 ) lcd.clear(), lcd.print("LED1 is now ON") , buttonPressed == HIGH, ledPin1S +=1;
			if (menuB == HIGH)  menuPos -=10, buttonPressed == HIGH;
			}
	}

Theres is a lot of variables like:
“ON >”
"OFF "
LedPin1S
“LED1 already ON”

Oh, and I know there’s a shit load of IF in this code, and I should tidy it at least with some ELSE IF but I’m not actually hoping to make anything yet, just to learn something…
Am I at all on the right track here? I could use SWITCH but I don’t know how it works, IF is so simple :slight_smile:
Ps. had to cut code, message to long(over9500)

menu:72: error: 'LedPin1S' was not declared in this scope
int ledPin1S = 0;

Variables are case sensitive.

I’m also wondering how to use functions

void Menu1 (char firstline[],char secondline[])
	{
		lcd.clear()
		lcd.print("firstline"), lcd.setCursor(1, 2);	 
		lcd.print("secondline");

Variables don’t have quotes surrounding them

And use it like this:

Menu1 (Led1 Settings  >, Led2 Settings   )

What do you think the ‘>’ is doing? strings like “Led1 Settings” should be surrounded with quotes. It seems as though you are mixing up what gets surrounded with quotes.

And what about this one:

Theres is a lot of variables like:
"ON             >"
"OFF             "
"LED1 already ON"

Those aren’t variables, those are constant strings.

Arrch: menu:72: error: 'LedPin1S' was not declared in this scope

int ledPin1S = 0;

Variables are case sensitive.

Oh, stupid me, fixed it and all good now, THANK YOU

What do you think the '>' is doing?

I'm trying to print on a 2x16 lcd:

ON > OFF

And when you scroll down the next thing to print would be:

OFF > ON

The ">" is trying to point to what would happen if you press forward in the first case LED would go ON in the second case LED would go OFF

Those aren't variables, those are constant strings.

So how would I do this? I want it to print different menu_text's and do things to different int values.

Samba: I'm trying to print on a 2x16 lcd:

ON > OFF

And when you scroll down the next thing to print would be:

OFF > ON

So constant strings should be surrounded by quotes. Variables shouldn't. Here's is a quick example:

// function declaration
void debugPrint(char *label, char *value)
{
  Serial.print(labal);
  Serial.print(" = [");
  Serial.print(value);
  Serial.println("]");
}

// later in the code when you want to call it:
char someValue[] = "True";
debugPrint("The Value in someValue", someValue);

In the Serial monitor, we would see:

The Value in someValue = [True]

Take not of when double quotes are appropriate.

Thank you Arrch for your reply,I might just understand now :) So did I get it right: To get this code:

{
        lcd.clear()
        lcd.print("ON"), 
        lcd.setCursor(16, 1),lcd.print(">");
        lcd.setCursor(1, 2); 
        lcd.print("OFF");
        if (buttonPressed == LOW)
            {
            if (menuD == HIGH)   menuPos +=100, buttonPressed == HIGH;
            if (menuF == HIGH && LedPin1S = 1 ) lcd.clear(), lcd.print("LED1 already ON"), buttonPressed == HIGH; 
            if (menuF == HIGH && LedPin1S = 0 ) lcd.clear(), lcd.print("LED1 is now ON") , buttonPressed == HIGH, LedPin1S +=1;
            if (menuB == HIGH)  menuPos -=10, buttonPressed == HIGH;
            }
    }

I would make a function like this:

void menuLedOn (char *line1, char *line2, char *whatled, int ledpinSet) //(LCD line 1,LCD line2, Led name, Led setting value)
{
        lcd.clear()
        lcd.print("line1"), 
        lcd.setCursor(16, 1),lcd.print(">");
        lcd.setCursor(1, 2); 
        lcd.print("line2");
        if (buttonPressed == LOW)
            {
            if (menuD == HIGH)   menuPos +=100, buttonPressed == HIGH;
            if (menuF == HIGH && ledpinSet = 1 ) lcd.clear(), lcd.print(whatled) , lcd.print(" already ON"), buttonPressed == HIGH; 
            if (menuF == HIGH && ledpinSet = 0 ) lcd.clear(), lcd.print(whatled) ,lcd.print(" is now ON") , buttonPressed == HIGH, ledpinSet +=1;
            if (menuB == HIGH)  menuPos -=10, buttonPressed == HIGH;
            }
    }

And call it like this:

menuLedOn (ON, OFF, LED1, LedPin1S)

Did I get the [u]int ledpinSet[/u] part right, I'm trying to get the function to affect a different int depending on the menu position

So did I get it right:

Nope. When you surround text in quotes before passing it to something like lcd.print, you're telling the compiler that you want the text in between the quotes to be printed:

char line1[] = "hamster"
lcd.print("line1"); // will print "line1" to lcd
lcd.print(line1); // will print "hamster" to lcd

So when you make a call like this:

menuLedOn (ON, OFF, LED1, LedPin1S)

LED1 must be a declared variable somewhere.

Sorry about the lcd.print("line1"), that was a "typo", I know that it should of been lcd.print(line1) Why does

LED1 must be a declared variable somewhere.

I just want to lcd.print the [u]word[/u] LED1 and lcd.print(" already ON") to get: "LED1 already ON"

About: char line1[] = "hamster"

So I need to do this to all the text I want to print?

If I have a menu like

"Led1 Settings"----------------------------------------------"ON" "Led2 Settings"--------------------------------------"ON" "OFF" "Led3 Settings"---------------------------"ON" "OFF" "Led4 Settings"-----------------"ON" "OFF" "OFF"[/table] Do i need to do a char somewhere for all of them? Like

char line1[] = "Led1 Settings"
char line2[] = "Led2 Settings"
char line3[] = "Led3 Settings"
char line4[] = "Led4 Settings"
char ?????[] = "ON"
char ?????[] = "OFF"

And if I do have to do that, wont the Function: void menuLedOn (char *line1, char *line2, char *whatled, int ledpinSet) only work when I want to print: "Led1 Settings" "Led2 Settings" How would I print: "Led3 Settings" "Led4 Settings"

I don't think I understanding this...

Samba: I just want to lcd.print the [u]word[/u] LED1

Then surround LED with quotes. If it is not surrounded by quotes, the compiler will look for a variable with that name.

So I need to do this to all the text I want to print?

No, that was just an example. Like this:

char line1[] = "hamster";
lcd.print(line1);
lcd.print("hamster");

These two blocks of code will produce the same result on the lcd.

Do i need to do a char somewhere for all of them?

Either that, or you use constant strings:

menuLedOn ("something", "something else", "Led1", 1);

Here's another simple example:

void sentence(char *animal, char *action, int times)
{
  Serial.print("The ");
  Serial.print(animal);
  Serial.print(" ");
  Serial.print(action);
  Serial.print(" ");
  Serial.print(times);
  Serial.print(" time(s)");
}

Given this block of code, you could print out different sentences using different arguments:

sentence("dog", "licks", 8); // The dog licks 8 time(s)
sentence("cat", "purrs", 1); // The cat purrs 1 time(s)

Dam, I'm still not getting it... Arrch, I hope you don't lose your patience w/ me...

Question:

if (pressbutton1 == HIGH && lightsensor1 == 56) ledpin1 = HIGH, analogoutpin1 =12, serial.Print("button 1 is pressed and Led1 is on"); if (pressbutton2 == HIGH && lightsensor2 == 67) ledpin2 = HIGH, analogoutpin2 =34, serial.Print("button 2 is pressed and Led2 is on");

if (xxxxxxxxxxx == HIGH && wwwwwww == rr) yyyyyyy = HIGH, ffffffffffffffff =dd, serial.Print("zzzzzzzz is pressed and qqqq is on");

How would do a Function for this? Not even sure if this is a valid question

if (pressbutton1 == HIGH && lightsensor1 == 56) ledpin1 = HIGH, analogoutpin1 =12, serial.Print("button 1 is pressed and Led1 is on");

Can I persuade you that you never saw the comma in a C program? I know you did, but they don't act like you think. Use the semicolon to separate, and braces to group.

if (pressbutton1 == HIGH && lightsensor1 == 56) 
{
  ledpin1 = HIGH;
  analogoutpin1 =12;
  Serial.Print("button 1 is pressed and Led1 is on");
}

Well, first you have to identify which of the variables you are trying to change, and which you are just need the value from. That will affect how the variable is passed, be it by value or by reference.

If you were to take the lines as you posted them, yyyyyyy and fffffff would need to be passed by reference because you are changing the values. However, based on the examples you gave, I get the feeling you should be using digitalWrite() and analogWrite() with yyyyyyy and fffffff instead, which would make it a pass by value scenario. I would start with a very simple sketch to get a function working before your try to incorporate it into your main sketch. This will give you a better environment to learn how the code works.

Also, what AWOL said about commas.

Oh, I didn't know that. I just feel like the code is easier to read and its more compact. I'll correct my self:

Dam, I'm still not getting it... Arrch, I hope you don't lose your patience w/ me...

Question:

if (pressbutton1 == HIGH && lightsensor1 == 56) 
{
ledpin1 = HIGH;
analogoutpin1 =12;
serial.Print("button 1 is pressed and Led1 is on");
}
if (pressbutton2 == HIGH && lightsensor2 == 67) 
{
ledpin2 = HIGH;
analogoutpin2 =34;
serial.Print("button 2 is pressed and Led2 is on");
}
if (xxxxxxxxxxx == HIGH && wwwwwww == rr) 
{yyyyyyy = HIGH; 
ffffffffffffffff =dd; 
serial.Print("zzzzzzzz is pressed and qqqq is on");
}

How would do a Function for this? Not even sure if this is a valid question

Samba:
How would do a Function for this?

Start by addressing the concerns laid out in my previous response.

lightsensor1 == 56

I've lost sight of the original code (hint), but if the "lightsensor" value is the result of an analogRead, it's a bad idea to look for an exact comparison. Better to look for an absolute difference between the value and the threshold of less than, say 5 (or whatever)

I'm trying to make a function for:

{
            lcd.clear();
            lcd.print("OFF            >"), lcd.setCursor(1, 2); 
            lcd.print("ON              ");
            if (buttonPressed == LOW)
                {
                if (menuU == HIGH)   menuPos -=100, buttonPressed = true;
                if (menuF == HIGH && LedPin1S == 1) lcd.clear(), lcd.print("LED1 is now OFF"),  buttonPressed = true, LedPin1S =0;
                if (menuF == HIGH && LedPin1S == 0) lcd.clear(), lcd.print("LED1 already OFF"), buttonPressed = true;       
                if (menuB == HIGH)  menuPos -=110, buttonPressed = true;
                }
        }

and

{
            lcd.clear();
            lcd.print("OFF            >"), lcd.setCursor(1, 2); 
            lcd.print("ON              ");
            if (buttonPressed == LOW)
                {
                if (menuU == HIGH)   menuPos -=100, buttonPressed = true;
                if (menuF == HIGH && LedPin2S == 1) lcd.clear(), lcd.print("LED2 is now OFF"),  buttonPressed = true ,LedPin2S =0;
                if (menuF == HIGH && LedPin2S == 0) lcd.clear(), lcd.print("LED2 already OFF"), buttonPressed = true;       
                if (menuB == HIGH)  menuPos -=110, buttonPressed = true;
                }
        }

I think I would be

passed by reference because you are changing the values.

This is a option in the menu I was speaking about earlier LedPin1S and 2 are not boolean, I want them to be able to be 3,4,5 and so on, for more settings like blink, fade...

In the end I could do things with the LedPin1S and 2 like:

if (LedPin1S == 1)digitalWrite(ledPin1 , HIGH);
    if (LedPin1S == 0)digitalWrite(ledPin1 , LOW);
if (LedPin2S == 1)digitalWrite(ledPin2 , HIGH);
    if (LedPin2 == 0)digitalWrite(ledPin2 , LOW);

EDIT: I should add that

//Led
const int ledPin1 = 13;
const int ledPin2 = 14;

//LedSetting
int ledPin1S = 0;
int ledPin2S = 0;

//Button
int menuD = 17;
int menuU = 18;
int menuF = 19;
int menuB = 20;
boolean buttonPressed = false;

and

        pinMode(ledPin1, OUTPUT);
    pinMode(ledPin2, OUTPUT);

    pinMode(menuD, INPUT);
    pinMode(menuU, INPUT);
    pinMode(menuF, INPUT);
    pinMode(menuB, INPUT);
if (buttonPressed == LOW)
				{
				if (menuU == HIGH)   menuPos -=100, buttonPressed = true;
				if (menuF == HIGH && LedPin2S == 1) lcd.clear(), lcd.print("LED2 is now OFF"),  buttonPressed = true ,LedPin2S =0;
				if (menuF == HIGH && LedPin2S == 0) lcd.clear(), lcd.print("LED2 already OFF"), buttonPressed = true; 		
				if (menuB == HIGH)  menuPos -=110, buttonPressed = true;
				}

You’ve still got that comma thing going on.
Fix it, then we can talk.

That was actually copied from my first post before you corrected me in my ways

{
    lcd.clear();
    lcd.print("OFF            >");
        lcd.setCursor(1, 2); 
    lcd.print("ON              ");

        if (buttonPressed == LOW)
                {
                    if (menuU == HIGH)
                                    {
                        menuPos -=100;
                                        buttonPressed = true;
                    }

                    if (menuF == HIGH && LedPin1S == 1) 
                                    {   
                        lcd.clear();
                                        lcd.print("LED1 is now OFF");
                                       buttonPressed = true;
                                           LedPin1S =0;
                    }

                    if (menuF == HIGH && LedPin1S == 0)
                                    { 
                        lcd.clear();
                                       lcd.print("LED1 already OFF");
                                       buttonPressed = true;}      

                    if (menuB == HIGH)  
                                    {
                        menuPos -=110;
                                           buttonPressed = true;}
                    }
}
        [\code]

That was actually copied from my first post before you corrected me in my ways

No, it was actually copied from reply #14.

AWOL:

That was actually copied from my first post before you corrected me in my ways

No, it was actually copied from reply #14.

OK, I stand corrected, but still as lost on Functions as earlier