Ein Potentiometer bestimmt die Helligkeit einer LED.
/* Poti controls LED brightness
* Controlling the modulation of an LED using a potentiometer (variable resistor)
*/
int potPin = 3; // analog Pin 3 used to connect the potentiometer
int ledPin = 9; // digital Pin 9 for the LED
int val; // variable to read the value from the analog Pin
void setup() {
Serial.begin(9600); // initialize Serial Interface with baud rate of 9600
// remember to set baud rate in Serial Monitor!
pinMode(ledPin, OUTPUT);
}
void loop() {
val = analogRead(potPin); // reads the value of the potentiometer (value between 0 and 1023)
Serial.println(val); // write val to Serial Monitor
val = map(val, 0, 1023, 0, 255); // maps input value to range of LED-pin
analogWrite(ledPin, val); // uses Pulse Width Modulation (PWM) to dim LED
}