Go Down

Topic: error code PLEASE HELP (Read 533 times) previous topic - next topic

arduinoalan

I have gotten this error code several times and I am not sure what it means. Please help me.

code:

Code: [Select]
int ledpin = 12
int sensor = 0

void setup () {
 pinMode(ledpin, OUTPUT);
 pinMode(sensor, INPUT);
}

void loop()
{
 val = analogRead(sensor);       // self-explanitory
 if val <= 12 {                  // if the area is dark enough,
   digitalWrite(ledpin, HIGH);   // Led will come on
 } else {                        // or,
   digitalWrite(ledpin, LOW);    // it won't do anything
 }
}



the error message at the bottom says:

error: expected unqualified-id before numeric constant In function 'void loop()':
Bad error line: -2


thank you for any help.

Coding Badly

Add semi-colons to these two lines...

Code: [Select]
int ledpin = 12 [glow];[/glow]
int sensor = 0 [glow];[/glow]


arduinoalan

Thank You so much

I had to do a little more and ended up with this.
A program to turn on a light when it is too dark.

Code: [Select]
int ledpin = 12;
int sensor = 2;
int val = 0;

void setup () {
 pinMode(ledpin, OUTPUT);
 pinMode(sensor, INPUT);
}

void loop()
{
 val = analogRead(sensor);       // self-explanitory
 if (val <= 12) {                // if the area is dark enough,
   digitalWrite(ledpin, HIGH);   // Led will come on
 } else {                        // or,
   digitalWrite(ledpin, LOW);    // it won't do anything
 }
}

Go Up