Pages: [1]   Go Down
Author Topic: If(predetermined situtation); statement?  (Read 423 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 23
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi. I have a project in which I am reading data from an accelerometer, where certain ranges of X, Y, & Z values correspond to certain scenarios. I then have to check to see if these scenarios are happening using if... statements. Here's an idea of how the code is now, and how I want it to be... (psuedo code)....

NOW:

   if ("value of x" > *insert*     AND     "value of x" < *insert*     AND     "value of y" > *insert*     AND    "value of y" < *insert*)
      {
           DO A BUNCH OF STUFF  }


WANT IT TO BE:

   if (movingForwardRight)
     {
         DO A BUNCH OF STUFF }

  

   movingForwardRight IS WHEN ("value of x" > *insert*     AND     "value of x" < *insert*     AND     "value of y" > *insert*     AND    "value of y" < *insert*)




I didn't really know the best way to word this question, but what is the best way to do something like this ?

Logged

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

Quote
Here's an idea of how the code is now
I'm pretty sure that that code won't compile. Post your real code.

You could create a macro that took several arguments, called movingForwardRight, but I don't recommend that.

Perhaps better would be to break the code down into a moving forward and a moving backward section. Make each section a function. In each section/function, determine if you are/should be moving left or right, and call the appropriate function.

Do the same, in those functions, for up and down, if needed.
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 142
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It looks like you want to set movingForwardRight to true when
Quote
Code:
("value of x" > *insert*     AND     "value of x" < *insert*     AND     "value of y" > *insert*     AND    "value of y" < *insert*)
is true, but what the hell does:
Quote
movingForwardRight IS WHEN
mean?
I think you are wanting from the way you worded that:
Code:
boolean movingForwardRight = FALSE;
if ((x > xx     &&     x < xz)     &&     (y > yy     &&    y < yz))
      {
           movingForwardRight = TRUE;  
     }

if (movingForwardRight){
//TODO
}
but in that case you could scrap off movingForwardRight and just use the condition.
Logged

Finland
Offline Offline
Sr. Member
****
Karma: 1
Posts: 270
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


I think you are wanting from the way you worded that:
Code:
boolean movingForwardRight = FALSE;
if ((x > xx     &&     x < xz)     &&     (y > yy     &&    y < yz))
      {
           movingForwardRight = TRUE;  
     }


Or simply:

Code:
boolean movingForwardRight  = (x > xx     &&     x < xz)     &&     (y > yy     &&    y < yz);
Logged

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

Thanks everyone.. Yeah, the pseudo code I posted was kind of sloppy, and I didn't want to post my real code because the thing is pretty big and had a lot of other stuff. But I saw what you guys said and figured something out. I'll just have the 'if' statement contain all of my needed things, to figure out the situation, and then just do things from there, instead of referencing something else. Got it figured out now.
Logged

Pages: [1]   Go Up
Jump to: