code error plz help

here is the whole code for reference...
#include<Servo.h>

Servo myServo;

int flexPin = A0; // analog input 0

int laserSight = 13; // digital input 13

int openPos = 90;

int lowerPos = 0;

int switchPin = 1; // digital pin 1

//boolean switchOff = false;

int laser = 3; // digital pin 3
void setup(){
myServo.attach(9); // connect myServo to pin digital pin 9

pinMode(laserSight, OUTPUT);

pinMode(switchPin, INPUT);

pinMode(laser, OUTPUT);

Serial.begin(9600);

}

void loop(){

int flexVal = analogRead(flexPin); // creating int called flexVal to store the analogRead of flexPin

Serial.println( "flexVal" );
Serial.println(flexVal);

flexVal = constrain(flexVal, 35, 70);

flexVal = map (flexVal, 35, 70, 0 ,90); // scaling the flexVal from 0 - 1023 down to 0 - 179 for my servos range

Serial.println( "flexVal mapped" );

Serial.println(flexVal);

delay(500);

if (flexVal < 1)
{

delay(500);

myServo.write(openPos);

delay(500);

digitalWrite(laserSight, HIGH);
}

else
{
myServo.write(lowerPos);

digitalWrite(laserSight, LOW);
}

if (flexVal < 1 && switchPin == HIGH);
{
myServo.write(openPos);
delay(1000);
digitalWrite(laser, HIGH);
digitalWrite(laserSight, LOW);
}

else (flexVal > 1 && switchPin == HIGH);
{
myServo.write(lowerPos);
digitalWrite(laser, LOW);
digitalWrite(laserSight, LOW);
}

}
the error is ...

error: 'else' without a previous 'if'

for this segment of code..
if (flexVal < 1 && switchPin == HIGH);
{
myServo.write(openPos);
delay(1000);
digitalWrite(laser, HIGH);
digitalWrite(laserSight, LOW);
}

else (flexVal > 1 && switchPin == HIGH);
{
myServo.write(lowerPos);
digitalWrite(laser, LOW);
digitalWrite(laserSight, LOW);
}

any help with this or suggestions about more effective ways to write this code would be appreciated.. thank you

b-morales91:
any help with this or suggestions about more effective ways to write this code would be appreciated.. thank you

Help with what? You've posted your code, but you haven't said what the problem is. The title indicates there is an error, but you don't post it. Perhaps you should start here:

How to use this forum

actually if you look i wrote

"the error is ...

error: 'else' without a previous 'if'

for this segment of code..
if (flexVal < 1 && switchPin == HIGH);
{
myServo.write(openPos);
delay(1000);
digitalWrite(laser, HIGH);
digitalWrite(laserSight, LOW);
}

else (flexVal > 1 && switchPin == HIGH);
{
myServo.write(lowerPos);
digitalWrite(laser, LOW);
digitalWrite(laserSight, LOW);
}
"

b-morales91:
actually if you look i wrote

"the error is ...

error: 'else' without a previous 'if'

Would have been easier to see if you used code tags.

if (flexVal < 1 && switchPin == HIGH);

If statements generally are not ended with a semicolon.

maybe you should check out

"how to read a forum"...

b-morales91:
maybe you should check out

"how to read a forum"...

Where is that article?

Fixing the above will get rid of the compilation error, but I can already see another error with your logic that is going to present some problems.

alright if you could point it out id appreciate it

b-morales91:
alright if you could point it out id appreciate it

Too busy figuring out how to read forums. I found the article; It's an eye-opener.

lol very funny man wasnt tryin to be a ****...

so no help?

Moderator edit : language

b-morales91:
wasnt tryin to be a ****...

Now we both know that's not true.

so no help?

You're comparing a constant pin number (switchPin) to a constant value (HIGH). Since switchPin will always equal HIGH, you can remove that condition and your if statement would have the same functionality. You're probably looking for digitalRead().

that makes sense thank you

so does this make more sense?

if (flexVal < 1 && digitalRead(switchPin) == HIGH)
{
myServo.write(openPos);
delay(1000);
digitalWrite(laser, HIGH);
digitalWrite(laserSight, LOW);
}

else (flexVal > 1 && digitalRead(switchPin) == HIGH);
{
myServo.write(lowerPos);
digitalWrite(laser, LOW);
digitalWrite(laserSight, LOW);
}[/table]

b-morales91:
so does this make more sense?

What I posted about if statements applies to else statements as well.

about not using a semicolon after them because i tried taking the semicolon out and verifying the code and it said this..

error: expected `;' before '{' token

and highlighted

else (flexVal > 1 && digitalRead(switchPin) == HIGH)
{

else blocks don't have conditions. You're probably looking for else if.

alright thank you