I need your suggestion in writing a program for the AVR butterfly which will drive a 7 element LED array to count up or count down
The 7-element LED has 7 LED’s physically laid out as follows:
0 1 2 3 4 5 6
Imagine these LED as being long and thin rather than circular. So the number 0 is displayed as:
on on on off on on on
The number 7 is displayed as:
on off on off off on off
The number 5 is displayed as:
on on off on off on on
tevvybear- 04-20-2007
A very basic way to do this would be as follows:
#define SEGMENT_0 (1<<SEGMENT_0_PIN) #define SEGMENT_1 (1<<SEGMENT_1_PIN) //repeat for all segments
#define OUTPUT_0 (SEGMENT_0|SEGMENT_1|SEGMENT_2|SEGMENT_4|SEGMENT_5|SEGMENT_6) #define OUTPUT_1 //similar to aabove //repeat for other numbers
When you want to output the value
void display(uint8_t value) {
switch(value) { case 0: OUTPUT_PORT = OUTPUT_0; break; case 1: OUTPUT_PORT = OUTPUT_1; break; //etc up to case 9 or case F if you want hex default: error_function(ERROR_CODE_DISPLAY_BOUND);
} return; }
I'm sure you could make more efficient code if you tried, but this is what i've got off the top of my head. ps. this may not work, it's completely untested
Forumer™ is Voted #1 Free Forum Hosting provider
Build your own community today with the largest message board hosting company.