Pages: 1 [2]   Go Down
Author Topic: Wall sensing robot code help  (Read 1117 times)
0 Members and 1 Guest are viewing this topic.
Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 309
Posts: 26495
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

"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.

Offline Offline
Newbie
*
Karma: 0
Posts: 37
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 309
Posts: 26495
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

"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.

Offline Offline
Newbie
*
Karma: 0
Posts: 37
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 309
Posts: 26495
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

"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.

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 638
Posts: 50304
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
  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.
Logged

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12630
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

I only provide help via the forum - please do not contact me for private consultancy.

Offline Offline
Newbie
*
Karma: 0
Posts: 37
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: 1 [2]   Go Up
Jump to: