Basic programming question.

Hello, having a seemingly simple problem.

what is wrong with my code?

// auto light switch tutorial from book
const int SensorDark = 500;

// photo cell voltage divider pin
int photocellPin = A0;
// led pin
int LEDPin = 2;

void setup() {
//initionlize the led as out put
pinMode (LEDPin, OUTPUT);

}

void loop()
{

int analogValue;

//read our photocell
analogValue = analogRead(photocellPin);

//the higher the analogValue reading is the darker it is.
//if its at least as dark as our constant “sensor Dark”
//light the LED

if (analogValue < photocellpin)}
{

digitalWrite(LEDPin, HIGH);
}
//other wise turn LDE off
else
{
digitalWrite(LEDPin, LOW);

//wait lms for better quality sensor readings

}
//wait lms for better quality sensor reading

delay(1);
}

error messages
Arduino: 1.6.4 (Mac OS X), Board: “Arduino Uno”

light_switch_from_book.ino: In function ‘void loop()’:
light_switch_from_book:31: error: ‘photocellpin’ was not declared in this scope
light_switch_from_book:31: error: expected primary-expression before ‘}’ token
light_switch_from_book:31: error: expected ‘;’ before ‘}’ token
light_switch_from_book.ino: At global scope:
light_switch_from_book:32: error: expected unqualified-id before ‘{’ token
light_switch_from_book:37: error: expected unqualified-id before ‘else’
light_switch_from_book:46: error: expected constructor, destructor, or type conversion before ‘(’ token
light_switch_from_book:47: error: expected declaration before ‘}’ token
‘photocellpin’ was not declared in this scope

This report would have more information with
“Show verbose output during compilation”
enabled in File > Preferences.

thank you for your help

You declare photocellPin but later use photocellpin. Note that C++ is case sensitive so photocellPin is not the same as photocellpin. Fix that and compile and we can work on the other errors.

edit: the only other error is a stray } after the incorrect photocellpin.

Use code tags to post code ("</>" button).

There are too many right curly braces.

Does this look right to you?
photocellpin)}

Will photocellpin always equal A0 ?

Do you know how to use the </> button that is in the posting menu?

Try this

// auto light switch tutorial from book
const int SensorDark = 500;

// photo cell voltage divider pin
int photocellPin = A0;
// led pin
int LEDPin = 2;

void setup() {
  //initionlize the led as out put
  pinMode (LEDPin, OUTPUT);
 
}

void loop()
{

	  
	 int analogValue;
	 
	 //read our photocell
	 analogValue = analogRead(photocellPin);
	 
	 
	//the higher the analogValue reading is the darker it is.
	//if its at least as dark as our constant "sensor Dark"
	//light the LED

	if (analogValue < SensorDark)
	{

	  digitalWrite(LEDPin, HIGH);
	}
	//other wise turn LDE off
	else
	{
	  digitalWrite(LEDPin, LOW);
	  
	  //wait lms for better quality sensor readings

	}
	//wait lms for better quality sensor reading

	delay(1);
}

Thank you... bhabhah... you know, I haven't coded since Comador 64... been a few years. Looks very familiar. :)

Ok, the code is stable. Now, I copied this from a basic book, project #3. I'm working on getting a solid angle on the programming end. We're building CNC units... off a SmoothieBoard...

Any how, some one mentioned that, I could clean this code up some...

// auto light switch tutorial from book
const int SensorDark = 500;

// photo cell voltage divider pin
int photocellPin = A0;
// led pin
int LEDPin = 2;

void setup() {
//initionlize the led as out put
pinMode (LEDPin, OUTPUT);

}

void loop()
{

int analogValue;

//read our photocell
analogValue = analogRead(photocellPin);

//the higher the analogValue reading is the darker it is.
//if its at least as dark as our constant “sensor Dark”
//light the LED

if (analogValue < photocellPin)
{

digitalWrite(LEDPin, HIGH);
}
//other wise turn LDE off
else
{
digitalWrite(LEDPin, LOW);

//wait lms for better quality sensor readings

}
//wait lms for better quality sensor reading

delay(1);
}

Is there a list that explains how these symbols work?

Hi,
Can you please post a copy of your sketch, using code tags?
They are made with the </> icon in the reply Menu.
See section 7 http://forum.arduino.cc/index.php/topic,148850.0.html

People ask why we point this feature out, it allows us to scroll on the screen and it stops the forum edit program from misinterpreting various text combinations like… :slight_smile: and >:(.
You can go back into you post and insert the code tags.

Thanks …Tom… :slight_smile:

You should also look at the auto format function of the IDE (tools, auto format or ctrl-t). Proper indent makes code easier to read. And limit the blank lines.

Hi,

Is there a list that explains how these symbols work?

At the top of the forum page is a tab called learning, select it and go to reference. It will list the basic C++ commands and how they work. Also if you look at the examlple sketch you have. each // line is a comment line telling you what is happening next.

For example

 //initialize the led as out put
  pinMode (LEDPin, OUTPUT);

Tom..... :)

Cool thank you every one. Oh second time’s a charm, now I understand </>.