// Joystick analog pins
const int VRx = A0; // Horizontal
const int VRy = A1; // Vertical
// RGB LED pins
const int redPin = 8;
const int greenPin = 10;
const int bluePin = 9;
void setup() {
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}
void loop() {
int x = analogRead(VRx);
int y = analogRead(VRy);
// Reset all colors
analogWrite(redPin, 0);
analogWrite(greenPin, 0);
analogWrite(bluePin, 0);
// Direction-based color logic
if (x < 400) {
analogWrite(redPin, 255); // Left → Red
} else if (x > 600) {
analogWrite(greenPin, 255); // Right → Green
} else if (y < 400) {
analogWrite(bluePin, 255); // Up → Blue
} else if (y > 600) {
analogWrite(redPin, 255);
analogWrite(bluePin, 255); // Down → Magenta
}
delay(100);
}