Beyond the Blinking LED: Starting Simply
Listing 8-1 illustrates perhaps the simplest possible Arduino sketch that actually does something useful.
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 the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.