How to control multiple LED's with only one or two pins

If I have somewhere between 6 and 12 led's, is there a clever way to control them with only a pin or two? The led's are 12V, and in my current setup I have 12 dedicated pins which turn on the led's via a transistor. I'm getting an anolog input from a mic and want to make a sort of EQ-looking thing, meaning for any given led that is on, every led beneath it will also be on. Maybe that isn't relevant, but I thought that may give some more circuit-based options.

Thanks for any ideas.

The easiest way is to use a dedicated LED driver chip. TI has many of those (category "signage LED display drivers"), like the TLC5928 for example. It can drive 16 LEDs up to 35 mA each, with a maximum LED supply voltage of 17 V. They're constant current, so you don't need any current limiting resistors.

You can drive tens or hundreds of these chips from only 3 (or 4) pins. If you are already using the SPI interface, it just costs a single pin.

Pieter

So many LEDs can be driven by shift registers of sufficient length or in a matrix. In former times there existed dedicated chips for level indication, but I don't remember any type, and together with a µC they have no advantage over shift registers.

With discrete hardware one might use a 1:16 decoder and add a gate to each output that turns on a LED with either the decoder output or the next higher LED signal. This way a single decoder signal ripples down and turns on all lower-order gates. But a look at the circuit diagram reveals a big decoder chip, size depending on the number of outputs, and an additional gate on each output, summing up to many chips and wires. The only advantage is the low number of control bits, e.g. a 1:16 decoder requires only 4 control bits (controller outputs).

For few outputs ROM chips have been used, which map the address bits into many (4-8) outputs, with arbitrary output patterns. The remaining address bits could be used to select one of multiple patterns, e.g. single LED or lin or log level display, and true/reversed patterns...

A typical shift register requires 3 connections - Data, Clock, and Latch. I've got a project with daisy-chained serially-controlled LED drivers for 48 addressable LEDs.

You can daisy-chain a virtually-unlimited number of driver chips (and use the same 3 wires).

[u]Neopixels[/u] are RGB LED strips that only require 1 data wire. DotStars are similar but they require 2-wires and the programming is simpler (because the timing isn't critical).

I'm trying to go the shift register route. Currently I only have 2 open pins, so I'm trying to figure out which of the existing pins can move over to the shift register, but everything seems like it might have some issues if run through a shift register (i2c lcd screen, weigand card reader, 3x4 keypad, buzzer, and a microphone on an analog pin).

Is it possible to run a matrix keypad off of a shift register, or will that introduce some weird latency issues? My next choice would be the piezo buzzer, but that requires PWM, which I assume would not work across the shift register.

Please post a schematic of your setup.
The things you mention only account for 2+2+7+1+1 = 13 pins, an Arduino UNO has 20 pins.

Keep in mind that analog pins are just digital pins with an additional analog function.

Since you're already using the I2C bus, an I2C port expander or LED driver (do they exist?) might be a solution.

You can drive four of the pins of the keypad matrix using a shift register, but you have to make sure you don't short out anything. Either use an open-collector/drain shift register, or use a keypad with diodes in each switch.

Neopixels are the way to go. Unlimited colors and patterns with only one Arduino pin. 5V only, I'm afraid but that usually isn't a problem if you're only driving 1 to 10 of them.

I have a project with 412 of them. Power wiring is quite important for that but the data is just one wire.

PieterP:
The things you mention only account for 2+2+7+1+1 = 13 pins, an Arduino UNO has 20 pins.

I'm using a pro micro. I'm not sure an uno would fit in my existing enclosure. I'd use a nano, but I need the additional serial port.

/*----------PINS----------*/
// 0, 1, and 4 reserved for network
// 2 and 3 reserved for lcd
const byte wiegand_D0 = 5;
const byte wiegand_D1 = 6;
const byte buzzer = 7;
const byte microphone = 8;
const byte rowPins[4] = {A3, A2, A1, A0};
const byte colPins[3] = {15, 14, 16};
// remaining: 9, 10
/*------------------------*/

PieterP:
Since you're already using the I2C bus, an I2C port expander or LED driver (do they exist?) might be a solution.

You can drive four of the pins of the keypad matrix using a shift register, but you have to make sure you don't short out anything. Either use an open-collector/drain shift register, or use a keypad with diodes in each switch.

I'll look into the port expander next. I wasn't aware it was a thing.

Why only 4 pins for the keypad? Is it because the shift register can't check the row and column for a given key simultaneously?

MorganS:
Neopixels are the way to go.

I have a few of these 12V led bars (this thing, without the blue pcb beneath it) already soldered together with the transistors, and I have the corresponding hole cut out for my led bar thing. If I were starting from scratch I'd look at the neopixels, but I'm a little too far down this road. Plus I've been wanting to learn about shift registers.