[resolved] I just do not understand these output voltages

Hey viewers,
First off thank you for looking at this. I’m sure my problem is simple but due to my early stages in arduino work this one is eluding me. My code is straight forward, I am just trying to make my joystick prove its location by lighting up 4 LEDs. It works, too, the LEDs will light up in the right spot. It wasnt until I added the option of lighting them all on a push button that I realized something was off. My LEDs are significantly brighter on the push button scenario than the Up/Down, Left/Right scenarios. I took it to the DMM and saw that U/D, L/R controls only produced an output voltage of about 4.7mV while the button scenario had an output of 4 something volts. Why? They are all set as outputs each time. Like I said, I assume I am just missing something, so hopefully someone can help.
Heres the code:

 #include <Streaming.h>
 int Up = 2;
 int Down= 4;
 int Left= 3;
 int Right= 5;
 
  
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
  pinMode(Up, OUTPUT);
  pinMode(Down, OUTPUT);
  pinMode(Left, OUTPUT);
  pinMode(Right, OUTPUT);
}
  
void loop() {
  // read the input on analog pin 0:
  int Vx = analogRead(A0);
  int Vy = analogRead(A1);
  int button = analogRead(A2);
  
  if(Vx<510)
    digitalWrite(Left, HIGH);
  
  if(Vx>520)
    digitalWrite(Right, HIGH);

  if(Vy<498)
    digitalWrite(Up, HIGH);
  
  if(Vy>518)
    digitalWrite(Down, HIGH);
    
  if(button==0)
  {
    digitalWrite(Up, HIGH);
    digitalWrite(Down, HIGH);
    digitalWrite(Left, HIGH);
    digitalWrite(Right, HIGH);
  }
  else
  {
    digitalWrite(Up, LOW);
    digitalWrite(Down, LOW);
    digitalWrite(Left, LOW);
    digitalWrite(Right, LOW);
  }
  
  float vx = Vx;    //take out from here
  float vy = Vy;
  float b= button;
  // print out the value you read:
  Serial << "Vx= " << vx << " Vy= " << vy << "button= " << b << endl;
  delay(000);                      //to here, also header isnt needed after this
}

Umm as far as my wiring, I have all inputs going into analog inputs, and all outputs are digital.
Thanks in advance guys, this is really bothering me and I am almost certain its just something small and stupid I have missed.

Cheers, Brady

a schematic and picture might be helpful. what value resistors are you using? its always smart to initialize your inputs as well.

Yes, I think the problem is easy to understand, but I don’t know if is easy to solve.

The problem is that in this portion of code:

  if(Vx<510)
    digitalWrite(Left, HIGH);
  
  if(Vx>520)
    digitalWrite(Right, HIGH);

  if(Vy<498)
    digitalWrite(Up, HIGH);
  
  if(Vy>518)
    digitalWrite(Down, HIGH);

you are turning the LED’s ON if the joystick is in that position.

But in this part of the code:

  else
  {
    digitalWrite(Up, LOW);
    digitalWrite(Down, LOW);
    digitalWrite(Left, LOW);
    digitalWrite(Right, LOW);
  }

you are saying that if the button is not pushed the Arduino must turn OFF that same LED.

Imagine this situation:
Vx = 210
button=1

The Vx=210 will turn ON the Left LED but the else will turn it OFF. So you will end with the LED blinking very fast (unvisible for your eyes) but sowing less brightness.

EDIT: So you must find a way to only turn OFF the LED’s if the button is not pressed (button=1) and you are not in a position that need that the LED is ON. For example:

 #include <Streaming.h>
 int Up = 2;
 int Down= 4;
 int Left= 3;
 int Right= 5;
 
  
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
  pinMode(Up, OUTPUT);
  pinMode(Down, OUTPUT);
  pinMode(Left, OUTPUT);
  pinMode(Right, OUTPUT);
}
  
void loop() {
  // read the input on analog pin 0:
  int Vx = analogRead(A0);
  int Vy = analogRead(A1);
  int button = analogRead(A2);
  
  if(Vx<510 || button==0)
    digitalWrite(Left, HIGH);
  else 
    digitalWrite(Left, LOW);

  if(Vx>520 || button==0)
    digitalWrite(Right, HIGH);
  else 
    digitalWrite(Right, LOW);

  if(Vy<498 || button==0)
    digitalWrite(Up, HIGH);
  else 
    digitalWrite(Up, LOW);
  
  if(Vy>518 || button==0)
    digitalWrite(Down, HIGH);
  else 
    digitalWrite(Down, LOW);
    
  float vx = Vx;    //take out from here
  float vy = Vy;
  float b= button;
  // print out the value you read:
  Serial << "Vx= " << vx << " Vy= " << vy << "button= " << b << endl;
  delay(000);                      //to here, also header isnt needed after this
}

I don’t like the code, but I think it should work.

Seanz, thank you for the interest in helping me. luisilva, thank you very much for this. I missed that concept entirely. Everything works perfectly now, thank you both so much for the interest!
Much thanks, Brady