#define JOYSTICK_X_PIN 34 // analog pin
#define JOYSTICK_Y_PIN 35 // analog pin
#define LED_PIN 12
int previousBrightness = 0;
void setup() {
Serial.begin(115200);
pinMode(LED_PIN, OUTPUT);
}
void loop() {
// Read the X-axis value of the joystick
int xValue = analogRead(JOYSTICK_X_PIN);
// Read the Y-axis value of the joystick
int yValue = analogRead(JOYSTICK_Y_PIN);
// Map the joystick X-axis value to LED brightness
int xBrightness = map(xValue, 0, 4095, 0, 255);
// Map the joystick Y-axis value to LED brightness
int yBrightness = map(yValue, 0, 4095, 0, 255);
// Calculate the average of X and Y axis brightness
int brightness = (xBrightness + yBrightness) / 2;
// Set the LED brightness
analogWrite(LED_PIN, brightness);
// Print messages indicating brightness change
if (brightness > previousBrightness) {
Serial.println("Increasing brightness");
} else if (brightness < previousBrightness) {
Serial.println("Decreasing brightness");
}
// Update the previous brightness value
previousBrightness = brightness;
// Print the joystick values and brightness to serial monitor
Serial.print("Joystick X-axis Value: ");
Serial.print(xValue);
Serial.print("\tY-axis Value: ");
Serial.print(yValue);
Serial.print("\tXBrightness: ");
Serial.print(xBrightness);
Serial.print("\tYBrightness: ");
Serial.print(yBrightness);
Serial.print("\tBrightness: ");
Serial.println(brightness);
delay(100); // Adjust delay as needed for responsiveness
}