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