Table of Contents
LED Fader with Control
Control the brightness of your LED with a potentiometer (a.k.a. “pot”). The pot works just like the resistor/photoresistor combo we used in the Photo-Blink sketch. This sketch also introduces the map function, which helps make up for the difference between what the analog inputs read (0-1023) and what the PWM pins can put out (0-255).
Breadboard Layout
Code
- led_fader_with_control.ino
int ledPin = 11; int potPin = 0; int brt = 0; void setup() { // put your setup code here, to run once: pinMode(ledPin, OUTPUT); Serial.begin(9600); } void loop() { // put your main code here, to run repeatedly: brt = map(analogRead(potPin), 0, 1023, 0, 255); brt = constrain(brt, 0, 255); Serial.println(brt); analogWrite(ledPin, brt); }
