// Pin definitions
const int xPin = A0; // X-axis of joystick connected to A0
const int yPin = A1; // Y-axis of joystick connected to A1
const int redPin = 9; // Red LED pin
const int bluePin = 10; // Blue LED pin
void setup() {
// Set LED pins as outputs
pinMode(redPin, OUTPUT);
pinMode(bluePin, OUTPUT);
Serial.begin(9600); // For debugging purposes, optional
}
void loop() {
// Read joystick positions
int xValue = analogRead(xPin); // Read X-axis value (0-1023)
int yValue = analogRead(yPin); // Read Y-axis value (0-1023)
// Map joystick values to LED brightness (0-255)
int blueBrightness = map(xValue, 0, 1023, 0, 255);
int redBrightness = map(yValue, 0, 1023, 0, 255);
// Write the mapped brightness values to the LEDs
analogWrite(bluePin, blueBrightness); // Set blue LED brightness
analogWrite(redPin, redBrightness); // Set red LED brightness
// Optional: Print values to Serial Monitor for debugging
Serial.print("Blue Brightness (X-axis): ");
Serial.println(blueBrightness);
Serial.print("Red Brightness (Y-axis): ");
Serial.println(redBrightness);
Serial.println("---");
delay(50); // Small delay to smooth out the readings
}