Strange compiler error

After having saved a newly named version of a slightly altered sketch that properly compiled, the newly saved version no longer compiles, and the bad lines are exactly the same as the previous version,

The error is "expected unqualified - id before numerical constant"

The program starts out by calling the servo library

#include<servo.h>

Second line, that the compiler stops at and says is in error is

servo steerservo

Yet it worked 50 times before??? Was the error caused by something I did I in renaming the sketch and saving it???

The IDE I am using is 1.05 r2

Thanks!

At any time you feel like posting your code, please go ahead.
Don't stand on ceremony, just remember to use code tags.

#include<servo.h>
servo steerservo

Shouldn't that be

#include <Servo.h>
Servo steerservo;

Perhaps it is correct in your code. We will see when you post it.

Here is the code. Thanks so much for helping me on this.

#include <Servo.h>

#define echoPinLeft 7 // Left Echo Pin
#define trigPinLeft 8 // Left Trigger Pin

#define echoPinRight 9 // Right Echo Pin
#define trigPinRight 10 // Right Trigger Pin

//long durationLeft, distanceLeft; // Duration used to calculate distance
//long durationRight, distanceRight; //Right front sensor duration used to calculate distance

//Declare Servos
Servo steerservo; //steering servo
Servo driveservo; //drive servo
const int turntime=0; //number of milliseconds to hold turn when turning
const int turnaroundtime=1000; // number of milliseconds to turn completely around
const int steerservopin=11; //pin number for steering servo
const int driveservopin=12; //pin number for drive servo
const int distancelimit=20; //threshold in inches to initiate reaction
const int pingdelay=50 // milliseconds delay added prior to a ping

//Setup function. Runs once when Arduino starts or is reset

void setup() {
Serial.begin (9600);
steerservo.attach(steerservopin); // attaches the steering servo to its pin 11
driveservo.attach(driveservopin); // attaches the drive servo to its pin 12
delay(1000); // delay one second

}

void loop(){
//go(); // proceed using the go function (disabled to implement only when if else enables)

int distanceleft=pingleft(); // invoke left sensor ping function to look for obstacles left of centre
int distanceright=pingright(); // invoke right sensor ping function to look for obstacles right of centre

Serial.print("Distance Left: ");
Serial.println(distanceleft);
Serial.print("Distance Right: ");
Serial.println(distanceright);

if(distanceleft<distancelimit || distanceright<distancelimit) {

char turndirection=scan(); // Goes to scan function to decide which way to turn based on l,r,s values.
switch (turndirection){
case 'l':
turnleft(turntime);
//delay(turntime);
break; // exits the case
case 'r':
turnright(turntime);
//delay(turntime);
break;
case 's':
turnleft(turnaroundtime);
break;
}
}
else
{
go();
}
}
int pingleft(){
delay(pingdelay); // delay between sensor firing to avoid risk of interference
long durationLeft, inchesLeft, cmLeft;
//Send Left pulse
pinMode(echoPinLeft, INPUT);
pinMode(trigPinLeft, OUTPUT);
digitalWrite(trigPinLeft, LOW);
delayMicroseconds(2);
digitalWrite(trigPinLeft, HIGH);
delayMicroseconds(10);
digitalWrite(trigPinLeft, LOW);
//read left echo
durationLeft=pulseIn(echoPinLeft, HIGH);
// convert the time to distance
inchesLeft=microsecondsToInches(durationLeft);
cmLeft=microsecondsToCentimeters(durationLeft);
Serial.print("Ping Left: ");
Serial.println(inchesLeft);
return round (inchesLeft);
}

int pingright(){
delay(pingdelay); // delay between sensor firing to avoid risk of interference
long durationRight, inchesRight, cmRight;
//Send Right pulse
pinMode(echoPinRight, INPUT);
pinMode(trigPinRight, OUTPUT);
digitalWrite(trigPinRight, LOW);
delayMicroseconds(2);
digitalWrite(trigPinRight, HIGH);
delayMicroseconds(10);
digitalWrite(trigPinRight, LOW);
//read right echo
durationRight=pulseIn(echoPinRight, HIGH);
// convert the time to distance
inchesRight=microsecondsToInches(durationRight);
cmRight=microsecondsToCentimeters(durationRight);
Serial.print("Ping Right: ");
Serial.println(inchesRight);
return round (inchesRight);
} //Driving the servo motors
void go(){
steerservo.write(90); //for now, we don't go anywhere, thus value is 90 for both which is stopped
driveservo.write(120);
Serial.println("Going forward ");
}
void turnleft(int t){
steerservo.write(150);
driveservo.write(90);
delay(turntime);
Serial.println("Turning Left ");
}
void turnright(int t){
steerservo.write(30);
driveservo.write(90);
delay(turntime);
Serial.println("Turning Right ");
}
void stopmotors(){
steerservo.write(90); // 90 is stop
driveservo.write(90);
Serial.println("STOPPED ");
}

char scan(){
int leftscanval, rightscanval;
char choice;

// read left
leftscanval=pingleft();
delay(50);
//read right
rightscanval=pingright();
delay(50);
// The turning decision is made here

if(leftscanval>rightscanval){
choice='l';
}
else if(rightscanval>leftscanval){
choice='r';
}
else{
choice='s';
}
Serial.print("Choice: ");
Serial.println(choice);
return choice;
}
long microsecondsToInches(long microseconds){
return microseconds/74/2;
}
long microsecondsToCentimeters(long microseconds){
return microseconds/29/2;
}

I missed noticing or posting a second line in the error code. As a second line it says"error expected ";" or "," before void

I am still clueless. I can't figure out what changed, and why my earlier versions compiled and ran.

This line is the issue:

const int pingdelay=50  // milliseconds delay added prior to a ping

You're missing a semi-colon

The mangling the IDE does to your sketch is apparently causing the wrong line to be blamed.

Thanks so much to all you took the time to read this and assist. That fixed it.

I am having a great time with this little board. Takes me back to my Vic20 days.

Another thing is you've got two virtually identical ping functions.
Give one of them parameters for the pins, and lose the other one.

I'm playing with staggering the firing of the two ping sensors because they both face forward, and I'm worried that echos from one might interfere with the other.

My objective is to have the robot sense which side the obstacle is crossing its path from, and turn away from the obstacle. I am finding that when I get a clean reading, it responds exactly as it should. However at times the reflection must be either marginal or causing cross interference between the sr-04 units, as it gets erroneous ping distance readings and the robot oscillates left and right.

20Hz update is quite fast - you may be triggering from echoes from greater ranges - try slowing the pings.

However, this doesn't affect the fact that you could lose one of the ping routines.

Edit: Scratch that - I missed the second delay

round (inchesRight)

?

Yes, that round command is not needed. It returns whole numbers regardless.

I'd like some sort of way to filter out spurious readings from the sonic sensors. Averaging might not be good, as the odd time a really high reading comes in that is in the 1000 inch range, when it should be reading around 100 inches to the wall.

How could I take 3 readings and only use the median reading?