3x3x3 LED cube with accelerometer

Hello.

Did wan tot ceck if someone can see what is wrong with this code?

const int row[9] = {5,6,7,8,9,10,11,12,13};
const int col[3] = {2,3,4};
const int xpin = A1;
const int ypin = A0;
int x = 0;
int y = 0;

void setup(){
  
  for(int i = 0; i < 9; i++){
    pinMode(row[i], OUTPUT);  
  }
  for(int j = 0; j < 3; j++){
    pinMode(col[j], OUTPUT);
  }
  
  // initialize serial communication:
  Serial.begin(9600);
   pinMode(xpin,INPUT);
   pinMode(ypin,INPUT);
}

void loop() {
  
    x= analogRead(xpin);
    y= analogRead(ypin);
  
  //Center
  if(280 < x <400 && 260 < y < 435){
   //reset all leds
    for(int i=0; i<9; i++){
      digitalWrite(row[i], LOW);
    }
    for(int i=0; i<3; i++){
      digitalWrite(col[i], LOW);
    }
    //Light middle led
    digitalWrite(row[4], HIGH);
  }
  
  //Lean right side  
  if(x > 400 && 260 < y < 435){
    digitalWrite(row[4], LOW);
    digitalWrite(row[8], HIGH);
    digitalWrite(row[7], HIGH);
    digitalWrite(row[6], HIGH);
  }
  //Lean left side
  if(x < 280 && 260 < y < 435){
    digitalWrite(row[4], LOW);
    digitalWrite(row[0], HIGH);
    digitalWrite(row[1], HIGH);
    digitalWrite(row[2], HIGH);
  }
  //Lean forward
  if(y > 400 && 280 < x < 400){
    digitalWrite(row[4], LOW);
    digitalWrite(row[0], HIGH);
    digitalWrite(row[3], HIGH);
    digitalWrite(row[6], HIGH);
  }
  //Lean backwards
  if(y < 280 && 280 < x < 400){
    digitalWrite(row[4], LOW);
    digitalWrite(row[8], HIGH);
    digitalWrite(row[5], HIGH);
    digitalWrite(row[2], HIGH);
  }

    
  /*send x and y cords to process
  Serial.print(x);
  Serial.print(",");
  Serial.println(y);
  x=0;
  y=0; 
  */
}

Nothing happens when i tilt it.

Thx for answers beforehand.

if(280 < x <400 && 260 < y < 435){

Tell us what you think that does.

You have a “Serial.begin”, but don’t use it.
Serial debug is about the most useful tool you have.

AWOL:

if(280 < x <400 && 260 < y < 435){

Tell us what you think that does.

You have a “Serial.begin”, but don’t use it.
Serial debug is about the most useful tool you have.

What it is suppose to do is when the value form the accelermeter is between 280 and 400 for x and 260 and 435 between 1 LEd in middle will ligtht.
Know i am not ussing it will take a close look in the monitor and see if maybe i got the values wrong.

What it is suppose to do is when the value form the accelermeter is between 280 and 400 for x and 260 and 435 between

It doesn’t do that.

if( (x > 280) && (x < 400) && (y > 260) && (y < 435)) (or similar) is probably more like it.

Just because something compiles doesn’t mean it works as you think.

Is only one LED going to be on when tilted, or is it going to look like a tilting square?

Okej thx. Then i know what is wrong.