I have built an insect robot read in Arduino Bots and Gadget.
#include <Servo.h>
Servo frontServo;
Servo rearServo;// Servo Motor Initiation
int centerPos = 90;
int frontRightUp = 72;
int frontLeftUp = 108;
int backRightForward = 75;
int backLeftForward = 105;
int walkSpeed = 150;
int centerTurnPos = 81;
int frontTurnRightUp = 63;
int frontTurnLeftUp = 117;
int backTurnRightForward = 66;
int backTurnLeftForward = 96;//Ping Measurement
int pingPin = 4;
long int duration, distanceInches;
long distanceFront=0; //cm
int startAvoidanceDistance=20; //cmlong microsecondsToInches( long microseconds)
{
return microseconds / 74 / 2;
}long microsecondsToCentimeters(long microseconds)
{
return microseconds / 29 / 2;
}long distanceCm(){
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);distanceInches = microsecondsToInches(duration);
return microsecondsToCentimeters(duration);
}void center()
{
frontServo.write(centerPos);
rearServo.write(centerPos);
}void moveForward()
{
frontServo.write(frontRightUp);
rearServo.write(backLeftForward);
delay(125);frontServo.write(centerPos);
rearServo.write(centerPos);
delay(65);frontServo.write(frontLeftUp);
rearServo.write(backRightForward);
delay(125);frontServo.write(centerPos);
rearServo.write(centerPos);
delay(65);
}void moveBackRight();
{
frontServo.write(frontRightUp);
rearServo.write(backRightForward-6);
delay(125);frontServo.write(centerPos);
rearServo.write(centerPos-6);
delay(65);frontServo.write(frontLeftUp+9);
rearServo.write(backLeftForward-6);
delay(125);frontServo.write(centerPos);
rearServo.write(centerPos);
delay(65);
}void moveTurnLeft()
{
frontServo.write(frontTurnRightUp);
rearServo.write(backTurnLeftForward);
delay(125);frontServo.write(centerPos);
rearServo.write(centerPos-6);
delay(65);frontServo.write(frontLeftUp+9);
rearServo.write(backLeftForward-6);
delay(125);frontServo.write(centerPos);
rearServo.write(centerPos);
delay(65);
}void setup()
{
frontServo.attach(2);
rearServo.attach(3);
pinMode(pingPin, OUTPUT);
}void loop()
{
distanceFront=distanceCm();
if (distanceFront > 1){
if (distanceFront<startAvoidanceDistance) {
if(int i=0; i<=8; i++){
moveBackRight();
delay(walkSpeed);
}
for(int i=0; i<=19; i++) {
moveTurnLeft();
delay(walkSpeed);
}
} else {
moveForward();
delay(walkSpeed);
}
}
}
This is the error I get
This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.
Arduino: 1.0.6 (Windows NT (unknown)), Board: "Arduino Duemilanove w/ ATmega328"
InsectRobot:82: error: expected unqualified-id before '{' token
InsectRobot.ino: In function 'void loop()':
InsectRobot:132: error: expected )' before ';' token InsectRobot:132: error: 'i' was not declared in this scope InsectRobot:132: error: expected ;' before ')' token
What am I doing wrong. I have written as the book says. I am using Arduino 1.0.6