Newbie needs help

Hi all, I'm very new to Arduino, I have bought and read through Getting started with Arduino by Massimo and done all the sketches in that. I'm trying to build a digital scoreboard that keeps score for two players. I am using a pair of 2 digit 7 segment LED's that I bought from sure electronics (http://www.sureelectronics.net/goods.php?id=1164). Each LED setup has two 74HC164 shift registers coupled with two darlington arrays to drive the pair of LEDs. The shift registers are in series. I think I'm pretty solid on using the shiftout command to send serial data to the first shift register, then sending another set of data to the first register thus causing the first set of data to be moved to the second shift register causing both LEDs to display the desired numbers.

To keep up with score I plan on using two 3-way momentary toggle switches. So when you flip Player 1 toggle switch up once it adds one to Player 1's score. I'm pretty sure I understand how to do that; use a digitalRead command and when the pin that corresponds to that input is HIGH its P1 = P1 + 1 so it adds one point to Player 1's score. Same for Player 1 toggling the switch down it would subtract 1 point and be P1 = P1 -1. Same for Player 2. To reset both players back to Zero I would just have both switches toggled down for at least half a second at the same time.

The part that I'm having trouble figuring out is taking the values from variables P1 and P2 and then breaking them into two separate digits and then converting those decimal values into the correct binary output to send to the shift register via the shiftout command. For example if Player 1 had a score of 15. I would need to display "1" on the first 7 seg LED and "5" on the second 7 seg LED. And to get "1" to display on the 7 seg LED I need to send out the following data to the shift register B01100000 (LSB). Since the number ONE in binary is B00000001, they obviously aren't equal. Same with "5". How do I get the decimal value 5 converted to B10110110 (LSB)? Is there a library in the Arduino IDE that would make this simpler? Any help would be greatly appreciated! Thanks!

The values that you send to the shift registers are not the values you want displayed. The value you send defines the segments to light up to display a given value. So, you need to defined a look-up table. The digit to display is the index into the look-up table. The output is the value to send to the shift registers.

(A look-up table is one use of an array).

As for splitting the score into separates digits, that is simple. Divide the value, as an int, by 10 to get the 10s value. 15/10 = 1. The, use the modulo function to get the ones value. 15 % 10 = 5.

Thanks for the input. I'll do some research on arrays and lookup tables for Arduino.

As for the the other part, breaking the digits up, I was thinking there had to be a mathematical solution to accomplishing that task.

Simplest way is to keep track of the digits seperately.
Count from 0 to 9, when you get to 10 reset to 0 and increment the next digit. Then you have two bytes to shift thru the registers.