I am attempting to create a nine-LED layout. LEDs should all be turned on and off at the same time using a toggle switch.
I am trying to have this sorted by Friday for an astronomy demo (testing mirror alignment). I am creating a flat field for collimating telescopes by connecting fiber optic fibers to the LED's and running the fiber to the flat field.
I am using 5mm Diodi Led, 80 Pezz ulticolor.
Arduino 2560 R3 and breadboard with toggle switch.
It's not required - but that way you need no extra hardware.
As well as the per-pin current limitation, remember that there is also a limit on the total combined current that a chip can take simultaneously through multiple pins...
Yes, and at the same time no. The issue is how much current your particular type(s) of LEDs need, vs how much current a single output pin can sink/source. We generally simplify this to an LED per pin, but it needn't be that restrictive.
LED current - if you don't know the spec for your LED, best to use a selection of resistors and a 9V battery, start at 2 kohm and work down until you have the brightness you desire, then calculate the current. Say it's 4 ma.
Output sink/source - The manufacturer of your particular processor(depends on which Arduino product, or clone) will have a specification for absolute maximum and typical maximum per pin, plus a specification per a set of pins, plus a maximum for the whole device, and all of this typically derated depending on operating temperature. It gets complicated really quickly.
And then, of course, there's the likelihood that tomorrow, you'll decide, well, I really would like to be able to have three LEDs on, then six, then nine. Or some other variation. So easy if you're already driving them individually, otherwise it's rewire time.
So as you can see, "it depends" is about all we can say.
Sorry for the long read, if you even got this far.
Good news is, with the Mega, you're not pin-limited.