const int buttonPin = 2; // Digital input pin
const int analogOutPin = A1; // Analog output pin
void setup() {
pinMode(buttonPin, INPUT_PULLUP); // Initialize digital pin as an input with internal pull-up resistor
}
void loop() {
int buttonState = digitalRead(buttonPin); // Read the digital input from the button
if (buttonState == LOW) { // Check if the button is pressed
int potValue = analogRead(A1); // Read the analog input from the potentiometer
analogWrite(analogOutPin, potValue / 4); // Set the analog output based on the potentiometer value
} else {
analogWrite(analogOutPin, 0); // Turn off the analog output if the button is not pressed
}
}