Analog Write with 12 LEDs on an Arduino Mega
This example fades 12 LEDs up and the down, one by one, on an Arduino Mega board.
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.
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.
The first of these loops,
moves through each of the LEDS one by one, from the lowest pin to the highest. Before this loop is allowed to move from one pin to the next, two things must be accomplished. First, you brighten the individual LED through these lines of code:
EasyEDA: Ideas for Circuit Design, Innovation for Electronics Access
Free Circuit Design: Schematic – Simulation – PCB Layout – Gerber Viewer
JLCPCB Prototype: Only $2 for 10pcs 10×10cm, 24 hours Quick Turn, DHL Delivery in 3 days