7 Segment Display Problem

I’m new to Arduino and have been playing around with it for a couple of weeks. I’m currently working on a shuffleboard score keeper that counts from 0 to 21 using RF transmitter and receiver. I have one Arduino transmitting data using two push buttons(player1 and player2). I have another Arduino receiving the data and displaying it on 2 dual 7-segment displays.

Problem: I’m having problems updating the 2 dual 7-segment displays on the receiver. If I put a delay in certain places it will update the displays, but cause one of the dual display segments to fade . If I don’t put delays it will never update the counter.

Some of the hardware I’m using:

  1. 433Mhz RF transmitter and receiver to transfer the data
  2. 2 digit seven segment common cathode displays (two of these one for player1 and player2 .
  3. 4 74HC595 8 bit Shift Register
  4. 2 Arduino Uno

Here’s my code without any of the delays.

#include <VirtualWire.h>

//set arduino pins for 2 shift registers
const int dataPlayer1=6;
const int clockPlayer1=7;
const int latchPlayer1=5;

const int dataPlayer2=9;
const int clockPlayer2=10;
const int latchPlayer2=8;


//GroundConnectionsForSegments
int shiftRegisterGroundConnectionToSegmentDigitOne=B00100000;
int shiftRegisterGroundConnectionToSegmentDigitTwo=B01000000;

//setting segments to represent numbers
int zero  =B11101101; //0
int one   =B01000001; //1
int two   =B01111100; //2
int three =B01111001; //3
int four  =B11010001; //4
int five  =B10111001; //5
int six   =B10111101; //6
int seven =B01100001; //7
int eight =B11111101; //8
int nine  =B11110001; //9

int numReceivedRFPlayer1=0;
int numReceivedRFPlayer2=0;

int segmentOneNumberRepresentationPlayer1;
int segmentTwoNumberRepresentationPlayer1;
int segmentOneNumberRepresentationPlayer2;
int segmentTwoNumberRepresentationPlayer2;

void setup()
{
   pinMode(dataPlayer1,OUTPUT);
   pinMode(clockPlayer1,OUTPUT);
   pinMode(latchPlayer1,OUTPUT);
   pinMode(dataPlayer2,OUTPUT);
   pinMode(clockPlayer2,OUTPUT);
   pinMode(latchPlayer2,OUTPUT);
 
	//receiver
	//Initialise the IO and ISR
    vw_set_rx_pin(12);           // We will be receiving on pin 4 i.e the RX pin from the module connects to this pin.
    vw_setup(2000);                   // Bits per sec
    vw_rx_start();
}

void loop()
{
   ReceiverRF();
   Player1();
   Player2();
}

void ReceiverRF()
{
  int num;
    uint8_t buf[VW_MAX_MESSAGE_LEN];
    uint8_t buflen = VW_MAX_MESSAGE_LEN;
     
    //see if we have received a message from our transmitter
    if (vw_get_message(buf, &buflen)) 
    {
          //example of data coming in F1, F2....F10 - S1, S2....S10
          char val[buflen]; //Same as buf, last char will be used for null terminator
          memset(val, '\0', sizeof(val));
   
          //Copy value from string 
          strncpy(val, (char *)buf + 1, buflen - 1);
   
          //convert string containing value to integer 
          int VAL = atoi( val ); 
   
          switch (buf[0]) {
            case 'F':
		    //NumberReceived from transmitter for player 1
                      numReceivedRFPlayer1=VAL;
                      break;
            case 'S':
		    //NumberReceived from transmitter for player 2
                     numReceivedRFPlayer2=VAL;
                     break;
   
            default: //do nothing
                break;
          }
    }
}

void Player1()
{
	//Get 7 segment representation for number transmitted for player 1
	segmentOneNumberRepresentationPlayer1 = getNumberRepresentationForSegmentOne(numReceivedRFPlayer1);
	segmentTwoNumberRepresentationPlayer1 = getNumberRepresentationForSegmentTwo(numReceivedRFPlayer1);
     
	//Set the 7 segment display
        setNumberForSegmentOne(segmentOneNumberRepresentationPlayer1, dataPlayer1, clockPlayer1, latchPlayer1);
	setNumberForSegmentTwo(segmentTwoNumberRepresentationPlayer1, dataPlayer1, clockPlayer1, latchPlayer1);
}

void Player2()
{
	//Get 7 segment representation for number transmitted for player 2
	segmentOneNumberRepresentationPlayer2 = getNumberRepresentationForSegmentOne(numReceivedRFPlayer2);
	segmentTwoNumberRepresentationPlayer2 = getNumberRepresentationForSegmentTwo(numReceivedRFPlayer2);
   
	//Set the 7 segment display
	setNumberForSegmentOne(segmentOneNumberRepresentationPlayer2, dataPlayer2, clockPlayer2, latchPlayer2);
	setNumberForSegmentTwo(segmentTwoNumberRepresentationPlayer2, dataPlayer2, clockPlayer2, latchPlayer2);
}

int getNumberRepresentationForSegmentOne(int number)
{
    int segmentOne = zero;
    
	//set segment one to 1
    if (number >= 10 && number <= 19)
    {
      segmentOne = one;
    }
  
    //set segment one to 2
    if (number >= 20 && number <= 21)
    {
      segmentOne = two;
    }
 
    return segmentOne;
}

//This is ugly I will stream line this.  Better way to write this code
int getNumberRepresentationForSegmentTwo(int number)
{
   int segmentTwo = zero;
  
   switch (number) {
        case 0:
          segmentTwo=zero;
          break;
        case 1:
          segmentTwo=one;
          break;
        case 2:
          segmentTwo=two;
          break;
        case 3:
          segmentTwo=three;
          break;
        case 4:
          segmentTwo=four;
          break;
        case 5:
          segmentTwo=five;
          break;
        case 6:
          segmentTwo=six;
          break;
        case 7:
          segmentTwo=seven;
          break;
        case 8:
          segmentTwo=eight;
          break;
        case 9:
          segmentTwo=nine;
          break;
        case 10:
          segmentTwo=zero;
          break;
        case 11:
          segmentTwo=one;
          break;
        case 12:
          segmentTwo=two;
          break;
        case 13:
          segmentTwo=three;
          break;
        case 14:
          segmentTwo=four;
          break;
        case 15:
          segmentTwo=five;
          break;
        case 16:
          segmentTwo=six;
          break;
        case 17:
          segmentTwo=seven;
          break;
        case 18:
          segmentTwo=eight;
          break;
        case 19:
          segmentTwo=nine;
          break;
        case 20:
          segmentTwo=zero;
          break;
        case 21:
          segmentTwo=one;
          break;
    }
    return segmentTwo;
}

void setNumberForSegmentOne(int segmentOne, int data, int clock, int latch)
{
    digitalWrite(latch,LOW);
    shiftOut(data,clock,LSBFIRST,shiftRegisterGroundConnectionToSegmentDigitOne);
    shiftOut(data,clock,LSBFIRST,segmentOne);
    digitalWrite(latch,HIGH);
}

void setNumberForSegmentTwo(int segmentTwo, int data, int clock, int latch)
{
    digitalWrite(latch,LOW);
    shiftOut(data,clock,LSBFIRST,shiftRegisterGroundConnectionToSegmentDigitTwo);
    shiftOut(data,clock,LSBFIRST,segmentTwo);
    digitalWrite(latch,HIGH);
}

I did some research and to keep the displays from fading I think I need to incorporate the millis(). This is a great article - http://arduino.cc/playground/Code/AvoidDelay.