All exercises
3. Brightness control (PWM)
Use the potentiometer to change the brightness of the LED on D9.
Task
- 1.Run the program and move the potentiometer slider.
- 2.analogRead() returns 0–1023 and analogWrite() takes 0–255; map() connects them.
- 3.Invert the brightness: the LED is off with the slider at its end.
Code
Tab inserts two spaces. To leave the editor press Esc, then Tab.
Virtual stand
Program not started
| Pin | Part | State |
|---|---|---|
| A0 | Potentiometer | 512 · 2.50 V |
| D9 | Red LED | off |
Serial monitor 9600
The program has not sent anything over Serial yet.