Beyond the Blinking LED: Starting Simply

Listing 8-1 illustrates perhaps the simplest possible Arduino sketch that actually does something useful.

Listing 8-1. Dimming a Single LED with a Single Arduino Statement

void setup() { } void loop() {   analogWrite(11, analogRead(0) >> 2); }

For this sketch to work properly, you must attach a variable voltage to the first analog input, A0. This is easily accomplished using a potentiometer, whose endpoints are connected to VCC and ground and whose wiper contact (usually but not always the center pin) provides the variable voltage between the two potentials. A 10K linear potentiometer is perfect. Then connect D11 to D13 using a short jumper wire, so the PWM signal on D11 drives the LED that comes standard ...

Get Arduino Internals now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.