Go Down

Topic: Wall sensing robot code help (Read 1 time) previous topic - next topic

AWOL

In "pingsensor" you have a variable called "duration", but it is local, so is unavailable to the rest of the sketch.
In fact, it seems that "pingsensor" serves no purpose other than reporting a range to the serial monitor.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

gizahuna


In "pingsensor" you have a variable called "duration", but it is local, so is unavailable to the rest of the sketch.
In fact, it seems that "pingsensor" serves no purpose other than reporting a range to the serial monitor.


Isn't the duration the value the says how close the wall the robot is?  I get a lot of the basic programming and get the sensor to an extent.  I built the hot/cold sensor from Make Magazine, but I just can't figure out how to code this?

AWOL

Quote
Isn't the duration the value the says how close the wall the robot is?

It represents the time the echo takes to reach the sensor, so yes, it may be proportional to the distance to a wall, but all you do with it is to convert it to centimetres and inches, and report the value to the serial monitor.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

gizahuna

Based on that...what is the "if" in the if statement.  I guess the variable, correct?

AWOL

I don't understand the question.
Your problem seems to be that you're expecting a variable to have a value between six and nine inclusive, but you never set the value of the variable, so it is always zero.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

PaulS

Code: [Select]
  if (pulseDuration < 10 & pulseDuration > 5)
Where are you assigning pulseDuration a value? Nowhere in pingsensor(). In fact, no where at all, except when it is declared, and initialized to 0.

PeterH

Have you abandoned the thought of following the suggestions in replies 7 and 9?
I only provide help via the forum - please do not contact me for private consultancy.

gizahuna


Have you abandoned the thought of following the suggestions in replies 7 and 9?


I haven't...to be honest, I really don't know what I'm doing with the code.  I get the basics but not how to run the ping sensor.  The specific help I guess I need is how to get the sensor to register a value and then set up an if condition for when it comes close to a wall.

I appreciate the patience with a newb.

Go Up