Beginners: please read this post and this post before posting to the forum.
0 Members and 1 Guest are viewing this topic.
#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; }}
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.
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....