NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Microcontroller Programming » LED all at once

August 30, 2010
by Pr0ject
Pr0ject's Avatar

I'm making a project where the LED lights "dance" but I need them all to work at once, but all I'm able to do is so one lights up then closes then another and so on. So I've been wondering is there a way to get them to light up at the same time?

August 30, 2010
by Ralphxyz
Ralphxyz's Avatar

Short answer, yes.

If you are lighting the LED's from the MCU there is a limit as to how many LED's you could "light" at one time.

You might need to do a POV (persistance of vision) trick and flash the LED's so fast your eye will think they are on all of the time.

Check out the NerdKit LED Array to get some ideas and of course search for POV also search the Nerdkit forum for "traffic light" to get some more ideas about lighting LEDS.

Ralph

August 30, 2010
by Pr0ject
Pr0ject's Avatar

Thank you very much.

About that trick and flash thing, anything under 200 millisecond will work?

August 31, 2010
by hapshetsut
hapshetsut's Avatar

You say you can only get one to light up at a time? i've been able to make at least ten come on at the same time, so current limits shouldn't be a problem for at least that many. Based on what you said, i think you may be reusing the led_blink software, which is designed to flash only one LED at a time. If you put in as code in main(), say:

DDRC |= (1<<PC4);
PORTC |= (1<<PC4);

it will first configure pin 4 of port C as output, then set pin 4C high, driving the LED. If you then put, say:

DDRC |= (1<<PC5);
PORTC |= (1<<PC5);

it will configure 5C as output and set it high. At this point in execution, pins 5C and 4C should be high and their LEDs should be on simultaneously, and you should be able to repeat this process indefinitely, and the LEDs should remain on until they are told to turn off. You can do this with the following code:

PORTC &= ~(1<<PCX); //where X is the port number

As i said, i've used it to light 10 LEDs, PC1-5 and PB1-5. I have not ever used port A, so i couldn't comment on adding those in.

Also, i usually do all my pin configuring as one block right after the declaration of main, eg:

int main(){
    DDRC |= (1<<PC4);
    DDRC |= (1<<PC5);
    .... return 1;}

You ought to be able to use this to selectively turn on and off individual LEDs, at least (as i said before) 10 by my experience. Good luck, hope this is helpful!

Post a Reply

Please log in to post a reply.

Did you know that talking to the microcontroller over the USB/Serial link is easy under Windows, Linux, and OS X? Learn more...