8 7-segments display with two 4094

Hi
All,

I'm new in the Arduino Communauty, but in two months of decovery and test I think it's time to dial with your's.

So,

By the past I was finding a solution doing a cadencer for use in Regularity Rally, as TSD Time Speed Distance Rally. An embedded calculator using to show the ideal distance with a specified speed.

I find the solution with Arduino Solution.

The objet I have to realize is a litlle calculator with 4 switch wheel on Input, ( BCD code so : 16bits) for entering the speed,
and 4 or 8 7-segments to display the "Ideal" Distance .

Doing this with a native UNO it seems there are no numerous port to use...

The solution I opted for the project :

Multiplexing the display with 2 cascading 4094,
the first open the good 7-segments, the second send the number on it.

For the input I had to read for switch Wheel : so 4 * four bits : a word to read.

I use 2 * HC 165 to do this.

the usable pin on the uno may be :

clock, strobe, data for the 4094,

clock, strobe, data for the HC165,

with standard shiftout or shiftin routine the strobe and clock can't be mixed.

The hardware goes good, the routine and algorithm too, and with the free pin on the Arduino I can control new function like : switch the time , show the real speed (with a hall sensor,) programming new speed at a certain distance..... so many possibilities....

working on the code, Now I'm looking to use SPI, which can clarify the original routine and use only one clock and one strobe.

but a line for the MISO , one for the MOSI and 2 for the different Slave ( the chained 4094, the chained HC165).

Hope you follow me at this point.......

doing This I had a good display with SPI and the chained 4094 ,

A good reading on the 4 switches wiht the chained HC 165,

All is working good.......But, as there is a but......I can not display and reading in same time....

In my code I had to erase the reading routine to recupere the display....????

The orignial Code :

#define SPI_SCK 13 // clock
#define SPI_miso 12 // master In slave Out ----> Roue codeuse et bouton
#define SPI_mosi 11 // Master Out slave In ---> affichage
#define sept_segments_1 10 // 7-segments 4094 display
#define boutons 9 // HC165 reading

#include <SPI.h>

int aff[]={ B11111110,B11111101,B11111011,B11110111}; // indication du nombre d'afficheur
int car[]={ B00010001,B10011111,B00110010,B00010110,B10011100,B01010100,B11010000,B00011111,B00010000,B00011100 };

int i;
int j;
int raz = 7;
int gel = 6;
int time=0; // timing .5 entre chaque chiffre
long sec= millis();
int seconde=0;
int minute=0;
int heure=0;
int mm=0;
int m=0;
int ss=0;
int s=0;
int temps=20;

void setup() {
Serial.begin (57600);
pinMode(sept_segments_1, OUTPUT);
pinMode(boutons, OUTPUT);
SPI.begin();
SPI.setDataMode(SPI_MODE1);
SPI.setBitOrder(MSBFIRST);
SPI.setClockDivider(SPI_CLOCK_DIV32);
digitalWrite(boutons,LOW);
digitalWrite(sept_segments_1,1);
pinMode (gel,INPUT);
pinMode (raz,INPUT);

// for (int i=0;i<2;i+1){ // Boucle sans fin tant que raz n'est pas appuyé
// i=i-digitalRead(raz);
//}
}
/// ------------- Gestion de l'affichage avec k=numero d'afficheur et n=chiffre à indiquer----------------------------
void affichage(int k,int n){
digitalWrite(sept_segments_1, 0);
SPI.transfer(aff[k]);
SPI.transfer(car[n]);
digitalWrite(sept_segments_1, 1);

}

/// ------------- Boucle Principale with Simple Timer--------------------------------
void loop() {

if ( millis()>(sec+1000)){ // comptage des impulsion pour calcul des secondes
seconde++;
sec=sec+1000;
}

if (seconde>59){
seconde = 0;
minute++;
}
if (minute>99){
minute = 0;
heure++;
}

mm = int (minute/10);
m = int (minute-(mm10));
ss = int (seconde/10);
s = int (seconde-(ss
10));

affichage (0,mm);
affichage (1,m);
affichage (2,ss);
affichage (3,s);

/// ------------- Switch wheel reading --------------------

digitalWrite(boutons, HIGH);
byte value_high = SPI.transfer(0x00);
byte value_low = SPI.transfer( 0x00);
digitalWrite(boutons, LOW);

/// ------------- Screen display for control Reading Routine------------

for (i=0;i<8;i++)
{
Serial.print(bitRead(value_high,i));
Serial.print(" : ");
}
for (i=0;i<8;i++)
{
Serial.print(bitRead(value_low,i));
Serial.print(" : ");
}
//Serial.print(value_low);
Serial.println();

}

So The orignal solution without spi, go well, but for code optimization (and for my understanding).. I would know
if someone can show me my error, or the wrong use of the shiftering....

Thank your for your answer...