//this constant wont change. its the pin number
//of the sensors output:
const int pingPin = 7;
Says that there is a error before int
//this constant wont change. its the pin number
//of the sensors output:
const int pingPin = 7;
Says that there is a error before int
Post your code.
In code tags.
I don’t know what code tags are
Show us your current sketch. Please use code tags. Use the </> icon in the posting menu.
[code] Paste sketch here. [/code]
</> //this constant wont change. its the pin number
//of the sensors output:
const int pingPin = 7;
I think you missed the point
Show us all of your current sketch.
Hi,
Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html
then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.
Thanks.. Tom..
LarryD:
I think you missed the pointShow us all of your current sketch.
The sketch is on a different computer
void setup()
//this constant wont change. its the pin number
//of the sensors output:
const int pingPin = 7;
void setup(){
//establish motor direction toggle pins
pinMode(12, OUTPUT); //drive motor - HIGH = forwards and LOW = backwards
pinMode(13, OUTPUT); //turn motor - HIGH = left and LOW = right
//establish motor brake pins
pinMode(9, OUTPUT);//brake (disable)the drive motor
pinMode(8, OUTPUT);//brake (disable) the turn motor
//Turns brake off for drive motor
digitalWrite(9, LOW);
//turns brake on for turn motor
digitalWrite(8, HIGH);
//sets inital speed of drive motor
analogWrite(3,200);
//setsinital direction of drive motor
digitalWrite(12, HIGH);
}
void loop()
{
//establish variables for duration of the ping,
//and the distance result in inches and centimeters:
long duration,inches, cm;
//the PING))) is triggered by a HIGH pulse of 2 or more microseconds.
//Give a short LOW pluse 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 an object.
pinMode(pingPin, INPUT);
duration = pulseIn(pingPin,HIGH);
// convert the time into a distance
inches = microsecondsToInches(duration);
//
//if objects are less than 12 inches away
//the robot reverses and turns to the right
//for 2 seconds
//
if(inches < 12){
//brake drive motor and pause 1/10 second
digitalWrite(9, HIGH);
delay(100);
//
//setting turn motor
//
//turn off brake for turn motor
digitalWrite(8, LOW);
//set turn motor diretion
digitalWrite(13, HIGH);
//activate turn motor
analogWrite(11, 255);
//
//setting drive motor
//
//turn off brake of drive motor
digitalWrite(9, LOW);
//set drive motor backwards direction
digitalWrite(12, LOW);
//activate the drive motor
analogWrite(3, 200);
//backup for 2 seconds
delay(2000);
//
//stopping
//
//brake both motors
digitalWrite(8, HIGH):
digitalWrite(9, HIGH);
}
//
//when nothing is within 12"
//the robot simply drives forwards
//
else{
//
//setting drive motor
//
//set drive motor forward direction
digitalWrite(12, HIGH);
//turn off brake of drive motor
digitalWrite(9, LOW);
//activate drive motor
analogWrite(3, 200);
}
delay(100);
}
long microsecondsToinches(long microseconds)
{
//according to parallaxs datasheet for the PING))), there are
//73.746 microseconds per inch (i.e. sound travels 1130 feet per
//second). This gives the distance travelled by the ping, outbound
//and return, so we divide by 2 to get the distance of those obstacle.
//see: http://www.paralax.com/dl/docs/prod/acc/28015-PING-v1.3pdf
return microseconds /74 / 2;
}
Hi,
You can only have one, void setup().
Remove the first one.
Tom....
Ohhhhh that makes alot of sense thanks a lot
You can only have one setup()
void setup() <-------------------<<<<<< remove this line
//this constant wont change. its the pin number
//of the sensors output:
const int pingPin = 7;
void setup(){
.
.
.
inches = microsecondsToInches(duration); // <------<<< case is not the same microsecondsToinches
.
.
.
digitalWrite(8, HIGH): // <-------<<<< you want ; not :
.
Code works great now thanks a lot everyone
cbhunter:
Code works great now thanks a lot everyone
This is why we need the whole sketch. Errors are often caused by things that are not in the actual snippet where the error is flagged. In this example, there is nothing wrong in itself with having a line that says "void setup()", and so the compiler cant say that it's wrong, but it causes what comes after it in this sketch to be wrong.
It's ok to start a sentence with "My dog Spot was ", but "My dog Spot was into the dark and rainy city strode Batman." can't be parsed, and it's not obvious to a computer which particular part of it is wrong. It just has to stop at the first bit that makes it go "woah", which in this case is 'strode'. You need the whole thing to work out what is going on.
understood thanks a lot