Correcting Conflicting Accelerometer Code -lillypad

My project is to make LEDs light up when my accelerometer hits a few specific orientations.
My current code creates conflicting commands, which ultimately causes my LEDs to dim rather than turn off.

I am using the X-axis and Y-axis.

I have three criteria.
OFF when the accelerometer is in any orientation other than what is listed.
ON When the X-axis is tilted up 90-ish degrees (X=560-631)
ON When the Y-axis is rolled left 90-ish degrees (Y=394-426)

The trouble comes when it tries to satisfy those criteria. In order for the LEDs to light when the X-axis is satisfied, the Y-axis reading will then violate the other code I have written for the Y-axis illumination.

Example of conflict: The LED will only light if the X-axis is at X=560-631, but to achieve that reading the Y-axis reaches Y=470-515 which my next piece of code was told to only light when the Y-axis satisfies Y=394-426.

What is the best way to solve this?

Maybe I could write something like "if this.. ignore this.." How would I write that in code language?

MY CODE

int Xval;
int Yval;

int led1 = 11;

int led2 = 10;

int led3 = 9;

int led4 = 3;

int accPin = A3;
int accPin2 = A2;

void setup(){

Serial.begin(9600);

pinMode(led1, OUTPUT);

pinMode(led2, OUTPUT);

pinMode(led3, OUTPUT);

pinMode(led4, OUTPUT);

delay(1000);

Xval = analogRead(accPin);
Yval = analogRead(accPin2);
}

void loop(){

Xval = analogRead(accPin);

digitalWrite(led1, HIGH);

digitalWrite(led4, HIGH);

digitalWrite(led3, HIGH);

digitalWrite(led2, HIGH);

if (Xval < 560){

digitalWrite(led1, LOW);

digitalWrite(led4, LOW);

digitalWrite(led3, LOW);

digitalWrite(led2, LOW);

};

if (Xval > 598){

digitalWrite(led2, HIGH);

digitalWrite(led3, HIGH);

digitalWrite(led1, HIGH);

digitalWrite(led4, HIGH);

};

if (Xval > 631){

digitalWrite(led1, LOW);

digitalWrite(led4, LOW);

digitalWrite(led3, LOW);

digitalWrite(led2, LOW);

};

//y entries

Yval = analogRead(accPin2);

if (Yval < 394){

digitalWrite(led1, LOW);

digitalWrite(led4, LOW);

digitalWrite(led3, LOW);

digitalWrite(led2, LOW);

};

if (Yval > 394){

digitalWrite(led2, HIGH);

digitalWrite(led3, HIGH);

digitalWrite(led1, HIGH);

digitalWrite(led4, HIGH);

};

if (Yval > 426){

digitalWrite(led1, LOW);

digitalWrite(led4, LOW);

digitalWrite(led3, LOW);

digitalWrite(led2, LOW);

};

}

Do not cross post. Cross posting wastes member's time and irritates moderators.

Other thread removed.

You need to get clear in your mind what LEDs need to be on, and when.

Eg. if your X axis is inside the required range, but Y values are outside the range, which LEDs need to be on and which need to be off?

I also think you might find it helpful to learn about if / else statements like

if((Xval >= 560) && (Xval <= 631))
  {
     //set up LEDs this way
  }
else
  {
    //set up LEDs the other way
  };

I also think you might find it helpful to learn about if / else statements like

And, you should learn about functions, and define and call appropriately named functions.

Calling setLEDSToTipped90ishAboutX() will make it abundantly clear what should happen in the function. If something else happens, then the function is wrong OR you called the wrong function for the conditions.

Thanks for the reply's!

Sorry for double posting, I've never really forum'd before. I also have ZERO code experience (yesterday was my first day). I'm trying my best. Thanks for your patience and especially your help!

Your "if and else" advice was exactly what I need! Thanks for writing that example!
I found that || would work perfectly for what I need

if ((Xval > 575) || (Yval < 427)) 

{ 
digitalWrite(led1, HIGH);

digitalWrite(led4, HIGH);

digitalWrite(led3, HIGH);

digitalWrite(led2, HIGH);

} else {

digitalWrite(led1, LOW);

digitalWrite(led4, LOW);

digitalWrite(led3, LOW);

digitalWrite(led2, LOW);
}
}

Thanks again!

Update: Realized how helpful it would be to use the Z-axis! I don't know why I was afraid of it! This really simplified the project!

What I ended up using.

loop(){

if ((Zval < 620))  

//LED flashing sequence

else {

//LED off

Thanks again for all your help! I'm really having a great time learning this!

My next problem is programming it to ignore vibrations, ultimately preventing unwanted triggering.

That post is at Any ideas to make my accelerometer ignore shaking or jolting? - Programming Questions - Arduino Forum