by Dale Wheat

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

O'Reilly logo

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required