int c1=3,c2=2,c3=8,c4=9;
int r1=7,r2=6,r3=5,r4=4;
void setup() {
  // put your setup code here, to run once:
pinMode(c1, OUTPUT);
pinMode(c2, OUTPUT);
pinMode(c3, OUTPUT);
pinMode(c4, OUTPUT);
pinMode(r1, INPUT_PULLUP);
pinMode(r2, INPUT_PULLUP);
pinMode(r3, INPUT_PULLUP);
pinMode(r4, INPUT_PULLUP);

Serial.begin(9600);
}
String c;int a;
String tex;
void loop() {
  // put your main code here, to run repeatedly:
if(c!=key()){
if(key()!="" || key()!="\0"){
  a++;
 
Serial.println(key());
 c=key(); 
}
}
}

bool en;
String key()
{
  String data="";
 digitalWrite(c1,0);
 digitalWrite(c2,1);
 digitalWrite(c3,1);
 digitalWrite(c4,1);
 if(digitalRead(r1)==0){data="1";}
 if(digitalRead(r2)==0){data="4";}
 if(digitalRead(r3)==0){data="7";}
 if(digitalRead(r4)==0){data="*";}

 digitalWrite(c1,1);
 digitalWrite(c2,0);
 digitalWrite(c3,1);
 digitalWrite(c4,1);
 if(digitalRead(r1)==0){data="2";}
 if(digitalRead(r2)==0){data="5";}
 if(digitalRead(r3)==0){data="8";}
 if(digitalRead(r4)==0){data="0";}

 digitalWrite(c1,1);
 digitalWrite(c2,1);
 digitalWrite(c3,0);
 digitalWrite(c4,1);
 if(digitalRead(r1)==0){data="3";}
 if(digitalRead(r2)==0){data="6";}
 if(digitalRead(r3)==0){data="9";}
 if(digitalRead(r4)==0){data="#";}

 digitalWrite(c1,1);
 digitalWrite(c2,1);
 digitalWrite(c3,1);
 digitalWrite(c4,0);
 if(digitalRead(r1)==0){data="A";}
 if(digitalRead(r2)==0){data="B";}
 if(digitalRead(r3)==0){data="C";}
 if(digitalRead(r4)==0){data="D";}
 return data;
}