Help with Code

Salutations All,
I am having trouble with an error message. I am using an Arduino Uno on version 1.6.11. If someone can look over the code, to tell me how to fix it:
const int pingPin = 7;

void setup() {
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);

pinMode(9, OUTPUT);
pinMode(8, OUTPUT);

digitalWrite(9, LOW);
digitalWrite(8, HIGH);

analogWrite(3,200);

digitalWrite(12, HIGH);

}

void loop() {
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);

pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);

inches = microsecondsToInches(duration);

if(inches <12){
digitalWrite(9, HIGH);
delay(100);
digitalWrite(8, LOW);
digitalWrite(13, HIGH);
analogWrite(11, 255);
digitalWrite(9, LOW);
digitalWrite(12, LOW);
analogWrite(3,200);
delay(2000);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);

else{
digitalWrite(12, HIGH);
digitalWrite(9, LOW);
digitalWrite(3,200);
}
delay(100);

}
long microsecondsToInches(long microseconds);
{

}

"Duration" they say is not declared, and I am not sure how to fix it. Any help appreciated!

The easy way would be to declare the duration and inched variables as globals at the start of the program.

However, there are other errors in the program, including the fact that the microsecondsToInches() function has no code in it and has a semi colon where it should not be, and that you have an else clause inside an if clause instead of after it.

Auto Format the code in the IDE and the latter problem should be clearer.

cool, i figured both of those problems out. Now, the first "inches = microsecondsToInches(duration)" comes up as not declared. Can you suggest how to fix that?

Hello,
From a previous post update, i am having trouble with this code:

const int pingPin = 7;

void setup() {

pinMode(12, OUTPUT);
pinMode(13, OUTPUT);

pinMode(9, OUTPUT);
pinMode(8, OUTPUT);

digitalWrite(9, LOW);
digitalWrite(8, HIGH);

analogWrite(3, 200);

digitalWrite(12, HIGH);

}

void loop() {

long duration, inches, cm;

pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);

pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);

inches = microsecondsToInches(duration);

if (inches < 12) {
digitalWrite(9, HIGH);
delay(100);
digitalWrite(8, LOW);
digitalWrite(13, HIGH);
analogWrite(11, 255);
digitalWrite(9, LOW);
digitalWrite(12, LOW);
analogWrite(3, 200);
delay(2000);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);

else {
digitalWrite(12, HIGH);
digitalWrite(9, LOW);
digitalWrite(3, 200);
}
delay(100);

}
long microsecondsToInches(long microseconds)
{
return microseconds / 74 / 2;
}

I am working on a code that utilizes the Ping sensor. Here is the link to the project http://www.instructables.com/id/RC-Car-to-Robot/ .It keeps saying the first "inches = microsecondsToInches(duration);" is not declared. I cannot figure out how to fix this, any suggestions or modifications. Thank you!

This line

long microsecondsToInches(long microseconds)

needs to be at the top of the program - before setup()

...R

Why have you started another thread with the same question ?

Jeez - this is the same question that I just answered in your other Thread. DO NOT DOUBLE POST

...R

Reported to moderator

it worked, thanks a bunch!

ALRIGHT, noted. Not the end of the world. Appreciate the help

Yog1Girl:
Not the end of the world.

Maybe. But as you are hoping to get someone to give his/her time for free to help you doesn't it make sense to make things as easy as possible for the helper?

...R

everything else aside, does anyone have a suggestion as to adding onto the code or the project? http://www.instructables.com/id/RC-Car-to-Robot/

Yog1Girl:
everything else aside, does anyone have a suggestion as to adding onto the code or the project?

Code tags and fewer cross-posts.
I'd also suggest subtracting calls to delay.

oh it works, i am looking for suggestions on adding onto the car, like more sensors and such, and how to code that. what i have on the r/c car is a ping sensor. it basically senses an object in front of it and stops the car.