November 2011
Intermediate to advanced
392 pages
13h 3m
English
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 ...
Read now
Unlock full access