40 leds, specific leds turn on at the same time

Hi I am doing a project and I have 40 leds, I need to turn on 20 at same time and those 20 may vary after one minute and some calculation. Once leds 1,4,6,9 .... later 4,20,30,32 ..... I have few multiplexers 4051 and I know how to turn on specific LEDs but not at the same time, I was thinking to do it in a sequence and with minimum delay. I want to know if this is a good way to do it or there is a better option and if I need resistors, transistors or something different to the multiplexer. I have read about MAX7219 but I don't understand how it works. This is my second proyect in arduino so I'm know only few things , my first one was read data from 20 sensors with multiplexer but in that project didn't need to read everything at once

Hi,

A MAX7219 would make life easier for you. Up to 64 LEDs and no need for transistors or resistors (well, ok, one resistor). Try google for examples of its use. In brief, you connect your LEDs up in a matrix. Physically it can be any shape you like but electrically it needs to be wired up as a matrix. What layout do you want your LEDs to be in? What is the purpose of the LEDs?

To control the LEDs from the Arduino, you need to connect 3 outputs to the MAX7219. There is a library called the "LED Control Library" that will help you control the LEDs individually.

Paul

I have a little board that makes interfacing to the MAX7219 pretty easy. You can connectorize your LEDs even for ease in spacing them out. http://www.crossroadsfencing.com/BobuinoRev17/ Demo of 8 LEDs blinking http://www.crossroadsfencing.com/BobuinoRev17/MAX7219demo_movie.AVI

But with MAX7219 can I turn on specific leds at same time ??

Well, I read the data from the sensors, do some calculations and then according to the results obtained I turn on specific leds. leds are connected from the board to a model, then no matter the electrical design.

CrossRoads : Thanks for then example , but i still not know if with this I can turn on specif leds at the same time or a solution is doing the sequence with a minimun delay.

MAX7219 has 8 registers, each representing the state of 8 LEDs. To write a register:

digitalWrite (ssPin, LOW);
SPI.transfer(register1); // register1 address, happens to be 0x01
SPI.transfer(data1); // data for column 1
digitalWrite (ssPIN, HIGH);

Want 1 LED? data1 = 0b00000001 Want 2 other LEDs? data1 = 0b01000100 Want 3 other LEDs? data1 = 0b10011000 Don't over think it.

If the registers are in diffent columns, then do multiple transfers.

digitalWrite (ssPin, LOW);
SPI.transfer(register1); // register1 address, happens to be 0x01
SPI.transfer(data1); // data for column 1
digitalWrite (ssPIN, HIGH);
digitalWrite (ssPin, LOW);
SPI.transfer(register2); // register1 address, happens to be 0x01
SPI.transfer(data2); // data for column 1
digitalWrite (ssPIN, HIGH);
digitalWrite (ssPin, LOW);
SPI.transfer(register3); // register1 address, happens to be 0x01
SPI.transfer(data3); // data for column 1
digitalWrite (ssPIN, HIGH);
digitalWrite (ssPin, LOW);
SPI.transfer(register4); // register1 address, happens to be 0x01
SPI.transfer(data4); // data for column 1
digitalWrite (ssPIN, HIGH);
digitalWrite (ssPin, LOW);
SPI.transfer(register5); // register1 address, happens to be 0x01
SPI.transfer(data5); // data for column 1
digitalWrite (ssPIN, HIGH);
digitalWrite (ssPin, LOW);
SPI.transfer(register6); // register1 address, happens to be 0x01
SPI.transfer(data6); // data for column 1
digitalWrite (ssPIN, HIGH);
digitalWrite (ssPin, LOW);
SPI.transfer(register7); // register1 address, happens to be 0x01
SPI.transfer(data7); // data for column 1
digitalWrite (ssPIN, HIGH);
digitalWrite (ssPin, LOW);
SPI.transfer(register8); // register1 address, happens to be 0x01
SPI.transfer(data8); // data for column 1
digitalWrite (ssPIN, HIGH);

The transfers happens in like tens of microseconds, to the eye it appears to be simultaneous. Example: http://www.youtube.com/watch?v=hwYqgyMc5S4 These 32 columns are all updated at one time every 100mS or similar, you're not seeing the data ripple across the "screen", are you? I've had it running at 40-50mS, much faster and it gets hard to read as it goes by too fast.

This seems to be what I need, I'll try that. Thanks