LED's Refuse To Light Up

Hi guys,

I'm quite confused. I've been trying to solve this for quite a while now and have gotten nowhere. The wiring on my breadboard is correct and all the pins are wired correctly.

My serial monitor shows that the joystick is working as it is outputting the x and y values. However, the LED's won't light up. They do work outside of this circuit, as I've tried them all individually.

I'm now wondering if I have missed something blindingly obvious in my code that I can't see as I've been looking at it for so long now!

I am using a MEGA2560 for your reference. No errors are coming up too.

//Program to control what LED lights up in a circle that is controlled by a
//joystick. If the joystick is pressed down, all LEDs flash. Default mode is all
//LEDs are off when the joystick is in a neutral position.

int SW_pin = 2; // Digital pin connected to switch output
int X_pin = 0; // Analog pin connected to X output
int Y_pin = 1; // Analog pin connected to Y output
int N_LED_Pin=4;  // Declaring N_LED_Pin as a variable to pin 
int E_LED_Pin=5;  //  Declaring N_LED_Pin as a variable to pin 
int S_LED_Pin=6; //  Declaring N_LED_Pin as a variable to pin 
int W_LED_Pin=7;  //  Declaring N_LED_Pin as a variable to pin 

void setup() {
  Serial.begin(9600);
  pinMode(SW_pin, INPUT);
  digitalWrite(SW_pin,HIGH);
  pinMode(N_LED_Pin, OUTPUT);
  pinMode(E_LED_Pin, OUTPUT);
  pinMode(S_LED_Pin, OUTPUT);
  pinMode(W_LED_Pin, OUTPUT);
  }

void loop() {
  
if ((analogRead(X_pin)<550) && (analogRead(X_pin)>400) && (analogRead(Y_pin)<550) && (analogRead(Y_pin)>400)) {
  
  analogWrite(N_LED_Pin,0); // Setting N_LED_Pin off
  analogWrite(E_LED_Pin,0); // Setting E_LED_Pin off
  analogWrite(S_LED_Pin,0); // Setting S_LED_Pin off
  analogWrite(W_LED_Pin,0); // Setting W_LED_Pin off
}

if ((analogRead(X_pin)<100) && (analogRead(Y_pin)<550) && (analogRead(Y_pin)>400)) {
  
  analogWrite(N_LED_Pin,100); // Setting the brightness of N_LED_Pin high
  analogWrite(E_LED_Pin,0); // Setting E_LED_Pin off
  analogWrite(S_LED_Pin,0); // Setting S_LED_Pin off
  analogWrite(W_LED_Pin,0); // Setting W_LED_Pin off
}

if ((analogRead(Y_pin)<100) && (analogRead(X_pin)<550) && (analogRead(X_pin)>400)) {
  
  analogWrite(N_LED_Pin,0); // Setting N_LED_Pin off
  analogWrite(E_LED_Pin,100); // Setting the brightness of E_LED_Pin high
  analogWrite(S_LED_Pin,0); // Setting S_LED_Pin off
  analogWrite(W_LED_Pin,0); // Setting W_LED_Pin off
}

if ((analogRead(X_pin)>550) && (analogRead(Y_pin)<550) && (analogRead(Y_pin)>400)) {
  
  analogWrite(N_LED_Pin,0); // Setting N_LED_Pin off
  analogWrite(E_LED_Pin,0); // Setting E_LED_Pin off
  analogWrite(S_LED_Pin,100); // Setting the brightness of S_LED_Pin high
  analogWrite(W_LED_Pin,0); // Setting W_LED_Pin off
}

if ((analogRead(Y_pin)>550) && (analogRead(X_pin)<550) && (analogRead(X_pin)>400)) {
  
  analogWrite(N_LED_Pin,0); // Setting N_LED_Pin off
  analogWrite(E_LED_Pin,0); // Setting E_LED_Pin off
  analogWrite(S_LED_Pin,0); // Setting S_LED_Pin off
  analogWrite(W_LED_Pin,100); // Setting the brightness of W_LED_Pin high
}

if  (digitalRead(SW_pin) == LOW) {
  
  analogWrite(N_LED_Pin,100); // Setting the brightness of N_LED_Pin high
  analogWrite(E_LED_Pin,100); // Setting the brightness of E_LED_Pin high
  analogWrite(S_LED_Pin,100); // Setting the brightness of S_LED_Pin high
  analogWrite(W_LED_Pin,100); // Setting the brightness of W_LED_Pin high
}

Serial.print("Switch:  ");
  Serial.print(digitalRead(SW_pin));
  Serial.print("\n");
  Serial.print("X-axis: ");
  Serial.print(analogRead(X_pin));
  Serial.print("\n");
  Serial.print("Y-axis: ");
  Serial.println(analogRead(Y_pin));
  Serial.print("\n\n");
  delay(1000);


}

What happens if you simply turn the LEDs on, thusly?

analogWrite(N_LED_Pin,255); // Setting the brightness of N_LED_Pin high
  analogWrite(E_LED_Pin,255); // Setting the brightness of E_LED_Pin high
  analogWrite(S_LED_Pin,255); // Setting the brightness of S_LED_Pin high
  analogWrite(W_LED_Pin,255); // Setting the brightness of W_LED_Pin high
}

(pinMode isn't necessary for pins used solely with analogWrite )

Also, instead of

void loop() {
 
if ((analogRead(X_pin)<550) && (analogRead(X_pin)>400) && (analogRead(Y_pin)<550) && (analogRead(Y_pin)>400)) {

try

void loop() 
{
  int xReading = analogRead (X_pin);
  int yReading = analogRead (Y_pin);
if ((xReading<550) && (xReading>400) && (yReading<550) && (yReading>400)) {

etc - read once, compare many

Are all of those pins PWM pins? Why use analogWrite anyway? What values are you actually seeing? Should we just trust you that it's wired correctly?