Creating your own LED-array library
We are going to create a very small library and test it with a basic circuit including six LEDs that are not multiplexed.
Wiring six LEDs to the board
Here is the circuit. It basically contains six LEDs wired to Arduino:
The circuit diagram is shown as follows:
I won't discuss the circuit itself, except to mention that I put in a 1 kΩ resistor. I took the worst case where all LEDs would be switched on at the same time. This would drive a lot of current, and so this acts as security for our Arduino. Some authors wouldn't use it. I'd prefer to have some LEDs dimming a bit in order to protect my Arduino.
Creating some nice light patterns
Here is code for lighting up the LEDs according to some patterns, all hardcoded. A pause is made between each pattern display:
void setup() { for (int i = 2 ; i <= 7 ; i++) { pinMode(i, OUTPUT); } } void loop(){ // switch on everything...