Found something that may be useful
int extractDigit(int number, int place)
{
for(int i = 0; i < place; ++i)
number /= 10; //get rid of the preceding digits
return number % 10; //now ignore all of the following ones
}
though this is C++
the key to extracting digits is using integer and modular division. You could directly access no. 9 in 1981 with (1981 / 100) % 10. The reason this works is that 1981/100 = 19, and 19 % 10 = 9.
Also found premade 7-segment script
#define NUM_DIGITS 4
// table of 7-segment patterns
const byte seg_def[] = // segment patterns for digits 0-9
{//GFEDCBA
B0111111, // '0'
B0000110, // '1'
B1011011, // '2'
B1001111, // '3'
B1100110, // '4'
B1101101, // '5'
B1111101, // '6'
B0000111, // '7'
B1111111, // '8'
B1100111 // '9'
};byte digit_array[NUM_DIGITS];
void NumberToArray(word number)
{
char i;// initialize all digits to the empty pattern (no segments lit)
for (i=0;i<NUM_DIGITS;i++) digit_array*=0;*
- // extract each digit (right to left)*
** for (i=NUM_DIGITS-1;i>=0;i--) {**- // extract least significant digit as an index into the*
- // segment pattern table*
digit_array*=seg_def[number%10];[/b]
__ // get next digit*
** number=number/10;**
* // exit if there are no more digits to avoid leading zeroes*
_ ** if (number==0) break;**
}/for/
}/NumberToArray/_
[/quote]
Ok, this goes out of hand. It is 01:07 at night, must go to sleep__