Ci sono vicino ho applicato il pezzo di Lesto per trovare i bit cambiati e funziona, ma ottengo un numero in uscita sbagliato
//--------------------timer--------------------------------------------------------
unsigned long previousMillis_e = 0;
unsigned long interval_e = 50;
//---------------------------------------------------------------------------------
byte Port[] = {0,0,0,0,0,0,0,0,0}; //A,B,C,D,E,G,H,J,L ... valori hold
byte cont; // contatore per pulsante port 32(test)
void setup()
{
delay(1000);
Serial.begin(9600);//debug
pinMode(32, INPUT);
DDRL = 255; // set a OUTPUT i pin 42-43-44-45-46-47-48-49
//PORTL = 0; // metto a LOW i pin 42-43-44-45-46-47-48-49
}
void loop()
{
unsigned long currentMillis_e = millis();
if(currentMillis_e - previousMillis_e > interval_e)
{
previousMillis_e = currentMillis_e;
if(Port[2] != PINC){
byte C[] = {30,31,32,33,34,35,36,37};
BitChange(Port[2], PINC, C);
Port[2] = PINC;
Serial.println("CHANGE PORT_C 30-31-32-33-34-35-36-37 >> val byte = " + (String)PINC );//debug
}
/*if(Port[3] != PIND){
Serial.println("CHANGE PORT_D 18-19-20-21-38 >> val byte = " + (String)PIND);//debug
}*/
if(Port[5] != PING){
Port[5] = PING;
Serial.println("CHANGE PORT_G 39-40-41-4 >> val byte = " + (String)PING);//debug
}
if(Port[8] != PINL){
byte L[] = {42,43,44,45,46,47,48,49};
BitChange(Port[8], PINL, L);
Port[8] = PINL;
Serial.println("CHANGE PORT_L 42-43-44-45-46-47-48-49 >> val byte = " + (String)PINL );//debug
}
//----------------------test con pulsante-----------------------
if (digitalRead(32)) cont++; else cont=0;
if (digitalRead(42) == 0 && cont == 1){
PORTL |= (1<<7); cont++;
}
if (digitalRead(42) == 1 && cont == 1){
PORTL &= ~(1<<7); cont++;
}
//------------------------------------------------------------------
}
}
void BitChange(byte Hold_Val_Port, byte New_Val_Port, byte Pin[])
{
byte Cambio = New_Val_Port ^ Hold_Val_Port;
for ( byte i=0; i < 8; i++)
{
if ( Cambio & (1<<(8-i))) //controllo lo stato del bit in posizione 8-i
Serial.print("Il pin " + (String)Pin[i] + " e' cambiato! ... ");//debug <<<<<<<<<<<< ERRORE!!!
}
}
ricapitolando ho:
Un pulsante sul pin 32 quindi PORTC
Un led sul pin 42 quindi PORTL
premo il pulsante e lo rilascio immediatamente
se metto
Serial.print("Il pin " + (String)Pin[i] + " e' cambiato! ... ");
ottengo questa uscita
Il pin 33 e' cambiato! ... CHANGE PORT_C 30-31-32-33-34-35-36-37 >> val byte = 32 <<< ERRORE
Il pin 43 e' cambiato! ... CHANGE PORT_L 42-43-44-45-46-47-48-49 >> val byte = 128 <<< ERRORE
Il pin 33 e' cambiato! ... CHANGE PORT_C 30-31-32-33-34-35-36-37 >> val byte = 0 <<< ERRORE
se metto ivece -1 pensavo di correggere entrambi i valori
Serial.print("Il pin " + (String)Pin[i-1] + " e' cambiato! ... ");
ottengo invece questa uscita
Il pin 31 e' cambiato! ... CHANGE PORT_C 30-31-32-33-34-35-36-37 >> val byte = 32 <<< ERRORE
Il pin 42 e' cambiato! ... CHANGE PORT_L 42-43-44-45-46-47-48-49 >> val byte = 128 <<< GIUSTO
Il pin 31 e' cambiato! ... CHANGE PORT_C 30-31-32-33-34-35-36-37 >> val byte = 0 <<< ERRORE
Perchè??? dannazione 
Tabella dal file pins_arduino.h - Pin definition functions for Arduino
PL , // PL 7 ** 42 ** D42
PL , // PL 6 ** 43 ** D43
PL , // PL 5 ** 44 ** D44
PL , // PL 4 ** 45 ** D45
PL , // PL 3 ** 46 ** D46
PL , // PL 2 ** 47 ** D47
PL , // PL 1 ** 48 ** D48
PL , // PL 0 ** 49 ** D49
PC , // PC 7 ** 30 ** D30
PC , // PC 6 ** 31 ** D31
PC , // PC 5 ** 32 ** D32
PC , // PC 4 ** 33 ** D33
PC , // PC 3 ** 34 ** D34
PC , // PC 2 ** 35 ** D35
PC , // PC 1 ** 36 ** D36
PC , // PC 0 ** 37 ** D37