syntax error?

why this code did not work? is a simple vu meter for a LDR

define LED

define LED 2

define LED 3

int sensorPin = 0; int sensorValue = 0; int ledPin LED = 4; int ledPin LED 2 = 7; int ledPin LED 3 = 8; void setup() { pinMode(LED, OUTPUT) pinMode(LED 2, OUTPUT) pinMode(LED 3, OUTPUT) } void loop() { val = analogRead (0) } if (val == >0) && (val == [ch8804]341){ digitalWrite(LED, HIGH) digitalWrite(LED 2, HIGH) digitalWrite(LED 3, HIGH) } if (val == >341) && (val == [ch8804] 682){ digitalWrite(LED, HIGH) digitalWrite(LED 2, HIGH) digitalWrite(LED 3, LOW) } if (val == > 682) && (val == [ch8804] 1023){ digitalWrite(LED, HIGH) digitalWrite(LED 2, LOW) digitalWrite(LED 3, LOW) }

if (val == >0) && (val == [ch8804]341){

You have too many operators in there. “==” is an operator, as is “>”. You can only have one operator. Perhaps you wanted the “>=” and/or “<=” operators?

thank you :) i have corrected this error but..there're another error

error: stray '\' in program In function 'void setup()': In function 'void loop()': At global scope:

You have way to much going on here to help correct. Especially since i don’t quite understand you ultimate goal with this code. But i can point out some discrepancies in the basic coding.

  • get rid of the #define. its not needed. The int ledPin takes care of that for you

  • The following lines:

int ledPin LED = 4;
int ledPin LED 2 = 7;
int ledPin LED 3 = 8;

should read:

int LED = 4;
int LED2 = 7;
int LED3 = 8;

ledPin is a label. this can be anything you want it to be. Since your using multiple LEDs the labels need to be different so LED, LED2, and LED3 are all that is needed. The space between “LED” and the number should not be there as you can see in the above example.

-you need a “;” after everything.
Example:

void setup() {
 pinMode(LED, OUTPUT);
 pinMode(LED2, OUTPUT);
 pinMode(LED3, OUTPUT);
 }

-With the if statements it should look like this:

if (val >= 0 && val <= 341){
   digitalWrite(LED, HIGH);
   digitalWrite(LED2, HIGH);
   digitalWrite(LED3, HIGH);
   }

-this line:

val = analogRead (0)

should probably read:

val = analogRead(sensorpin)

also the “}” you have at the end designates the end of the loop so that needs to be moved to the end of the program.

Now i’m sure there is allot more troubleshooting that needs to be done. But that is just some of the major errors i could find. You may want to review a few examples to make sure your using things in the right way. I’m just not sure if your using analogRead in the correct way.

thank you so much ;) sorry :-[

To make it easier to follow here is your code with the errors i found corrected.

int sensorPin = 0;
int sensorValue = 0;
int LED = 4;
int LED2 = 7;
int LED3 = 8;
void setup() {
 pinMode(LED, OUTPUT);
 pinMode(LED 2, OUTPUT);
 pinMode(LED 3, OUTPUT);
 }
void loop() {
 val = analogRead (sensorpin)
 
 if (val >= 0 && val <= 341){
   digitalWrite(LED, HIGH);
   digitalWrite(LED 2, HIGH);
   digitalWrite(LED 3, HIGH);
   }
 if (val >= 341 && val <= 682){
   digitalWrite(LED, HIGH);
   digitalWrite(LED 2, HIGH);
   digitalWrite(LED 3, LOW);
   }
 if (val >= 682 && val <= 1023){
   digitalWrite(LED, HIGH);
   digitalWrite(LED 2, LOW);
   digitalWrite(LED 3, LOW);
   }
}

thank you digimike ;)

Crap i mess that up didn’t i. I corrected a couple of things but not all i had in mind at the time.

So here we go again.

int sensorPin = 0;
int sensorValue = 0;
int LED = 4;
int LED2 = 7;
int LED3 = 8;
void setup() {
 pinMode(LED, OUTPUT);
 pinMode(LED2, OUTPUT);
 pinMode(LED3, OUTPUT);
 }
void loop() {
 val = analogRead (sensorpin);

 if (val >= 0 && val <= 341){
   digitalWrite(LED, HIGH);
   digitalWrite(LED2, HIGH);
   digitalWrite(LED3, HIGH);
   }
 if (val >= 341 && val <= 682){
   digitalWrite(LED, HIGH);
   digitalWrite(LED2, HIGH);
   digitalWrite(LED3, LOW);
   }
 if (val >= 682 && val <= 1023){
   digitalWrite(LED, HIGH);
   digitalWrite(LED2, LOW);
   digitalWrite(LED3, LOW);
   }
}