Society of Robots - Robot Forum

General Misc => Robot Videos => Topic started by: HDL_CinC_Dragon on December 27, 2008, 04:07:00 AM

Title: My little LED Light Chaser
Post by: HDL_CinC_Dragon 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
[youtube]RqhLbR6A9g4[/youtube]
Code: [Select]
#include <avr/io.h>

//5 on = 0x5F
//4 on = 0x6F
//3 on = 0x77
//2 on = 0x7B
//1 on = 0x7D
//0 on = 0x7E

int del = 2500; // create a variable to be used as the delay
int rate = 100; // create a variable to be used as the rate of change

//=================================================================main

int main(void)
{
DDRC = 0xFF; // set all C ports as outputs
 //PORT ID 0b76543210  - port labels in the binary set
while(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_cycles

int delay_cycles(int x)
{
while (x>0)
{
x--;
}
}

//=================================================================PORT_HiLo

int 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-
Added a couple more comments into the source code.
-EDIT-
Added a couple more comments into the source code again.
-EDIT-
Added some more comments into the source code...
Title: Re: My little LED Light Chaser
Post by: Admin on December 27, 2008, 09:48:33 AM
hmmm do you have resistors with your LEDs on that breadboard? dun see any :P

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 . . .
Title: Re: My little LED Light Chaser
Post by: HDL_CinC_Dragon 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  :P. 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 :)
Title: Re: My little LED Light Chaser
Post by: Admin 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.
Title: Re: My little LED Light Chaser
Post by: HDL_CinC_Dragon 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 (http://www.societyofrobots.com/robotforum/index.php?topic=3348.0) 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....
Title: Re: My little LED Light Chaser
Post by: Admin 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
Title: Re: My little LED Light Chaser
Post by: HDL_CinC_Dragon 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?
Title: Re: My little LED Light Chaser
Post by: frodo 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.
Title: Re: My little LED Light Chaser
Post by: HDL_CinC_Dragon on January 04, 2009, 11:33:44 AM
Well heres how breadboards are layed out:
(http://ece-www.colorado.edu/~mathys/ecen2250/lab01/breadboard90.png) (http://ece-www.colorado.edu/~mathys/ecen2250/lab01/breadboard90.png)
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 :P

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.
(http://img136.imageshack.us/img136/7313/schematical1.jpg) (http://img136.imageshack.us/img136/7313/schematical1.jpg)
Title: Re: My little LED Light Chaser
Post by: frodo on January 05, 2009, 02:40:35 PM
cheers, really great circuit for just putting it together from scratch.
Title: Re: My little LED Light Chaser
Post by: HDL_CinC_Dragon 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 :)
(http://img101.imageshack.us/img101/3772/schematicupdatedst9.jpg) (http://img101.imageshack.us/img101/3772/schematicupdatedst9.jpg)
Title: Re: My little LED Light Chaser
Post by: HDL_CinC_Dragon 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 :)
(http://img101.imageshack.us/img101/1759/schematic03oj4.jpg) (http://img101.imageshack.us/img101/1759/schematic03oj4.jpg)
Title: Re: My little LED Light Chaser
Post by: TrickyNekro 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...
Title: Re: My little LED Light Chaser
Post by: HDL_CinC_Dragon 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 :)