const int nodetect=100;
const int fardetect=80;
const int meddetect=60;
const int closedetect=40;
const int veryclosedetect=20;
if (microsecondsToInches >= nodetect){
digitalWrite(ledpin,HIGH);
delay(slowflash);
digitalWrite(ledpin,LOW)
delay(slowflash);
}
if (microsecondsToInches >= fardetect && (microsecondsToInches <= nodetect))
{
digitalWrite(ledpin,HIGH);
delay(medflash);
digitalWrite(ledpin,LOW);
delay(medflash);
}
if (microsecondsToInches >= meddetect && (microsecondsToInches <= fardetect))
{
digitalWrite(ledpin, HIGH);
delay (fastflash);
digitalWrite(ledpin,LOW);
delay(fastflash);
}
if (microsecondsToInches >= closedetect && (microsecondsToInches <= meddetect))
{
digitalWrite(ledpin,HIGH);
delay(superfastflash);
digitalWrite(ledpin,LOW);
delay(superfastflash);
}
if (microsecondsToInches >= veryclosedetect && (microsecondsToInches <= closedetect))
{
digitalWrite(beeppin, HIGH);
delay (superfastflash);
digitalWrite(beeppin,LOW);
delay(superfastflash);
}
All that stuff needs to be inside a function.
You've declared a number of variables inside setup that you never use.
Please use CODE TAGS when posting code, do not use "format for forum" or whatever it is called