### Author Topic: My little LED Light Chaser  (Read 7602 times)

0 Members and 1 Guest are viewing this topic.

#### HDL_CinC_Dragon

• Supreme Robot
• Posts: 1,261
##### My little LED Light Chaser
« on: December 27, 2008, 04:07:00 AM »
So it was 1:30am and I was bored and decided to tinker around with one of my four ATMega8's. The result was an LED Light Chaser that speeds up and slows down. It also has a little piezo disc in parallel with the bottom LED to make a little click sound. Enjoy
Code: [Select]
`#include <avr/io.h>//5 on = 0x5F//4 on = 0x6F//3 on = 0x77//2 on = 0x7B//1 on = 0x7D//0 on = 0x7Eint del = 2500; // create a variable to be used as the delayint rate = 100; // create a variable to be used as the rate of change//=================================================================mainint main(void){ DDRC = 0xFF; // set all C ports as outputs //PORT ID 0b76543210  - port labels in the binary setwhile(1) // Basically saying "while true" and since 1 is always true, this will loop forever. Using "while(1)" is terrible programing etiquette. Dont do it. { while(del>=0) //This while loop will increase the speed at which the lights run by decreasing the delay time { int x; for(x=0;x<=5;x++) { PORT_HiLo(x); delay_cycles(del); } for(x=5;x>=0;x--) { PORT_HiLo(x); delay_cycles(del); } del -= rate; } while(del<=2500) //This while loop will decrease the speed at which the lights run by increasing the delay time { int x; for(x=0;x<=5;x++) { PORT_HiLo(x); delay_cycles(del); } for(x=5;x>=0;x--) { PORT_HiLo(x); delay_cycles(del); } del += rate; } }}//=================================================================delay_cyclesint delay_cycles(int x){while (x>0) { x--; }}//=================================================================PORT_HiLoint PORT_HiLo(int x){switch (x) { case 6: PORTC = 0x00; // Put all C ports low - Turns all LEDs on break; case 5: PORTC = 0x5F; // Put port C5 low - Turn top LED on break; case 4: PORTC = 0x6F; // Put port C4 low - Turn 2nd from top LED on break; case 3: PORTC = 0x77; // Put port C3 low - Turn 3rd from top LED on break; case 2: PORTC = 0x7B; // Put port C2 low - Turn 4th from top LED on break; case 1: PORTC = 0x7D; // Put port C1 low - Turn 5th from top LED on break; case 0: PORTC = 0x7E; // Put port C0 low - Turn bottom LED on break; default: PORTC = 0xFF; // Put all C ports high - Turns all LEDs off break; }}`

-EDIT-
-EDIT-
-EDIT-
« Last Edit: December 27, 2008, 04:21:53 AM by HDL_CinC_Dragon »
United States Marine Corps
Infantry
Returns to society: 2014JAN11

• Supreme Robot
• Posts: 11,669
##### Re: My little LED Light Chaser
« Reply #1 on: December 27, 2008, 09:48:33 AM »
hmmm do you have resistors with your LEDs on that breadboard? dun see any

I've been meaning to do that with my Axon, but with 28 LEDs. Its all wired up, just never got around to programming it . . .

#### HDL_CinC_Dragon

• Supreme Robot
• Posts: 1,261
##### Re: My little LED Light Chaser
« Reply #2 on: December 27, 2008, 12:59:57 PM »
Of course theres a resistor Admin! The LED breadboard is juiced from the regulated 5v supply rail through a 1k ohm resistor. You can see the resistor just above the first red wire that goes from the control circuit to the LED circuit. I hooked it up so that the ground rail on the LED circuit breadboard is actually the supply rail because its the closest one to the component pins  . Im powering the LEDs with 3V at about 3mA. They are sinking into the MCU exactly the way the  \$50 robot did with its LED
« Last Edit: December 27, 2008, 01:00:34 PM by HDL_CinC_Dragon »
United States Marine Corps
Infantry
Returns to society: 2014JAN11

• Supreme Robot
• Posts: 11,669
##### Re: My little LED Light Chaser
« Reply #3 on: December 28, 2008, 12:21:43 AM »
Hmmm but you need a resistor for each LED . . . 5 LEDs would need 5 resistors. If you use the exact same LEDs with the exact same internal resistance they'll work, but if any are different from manufacturing tolerances they'll act differently and possibly burn out over time.

#### HDL_CinC_Dragon

• Supreme Robot
• Posts: 1,261
##### Re: My little LED Light Chaser
« Reply #4 on: December 28, 2008, 01:05:20 AM »
Im 95% sure theyre all the exact same LED. Only 1 LED is ever on at one time so I figured if I power them all in parallel from the rail I could just use a single resistor to supply that rail to limit the current and drop the voltage to what I need for all the resistors. Seems to work pretty well and so far there doesnt seem to be any issues with it.

Should I post a schematic?

Im going to be staying at Jaimie Mantzels place in vermont for like a week so I wont have internet access for the duration. I plan on leaving in like 8 hours or so....
United States Marine Corps
Infantry
Returns to society: 2014JAN11

