|
|
Example 3: 5-LED scanner, aka Knight Rider lights
You might have read Metku's couple old modding articles about animating leds (Animated Leds 1 and Animated Leds 2) that were made few years ago. Now we make a same kind of system with a microcontroller. The main advantages of using a microcontroller instead of a normal IC is that you can program the microcontroller to do what ever animations you like without changing the physical arranging of the leds. Just write a new sequence, plug the programming cable to the chip and transfer the new code in and vóila.
If you are experiencing errors while trying to program the chip (such as 'Device not found' etc) try removing the leds from pins 5, 6 and 7, which are used for programming (the leds take their power from the programming lines and the chip doesn't get enough juice to be able to be programmed). Then after the programming has finished, connect the leds back. Easy fix to this would be that you have a common ground to all of the leds and you just disconnect the "led ground" from the "main ground" while programming.

More leds added to the original circuit
// Frequency number needed by the delay function.
// The chip is factory set to run on internal
// oscillator at 1 MHz so the value is 1000000UL
#define F_CPU 1000000UL
#include <avr/io.h>
#include <util/delay.h>
// Number of frames in the animation
#define FRAMES 8
// The animation sequence array.
// All the values are in binary for easy
// reading (1 = LED on / 0 = LED off)
// The rightmost bit is PB0 and the leftmost
// bit after '0b' is PB4.
// -> 0b[4][3][2][1][0]
char animation[FRAMES] =
{
0b00001,
0b00010,
0b00100,
0b01000,
0b10000,
0b01000,
0b00100,
0b00010
};
int main(void)
{
DDRB = 0x1F; // PB0-PB4 output
PORTB = 0x00; // Set all pins low
int i;
while(1)
{
// Loop through all the frames in the animation
for(i=0 ; i<FRAMES ; i++)
{
// Write the value from the array to the port
PORTB = animation[i];
// Wait 100 ms before going to the next frame
_delay_ms(100);
}
}
return 0;
}

Example 3 in action
Conclusion
We hope that you got your rig set up and leds flashing with the instructions. Please leave a comment or a question if you have something to ask. There is a part two of the article on planning stage and you can drop some ideas to the comments section about what you might want to see there (examples etc). All ideas and suggestions are taken into consideration and the most useful are then chosen.
|
Below are some useful links you might want to give a look at: |
Subscribe to Metku.net
Digg It
Save This Page
Stumble it!
Add to Facebook
|
Related articles in Metku.net
| | Pages: 1 2 3 4 5 6 | |


Subscribe to Metku.net
Digg It
Save This Page
Stumble it!
Add to Facebook





Content in english!
Sisältö suomeksi!
