Loading...
Pages: 1 [2]   Go Down
Author Topic: Wall sensing robot code help  (Read 451 times)
0 Members and 1 Guest are viewing this topic.
Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 138
Posts: 19067
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.

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: 138
Posts: 19067
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.

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: 138
Posts: 19067
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.

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 316
Posts: 35519
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
Tesla Member
***
Karma: 89
Posts: 6391
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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
Print
 
Jump to: