Ok, can someone just check my code? (its not perfect) Because the error that states "error: expected '}' before 'else'" keeps appearing! (its on the line indicated by A BUNCH of <<<<<<)
Thanks!
-A
int inches;
int randNumber;
int LM = 10;
int RM = 11;
void setup()
{
Serial.begin(9600);
for(int i = 175; i < 210; i++)
{
analogWrite(RM, i);
analogWrite(LM, i);
delay(200);
}
}
void loop()
{
if(inches < 7)
{
analogWrite(RM,190);
analogWrite(LM,190);
delay(1000);
Serial.println("stopped");
randNumber = random(0,1);
if(randNumber = 0);
{
Serial.println("right activate");
analogWrite(RM, 175);
delay(500);
analogWrite(RM, 190);
}
else <<<<<<<<<<<<<<<<<<<<<<
{
Serial.println("left activate");
analogWrite(LM, 175);
delay(500);
analogWrite(LM, 190);
}
}
else
{
Serial.println("Going forward");
long duration, inches;
pinMode(7, OUTPUT);
digitalWrite(7, LOW);
delayMicroseconds(2);
digitalWrite(7, HIGH);
delayMicroseconds(5);
digitalWrite(7, LOW);
pinMode(7, INPUT);
duration = pulseIn(7, HIGH);
inches = microsecondsToInches(duration);
Serial.println(inches);
analogWrite(RM,170);
analogWrite(LM,170);
}
}
long microsecondsToInches(long microseconds)
{
// According to Parallax's datasheet for the PING))), there are
// 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
// second). This gives the distance travelled by the ping, outbound
// and return, so we divide by 2 to get the distance of the obstacle.
// See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf
return microseconds / 74 / 2;
}