const int xPin = A0; // Joystick X-axis pin
const int yPin = A1; // Joystick Y-axis pin
const int ledPinX = 9; // LED to represent X-axis movement
const int ledPinY = 10; // LED to represent Y-axis movement
void setup() {
pinMode(ledPinX, OUTPUT); // Set LED pins as output
pinMode(ledPinY, OUTPUT);
}
void loop() {
int xVal = analogRead(xPin); // Read X-axis value
int yVal = analogRead(yPin); // Read Y-axis value
// Map joystick values to LED brightness
int brightnessX = map(xVal, 0, 1023, 0, 255);
int brightnessY = map(yVal, 0, 1023, 0, 255);
// Set LED brightness based on joystick position
analogWrite(ledPinX, brightnessX);
analogWrite(ledPinY, brightnessY);
}