PLZ HALP !!!!
i was trying to make a ping sensor work with my duelmilanove, my robot needs a ping sensor for reading distance so i am doing a hello wolrd for ping, i used the inch reader code on arduinos website, and now i am trying to make a pin 13 LED light up when an object gets within 6in of the PING, but my code has a crap load of errors like error 'time wad not declared in this scope, and other crap... if someone is to fix my code and make it work, i will be SUPER happy and i might even send you some paypal cash, and maybe you could even work with my to develop code for my bot, for even more money.... anyway here is my code....
// this constant won't change. It's the pin number
// of the sensor's output:
const int pingPin = 7;
void setup() {
// Pin 13 has an LED connected on most Arduino boards:
pinMode(13, OUTPUT);
}
void loop()
{
// establish variables for duration of the ping,
// and the distance result in inches and centimeters:
long duration, inches ;
// The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);
// The same pin is used to read the signal from the PING))): a HIGH
// pulse whose duration is the time (in microseconds) from the sending
// of the ping to the reception of its echo off of an object.
pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);
inches =time(duration);
long time(long microseconds)
return time / 74 / 2; // divide the time by 2 to get inches, by time i mean the microseconds between the ping sending the sound and reciveing it
}
{
if (inches < 6)
{
digitalWrite(13, HIGH); // set the LED on
}
if (inches > 6)
{
digitalWrite(13, LOW); // sets the LED off
}