Pages: 1 [2] 3   Go Down
Author Topic: Arduino, Processing and 2 HC-SR04 Ultrasonic Sensor problems. Please help....  (Read 3633 times)
0 Members and 1 Guest are viewing this topic.
Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 239
Posts: 24373
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Given the missing semicolons, I'm not surprised

(Generally we say something didn't work if it compiled, but didn't perform as expected.
If it didn't even compile we say it didn't compile)
« Last Edit: May 03, 2013, 02:21:00 pm by AWOL » 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.

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

Ok, thanks for letting us know.

How about the missing braces?

Have you read this?
« Last Edit: May 03, 2013, 02:32:17 pm by AWOL » 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.

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

So, it's now compiling - good.
OK, as long as you're happy to keep plugging away at it, it's all cool
If you need any help, be sure to post code.
« Last Edit: May 03, 2013, 02:49:18 pm by AWOL » 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.

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

Code:
if (d1>=dist){
   currentState=currentState +1;

else
    if (d2>=dist){
      currentState=currentState -1;
    }
I'm guessing that the error message (which you didn't post) is something like "else without previous if", which is why I asked about the missing braces.

Please read my earlier definition of working vs. compiling.
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.

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

Something can only be said to work/not work if it actually runs.
It can only run if it compiles, which because of the lack of a closing brace } before the else, your code cannot.
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.

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

Quote
It kind of works now
So, you're saying this
Code:
if (d1>=dist){
   currentState=currentState +1;

else
compiles?
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.

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

Keyhole debugging doesn't work for me.
Is that else clause really empty?
If it is, it doesn't need to be there at all.
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.

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

Quote
I am keep getting error messages.
Let's play "Guess the error message"
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: 549
Posts: 46154
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Let's play "Guess the error message"
I's really not that hard:
Code:
pd1 = nums;
pd2= nums;
int [] nums = int(split(myString, ','));
You can't assign an array to an int. You can't assign an array before you allocate it to anything.

Quote
Hi there I have been trying to create another 2 variables that stores the previous d1 and d2 values in pd1 and pd2
Then, wouldn't:
Code:
pd1 = d1;
pd2 = d2;
make a hell of a lot more sense?
Logged

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

You want us to rewrite Java to make that work? Forget it. pd1 will NEVER be NULL. Don't bother testing for an impossible situation.
Logged

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

Quote
Hi Paul, Please can you help me to get the other sensor "d2) to work.In order to go back to the previous image.
No. I've asked you to put each { on a new line, to use Tools + Auto Format, and to use only a reasonable amount of white space. You have ignored all those requests.

I've suggested, too, that you print() stuff, to understand what is going on.
Logged

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

Quote
Ok now I did the auto format.
But not the curly braces or the print statements.

Or the comparison between pd1 and d1 or between pd2 and d2.

We need to know what the problem is.
Logged

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

Quote
When you say put each { on a new line do you mean put all of them at the bottom sketch or with in each method???

Code:
if(whatever) { // Curly brace in wrong place

if(whatever)
{ // Curly brace on a new line, where it belongs.
Logged

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

Code:
int d1, d2 = 0;
Be careful where you write things like that.
At global scope, it's OK because both variables would be set to zero anyway, unless you specified a different value.
However, with local scope, only d2 would be initialsed, and d1 would pick up whatever junk was left on the stack.
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: 549
Posts: 46154
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
  if  (currentState<displayImage.size())
  {
    image(displayImage.get(currentState), 0, 0);
  }
  if (d1>=dist)
  {
    currentState=currentState +1;
  }
  if (d2>=dist)
  {
    currentState=currentState -1;
  }
Now that the code is arranged in a nice readable fashion, lets talk about what it actually does.

Display an image, and then check to see if that was the right image. I would think that you'd want to do the checking first, and then display the correct image.

I also thought that you were concerned about the current value (d1) vs. the previous value (pd1) (or d2 vs. pd2) somehow.
Logged

Pages: 1 [2] 3   Go Up
Jump to: