#define LED_PIN 9
#define POT_PIN A0
#define STOP_BUTTON 2
#define DEBOUNCE_DELAY 50
void setup() {
pinMode(LED_PIN, OUTPUT);
pinMode(STOP_BUTTON, INPUT_PULLUP);
Serial.begin(9600);
}
void loop() {
if (digitalRead(STOP_BUTTON) == LOW) {
analogWrite(LED_PIN, 0);
Serial.println("LED oprit instant!");
delay(DEBOUNCE_DELAY);
while (digitalRead(STOP_BUTTON) == LOW);
return;
}
int potValue = analogRead(POT_PIN);
int pwmValue = map(potValue, 0, 1023, 0, 255);
analogWrite(LED_PIN, pwmValue);
Serial.print("Luminozitate PWM: ");
Serial.print(pwmValue);
Serial.print(" (");
Serial.print((pwmValue * 100) / 255);
Serial.println("%)");
delay(100);
}