Code help for Ultrasonic Ping Interrupt

I've spent far too many hours trying to get these codes to work.. Can someone please offer some assistant on the Interrupt part?

"'ISR' does not name a type" is my error.

Thanks in advance!

#include <Servo.h>
#define trigPin 7
#define echoPin 6
Servo servo;
int pos = 0;
void setup()
{

Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
servo.attach(8);

cli();// stop interrupts

TCCR1A = 0;// set TCCR1A register to 0
TCCR1B = 0;
TCNT1 = 0; //initialize counter value to 0
//set timer count for 1khz increments
OCR1A = 15624;// = (1610^6) / (10008) - 1
//turn on CTC mode
TCCR1B |= (1 << WGM12);
//set CS12 and CS10 bits for 1024 prescaler
TCCR1B |= (1 << CS12) | (1 << CS10);
//enable timer compare interrupt
TIMSK1 |= (1 << OCIE1A);

sei();//allow interrupts
//END TIMER SETUP
}
ISR{TIMER1_COMPA_vect){
long duration, distance;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
if (distance < 8)

{
Serial.println("the distance is less than 5");
servo.detach();

}
else
{

servo.attach(8);

}
}
void loop()
{

for (pos = 0; pos <= 180; pos += 1) // goes from 0 degrees to 180 degrees
// in steps of 1 degree

{
servo.write(pos);
delay(15);

} // waits 15ms for the servo to reach the position
// waits 15ms for the servo to reach the position

for (pos = 180; pos >= 0; pos -= 1)
{ // goes from 180 degrees to 0 degrees

servo.write(pos);
delay(15);
// tell servo to go to position in variable 'pos'
// waits 15ms for the servo to reach the position
}
}

I've spent far too many hours trying to get these codes to work.. Can someone please offer some assistant on the Interrupt part?

Don't use the interrupt. Why do you feel the need to put an ultra sonic ping every second on a timer compare match interrupt which you are struggling with, when you could have used the basic millis() software timer?

if(millis() - timeOfLastPing >= interval)  //interval is currently set for 1000 ms with Timer interrupt
{ timeOfLastPing += interval;
   // do the ultrasonic thing
}

What Arduino are you using? Servo.h uses a 16 bit timer, and if if you are on one of the AT328 devices, than there is only one of them, Timer1, which you are trying to use for the compare match.

Okok yes I see the problem is "{" -_- derp. The reason I want it to ping every second is to make sure it doesn't miss any objects when it's turning. I'll look into the simpler code and see about removing my delays. Thanks guys!

I'm using the Mega 2560, is this interrupt code not meant for it? Either way I'll try out the suggested code. Thanks again.

Why not use the NewPing library, which handles all the interrupt and timing stuff for you?