I have rebuilt this circuit and rewrote the program multiple times and I cannot figure out what is wrong. I am fairly new to arduino and i am attempting to program this joystick to control four LEDs. For some reason all lights are just on unless I connect GND then they all just turn off. I will attach photos of my circuit. Here is the code: please help however you can thank you!
`// joystick pins
const int LRpin = A0;
const int UDpin = A1;
// variables for analog readings
int LR;
int UD;
// neutral readings for calibration
int LR_neutral;
int UD_neutral;
// red, yellow, green, blue LED pins
const int Rpin = 11;
const int Ypin = 10;
const int Gpin = 6;
const int Bpin = 9;
// LED brightnesses
int R;
int Y;
int G;
int B;
const int deadzone=10;
void setup() {
// put your setup code here, to run once:
// Initialize serial communication
Serial.begin(9600);
// get neutral readings for calibration
// make sure you are not touching the joystick when
// the program starts!
LR_neutral = analogRead(LRpin);
UD_neutral = analogRead(UDpin);
}
void loop() {
// put your main code here, to run repeatedly:
// read analog pins
LR = analogRead(LRpin);
UD = analogRead(UDpin);
if(UD>=UD_neutral+deadzone){ // joystick is up
B = 0; // blue LED off
R = map(UD,UD_neutral,1023,0,255);
}
else if(UD<=UD_neutral-deadzone){
R = 0; // red LED off
B = map(UD,UD_neutral,0,0,255);
}
else{
R = 0;
B = 0;
}
if(LR>=LR_neutral+deadzone){ // joystick is up
Y = 0; // blue LED off
G = map(LR,LR_neutral,1023,0,255);
}
else if(LR<=LR_neutral-deadzone){
G = 0; // red LED off
Y = map(LR,LR_neutral,0,0,255);
}
else{
G = 0;
Y = 0;
}
analogWrite(Rpin,R);
analogWrite(Ypin,Y);
analogWrite(Bpin,B);
analogWrite(Gpin,G);
}
`
won't the above result in values for R that are always > 255/2 and for B < 255/2.
you may find very little difference in light intensity except near the extremes.
why not just drive the LEDs On or Off using the joystick. You might also turn each LED On for half a second then Off in setup to verify that they are all wired correctly
Hi everybody thank you for all of the help so far. I attempted to make a schematic of my circuit to make it easier to see, this is my first time making a schematic so i apologize if its not perfect. Thanks again!
the blue wire did come unhooked in that photo. my mistake. the red and black wires in the other photo are actually wired to different places (GND and PWR) see schematic I just uploaded for details thank you!
Serialprint is an excellent tool for debugging.
With this print you can test the reading of your joystick. So you can isolate the problem: is it the joystick, or the led connections...
In your schematic the leds are reversed...
Try to mae as little wire crossings as possible...
Move the board up... above the leds...
Usually inputs (your pots) are on the left. Outputs (your leds) are on the right... mcu in the middle...
How is your joystick wired?
Can you make a picture of the print?
My guess is that both pots share + and -. So you need only 4 wires to connect them.
You might have connected one plus to plus and one plus to minus (=short circuit).
Yes, but rather without the crossing lines.
This is very difficult to follow (even though the circuit is quite easy)...
You have 4 leds. 3 to the left 1 to the right... that is just not communicating they are all connected in the same way...
The joystick is soldered on a blue print (post #1). The print has copper tracks (at the bottom side). Follow the tracks. Make a picture, so we can follow the tracks...