; FIGURE 14:
LED to pin 11
schematic.
; FIGURE 13:
LED to pin 11
drawing.
; Open the Set_LED_brightness sketch, or copy the
following code:
// Set_LED_brightness 3/11/14 int ledPin = 11; // LED connected to PWM pin 11 void setup() { Serial.begin(57600); Serial.println(“Enter 0 to 255 to set LED brighness”); } void loop() { int brightness; if(Serial.available()) { brightness = Serial.parseInt(); // convert input to int analogWrite(ledPin, brightness); // set PWM Serial.print(“Brightness: “); // print the brightness Serial.println(brightness); } }
; FIGURE 15: Set brightness
with Serial Monitor.
Open the serial monitor and set several values
between zero and 255 as shown in Figure 15.
Lab 2: Analog Output to Pulse
an LED — Heartbeat LED.
Parts required:
1 Arduino
In Chapter 3, Lab 2: Timing, Part 2 — Dimming the
1 USB cable
LED, we looked at using the delay timer to dim the LED.
1 Arduino proto shield
That technique is fairly low resolution compared to using
the analog Write() function. In this lab, we will use the LED
setup from Lab 1 and run the Arduino example program.
1 1,000 W resistor
1 LED
However, if we use the analog Write() command, the
dimming is done by the timer/counter peripheral that
controls the PWM on/off timimg of the pin that drives the
Estimated time for this lab: 10 minutes
Check off when complete:
LED. It does this in the background so that it doesn’t
affect the main program.
; Open the Arduino file menu and select
File/Examples/Analog/Fading as shown in Figure 16.
16 May 2014