const int potPin = 34; // Pin on està connectat el potenciòmetre
const int ledPin = 13; // Pin on està connectat el LED
int potValue = 0;
int brightness = 0;
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
delay(1000);
}
void loop() {
potValue = analogRead(potPin);
// Mapegem el valor del potenciòmetre (0 a 4095) a un rang de brillantor (0 a 255)
float brightness = map(potValue, 0, 4095, 0, 255);
// Ajustem la brillantor del LED
analogWrite(ledPin, brightness);
// Mostrem el valor del potenciòmetre i la brillantor pel serial monitor
Serial.print("Valor del potenciòmetre: ");
Serial.print(potValue);
Serial.print(" | Brillantor del LED: ");
Serial.println(brightness);
delay(100); // Pausa breu per evitar una lectura massa ràpida del potenciòmetre
}