• Supreme Robot
• Posts: 11,669
##### Re: My little LED Light Chaser
« Reply #5 on: December 28, 2008, 01:37:36 AM »
Quote
Only 1 LED is ever on at one time so I figured if I power them all in parallel from the rail I could just use a single resistor to supply that rail to limit the current and drop the voltage to what I need for all the resistors.
Yea if only one is on at a time, then no problem at all.

But if more than one is on at a time . . . lets say one LED has a resistance of 0.000001 ohms and the other 0.00001 ohms (because of manufacturing tolerances). You'd think, oh no big deal, the difference is tiny. But actually one has 10x the resistance as the other, and then that's where the problems arise. 10x the current goes through one over the other.

But if you put resistors with it, say a 201 ohm and a 199 ohm, then its a tiny current difference.

edit:
Quote
Im going to be staying at Jaimie Mantzels place in vermont for like a week so I wont have internet access for the duration. I plan on leaving in like 8 hours or so....
I'm leaving for Laos tomorrow, and will also be gone for a week. Won't be online much . . . 3rd world countries and all . . . rice paddies here I come! hehe
« Last Edit: December 28, 2008, 01:39:45 AM by Admin »

#### HDL_CinC_Dragon

• Supreme Robot
• Posts: 1,261
##### Re: My little LED Light Chaser
« Reply #6 on: January 01, 2009, 01:16:45 PM »
ah, I see what your saying. So if the 2 branches together were taking 60mA of current, it wouldnt be a 30/30 split. It would be closer to something like 5/50 give or take a couple hundred uA?
United States Marine Corps
Infantry
Returns to society: 2014JAN11

#### frodo

• Supreme Robot
• Posts: 329
• BOW DOWN TO MY MIGHTY STARE!!
##### Re: My little LED Light Chaser
« Reply #7 on: January 04, 2009, 04:23:51 AM »
could you please post a schematic because i don't how breadboard circuits work. i get very confused with them.
OMG!!!! I AM SUPREME ROBOT!!!

Check out my Web

#### HDL_CinC_Dragon

• Supreme Robot
• Posts: 1,261
##### Re: My little LED Light Chaser
« Reply #8 on: January 04, 2009, 11:33:44 AM »
Well heres how breadboards are layed out:

It would be extremely useful for you to remember that. But I know looking at breadboarded circuits does get pretty confusing >_< especially with poor lighting and insane wires going everywhere

Im drawing up a circuit schematic right now in EAGLE Light. Im not going to include the programmer circuit because the programmer part is setup exactly the way it is for the \$50 robot so theres no point in me cluttering up the place with other stuff

-EDIT-
Heres the schematic... nothing special. Hope it helps though.
NOTE: Its important that only one LED be on at a time unless each LED gets its own individual resistor.

« Last Edit: January 04, 2009, 12:16:32 PM by HDL_CinC_Dragon »
United States Marine Corps
Infantry
Returns to society: 2014JAN11

#### frodo

• Supreme Robot
• Posts: 329
• BOW DOWN TO MY MIGHTY STARE!!
##### Re: My little LED Light Chaser
« Reply #9 on: January 05, 2009, 02:40:35 PM »
cheers, really great circuit for just putting it together from scratch.
OMG!!!! I AM SUPREME ROBOT!!!

Check out my Web

#### HDL_CinC_Dragon

• Supreme Robot
• Posts: 1,261
##### Re: My little LED Light Chaser
« Reply #10 on: January 05, 2009, 05:07:12 PM »
I updated the schematic just a bit. I added the main board status green LED next the to voltage regulator that you can see in the second half of the video when its all dark. That green LED will be on as long as there is power coming from the vreg. I also added a warning note for the LEDs having only one common resistor
United States Marine Corps
Infantry
Returns to society: 2014JAN11

#### HDL_CinC_Dragon

• Supreme Robot
• Posts: 1,261
##### Re: My little LED Light Chaser
« Reply #11 on: January 05, 2009, 05:24:49 PM »
Ok I fixed up the schematic to make it look slightly more professional as well as gave each LED its own resistor like it should have been in the first place

United States Marine Corps
Infantry
Returns to society: 2014JAN11

#### TrickyNekro

• Contest Winner
• Supreme Robot
• Posts: 1,207
• 1.6L Peugeot 307 tuner
##### Re: My little LED Light Chaser
« Reply #12 on: January 09, 2009, 12:10:06 AM »
Dragon... How comes you connect the led and the piezo serially???
Mustn't they be connected in parallel?
Piezo is just a capacitor... it won't let current through for ever... Only when charging...
For whom the interrupts toll...

P.S. I've been inactive for almost a year... Don't give promises but I'll try to complete my tutorials. I'll let you know when..

Cheers!

#### HDL_CinC_Dragon

• Supreme Robot
• Posts: 1,261
##### Re: My little LED Light Chaser
« Reply #13 on: January 09, 2009, 05:33:22 PM »
Oh crap buckets. The actual design has the Piezo in parallel with the LED not in series >_< damn
good catch Nekro.

Unfortunately on Wednesday I accidentally corrupted my hard drive and lost everything. I dont have the original schematic files for a quick fix to repost it... I also didnt reinstall EAGLE Lite yet lol... gunna go do that in another tab
United States Marine Corps
Infantry
Returns to society: 2014JAN11