Analog Write with 12 LEDs on an Arduino Mega

Arduino Analog Write with 12 LEDs (1)

This example fades 12 LEDs up and the down, one by one, on an Arduino Mega board.

CircuitArduino Analog Write with 12 LEDs (1)

image developed using Fritzing. For more circuit examples, see the Fritzing project page

Connect the longer, positive legs of (anodes) 12 LEDs to digital pins 2-13 through 220 ohm current limiting resistors. Connect the shorter, negative legs (cathodes) to ground.

Schematic

Arduino Analog Write with 12 LEDs schematic (1)

Code

In the setup() function of the code below, a for() loop is used to assign digital pins 2-13 of the Mega as outputs.

Next, in the loop() function of the program below, a trio of nested for() loops are used.

Leave a Comment

Your email address will not be published. Required fields are marked *